Hello everyone!
Awesome project! I really like it and try to set up some nodes.
It works quite well. I upload my sensor data to thingspeak for further processing.
Temperature and humidity data from DHT sensors are working neatly.
But when I try to publish the data of a switch input it doesn't seem to work.
If I export the data from thingspeak, i just get empty entries like:
created_at,entry_id,field1,field2,field3
2015-12-22 11:43:15 UTC,1,,,
2015-12-22 11:43:31 UTC,2,,,
2015-12-22 11:44:01 UTC,3,,,
2015-12-22 11:45:32 UTC,4,,,
2015-12-22 11:45:46 UTC,5,,,
Has anyone managed to get switch-inputs to thingspeak?
Thank you!
Michael
Publish switch states to ThingSpeak
Moderators: grovkillen, Stuntteam, TD-er
Re: Publish switch states to ThingSpeak
After some code diving, I found the solution myself.
It wasn't implemented yet for the SENSOR_TYPE_SWITCH!
So i copied the code from SENSOR_TYPE_SINGLE, and it works like a charm
in _C004:
Greetings
Michael
It wasn't implemented yet for the SENSOR_TYPE_SWITCH!
So i copied the code from SENSOR_TYPE_SINGLE, and it works like a charm

in _C004:
Code: Select all
switch (event->sensorType)
{
case SENSOR_TYPE_SINGLE: // single value sensor, used for Dallas, BH1750, etc
postDataStr += F("&field");
postDataStr += event->idx;
postDataStr += "=";
postDataStr += String(UserVar[event->BaseVarIndex]);
break;
case SENSOR_TYPE_TEMP_HUM: // dual value
case SENSOR_TYPE_TEMP_BARO:
postDataStr += F("&field");
postDataStr += event->idx;
postDataStr += "=";
postDataStr += String(UserVar[event->BaseVarIndex]);
postDataStr += F("&field");
postDataStr += event->idx + 1;
postDataStr += "=";
postDataStr += String(UserVar[event->BaseVarIndex + 1]);
break;
case SENSOR_TYPE_SWITCH:
postDataStr += F("&field");
postDataStr += event->idx;
postDataStr += "=";
postDataStr += String(UserVar[event->BaseVarIndex]);
break;
}
Greetings
Michael
Re: Publish switch states to ThingSpeak
Instead of copying the code it's easier to add the case statement below the first one like this:
I'll add it in R56.
Code: Select all
case SENSOR_TYPE_SINGLE:
case SENSOR_TYPE_SWITCH:
postDataStr += F("&field");
postDataStr += event->idx;
postDataStr += "=";
postDataStr += String(UserVar[event->BaseVarIndex]);
break;
Re: Publish switch states to ThingSpeak
That's a nice trick, thanks!

Great!I'll add it in R56.

Who is online
Users browsing this forum: No registered users and 9 guests