Publish switch states to ThingSpeak

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
dermeb
New user
Posts: 4
Joined: 22 Dec 2015, 12:55

Publish switch states to ThingSpeak

#1 Post by dermeb » 22 Dec 2015, 13:04

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

dermeb
New user
Posts: 4
Joined: 22 Dec 2015, 12:55

Re: Publish switch states to ThingSpeak

#2 Post by dermeb » 22 Dec 2015, 13:49

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:

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

Martinus

Re: Publish switch states to ThingSpeak

#3 Post by Martinus » 22 Dec 2015, 14:00

Instead of copying the code it's easier to add the case statement below the first one like this:

Code: Select all

          case SENSOR_TYPE_SINGLE:
          case SENSOR_TYPE_SWITCH:
            postDataStr += F("&field");
            postDataStr += event->idx;
            postDataStr += "=";
            postDataStr += String(UserVar[event->BaseVarIndex]);
            break;
I'll add it in R56.

dermeb
New user
Posts: 4
Joined: 22 Dec 2015, 12:55

Re: Publish switch states to ThingSpeak

#4 Post by dermeb » 22 Dec 2015, 14:06

That's a nice trick, thanks!
I'll add it in R56.
Great! :)

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest