Friday, February 27, 2015

[Wireless Room Temperature Monitoring System] Sending Temperature values to the Raspberry Pi and store it in a .txt file

Now that each elements are working independently we will have the arduino measuring the temperature, sending it with the TX 433 Mhz module through the air and have the Raspberry Pi pick up the data and collect it in .txt file

I had to modify the Arduino code in order to get the temperature with full details. The device is giving a float value that cannot be sent over RF (basically we loose the numbers after the comma). In order to avoid that we multiply the float value by 100 in order to get full details and send it over RF.

I modified the "printTemperature" class from the Arduino Code :
void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  int tempCx100 = (int)(tempC*100); // Multiply the float value > int with 4 digits

  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
    mySwitch.send(0000, 24);
  } else {
    Serial.print("C: ");
    Serial.print(tempC); //reads the temp value on the serial port
    mySwitch.send(tempCx100, 24); //Temperature x100 with all the accuracy needed
  }
}
On the receiving end, I modified the code in order to modify the received Int into a float and to store the value received in a file.

Modification of the while loop within the RFSniffer.cpp program
 while(1) {
      if (mySwitch.available()) {
        int value = mySwitch.getReceivedValue();
        float valuefloat = (float) (value/100.0); // Divide the received value to get a float
        if (value == 0) {          printf("Unknown encoding");        } else {
          printf("Recu %i\n", mySwitch.getReceivedValue() );
          FILE *f = fopen("/home/pi/recu.txt", "a"); //append the value within the next line of the recu.txt file          fprintf(f,"%i\n",value );
          fclose(f);        }
        mySwitch.resetAvailable();
      }
There you can see the reading directly on the Serial Port reader from the Arduino Software


Then there is the value being sniffed by the Raspberry Pi directly in the Terminal


And finally the content of the file in which we are appending the received file indefinitely

Now that this work, here are the next challenge.

I need to be able to "identify" which Temperature sensor sent this result, basically label the sent value
I need to append those values into a file per day with the time stamp available
Ultimately i should be able to have those values read and plotted in a graph.

No comments:

Post a Comment