Código:
Simplemente debería añadir al final del fichero Encender luz dormitorio, pero en su lugar me muestra este resultado:#include "RCSwitch.h" #include <stdlib.h> #include <stdio.h> #include <iostream> #include <string> RCSwitch mySwitch; using namespace std; int main(int argc, char *argv[]) { // Lineas propias FILE *fp; fp=fopen("/home/pi/historial.txt", "r+b"); string accion; // This pin is not the first pin on the RPi GPIO header! // Consult https://projects.drogon.net/raspberry-pi/wiringpi/pins/ // for more information. int PIN = 2; if(wiringPiSetup() == -1) return 0; mySwitch = RCSwitch(); mySwitch.enableReceive(PIN); // Receiver on inerrupt 0 => that is pin #2 while(1) { if (mySwitch.available()) { int value = mySwitch.getReceivedValue(); if (value == 0) { printf("Unknown encoding\n"); } else { printf("Received %i\n", mySwitch.getReceivedValue() ); if (value == 3131){ accion = "Encender luz dormitorio";} } fseek (fp, 0, SEEK_END); fwrite(&accion, sizeof(string), accion.length(), fp); mySwitch.resetAvailable(); } } fclose(fp); exit(0); }
Código:
R-ÿÿÿÿÿÿÿÿ^ KÚ¶; P-èȶ0Ú¶äø©¾¨¥øŠR-ÿÿÿÿÿÿÿÿ^ KÚ¶; P-èȶ0Ú¶äø©¾¨¥øŠpi@raspberrypi:~$