So, I couldn't get my weathershield to work, so my attention has moved to getting temperature only via a DS18B20 sensor. Got the sketch to read the temp from the sensor, and also got the sketch to send a packet to the gateway, but ran into an issue that I can't figure out.
The sensor works and gives the correct temps via the serial monitor in the Arduino IDE, but the gateway receives a different value.
This leads me to believe that the conversions in the sketch are correct:
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
Serial.print(" Temperature = ");
Serial.print(celsius);
Serial.print(" Celsius, ");
Serial.print(fahrenheit);
Serial.println(" Fahrenheit");
It's confusing though, because when I send the "raw" value, before any conversions are made in the sketch, the gateway receives the correct value:
[43] F:370 [RSSI:-36][ACK-sent]
In this case, the raw value of 372 is equal to what I'm seeing in the monitor:
Transmitting at 915 Mhz...
Data = 1 72 1 55 0 7F FF 7F 10 18 CRC=18
Temperature = 23.12 Celsius, 73.62 Fahrenheit
ok!
When I send the value of "fahrenheit", the gateway receives:
[43] F:1638 [RSSI:-41][ACK-sent]
or
[43] F:-13108 [RSSI:-40][ACK-sent]
Send the value of celsius returns different numbers, but still unrecognizable.
Here is my packet code:
sprintf(buff, "F:%d", fahrenheit);
sendSize = strlen(buff);
So, in short, "raw" sends the right data, but the other 2 are sending something odd.
Quote from: peckcj on January 23, 2016, 04:17:57 PM
sprintf(buff, "F:%d", fahrenheit);
sendSize = strlen(buff);
So, in short, "raw" sends the right data, but the other 2 are sending something odd.
Isn't fahrenheit a float value? If so, %d isn't the right format and, you'll need to use one of the funky Arduino float to str functions to convert it (unless you override the compiler options to include float support on sprintf).
Tom
OK, that makes more sense. So if I'm understanding it correctly (I am terribly new to this), the "fahrenheit" value is being stored in one format, but the packet needs to send it in a different format?
Thank you.
Would it be easier to have the metric.js file convert the "raw" data for me ... ie:
https://lowpowerlab.com/forum/index.php/topic,1331.msg9191.html#msg9191 (https://lowpowerlab.com/forum/index.php/topic,1331.msg9191.html#msg9191)
I tried this, but when I attempted to create a new metric, the web gateway crashed. Of course, I probably didn't do it correctly.
I just added the following:
//Temperature
//TEMP : { name:'Temp', regexp:/F\:(-?\d+)/i, value:'', valuation = function(value) { return ((value / 16.0) * 1.8) + 32.0; }}, unit:'°F', pin:1, graph:1, graphValSuffix:'F', graphOptions:{ legendLbl:'Temperature', lines: { lineWidth:1 }}},
to the exports.metrics portion of the metrics.js file.
I thought that this would add a new metric that could convert the "raw" data from my sensor. This caused the gateway web app to stop.