0

Getting data from io.adafruit
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Getting data from io.adafruit

by cwkreimer on Tue Oct 30, 2018 12:38 am

I have two questions -- I am building an IOT device that will check the temperature of a rubber mat that has an embedded 12AMP heating element that melts snow in the winter. I need a way to have the ESP8266 fetch a few integer variables from the cloud when the ESP8266 starts. This is not an "on change event"... rather, it is a "pull" from the io system.

For example -- I want to load Initial_Max_Heat_Temperature and Turn_Coils_Off_When_Temp_Reached into variables in my arduino sketch. I want to be able to keep the variables in the cloud instead of burning them into the sketch to be able to change the data remotely.

I am using the LampOnExample as a starting point.
Adafruit_MQTT_Subscribe lamp = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/lamp");
.
.
.
while (subscription = mqtt.readSubscription(1000)) {

// we only care about the lamp events
if (subscription == &lamp) {

// convert mqtt ascii payload to int
char *value = (char *)lamp.lastread;
Serial.print(F("Received: "));
Serial.println(value);


This works for turning on the mats using a relay and a toggle control on the dashboard.

One problem that I am having is keeping the state of the lamp in sync. It seems that the ESP8266 only "hears" when there is a state change in the lamp feed. How can I "pull" data down to initialize the variables?

Also -- My plan is to have 6 ESP8266s running and I need to make sure that I don't consume too many amps. I need to have one ESP8266 tell another ESP8266 to turn on or turn off.

Is there a control on the io.adafruit.com that does this? If an IOT device changes a feed using a "publish", will that trigger another ESP that is listening using a "subscription"?

Thanks in advance,

CW

cwkreimer
 
Posts: 1
Joined: Mon Oct 29, 2018 2:07 am

Re: Getting data from io.adafruit

by brubell on Tue Nov 06, 2018 9:39 am

It seems you're using the older, Adafruit IO MQTT examples. These still work, but the Adafruit IO Arduino library is more featured and is supported (https://github.com/adafruit/Adafruit_IO_Arduino).


One problem that I am having is keeping the state of the lamp in sync. It seems that the ESP8266 only "hears" when there is a state change in the lamp feed. How can I "pull" data down to initialize the variables?

Set up a feed as a subscription (https://github.com/adafruit/Adafruit_IO ... be.ino#L55) and create an event handler (https://github.com/adafruit/Adafruit_IO ... be.ino#L82) to be called whenever you change the heating values of that specific feed from your dashboard.

Also -- My plan is to have 6 ESP8266s running and I need to make sure that I don't consume too many amps. I need to have one ESP8266 tell another ESP8266 to turn on or turn off.
Is there a control on the io.adafruit.com that does this? If an IOT device changes a feed using a "publish", will that trigger another ESP that is listening using a "subscription"?

You'll want something similar to what I described above. But, because you're subscribing to this feed and publishing it, I suggest using the publish/subscribe features in the Adafruit IO Arduino library. There's an example of both of these features here: https://github.com/adafruit/Adafruit_IO ... pubsub.ino. An ESP subscribes to the same feed as the second. The first ESP publishes a value to that feed. If the second ESP is subscribed and has an event handler set up, it'll trigger that function .


EDIT: You can also use the MQTT GET to fetch the current state of the feed and resend it (https://io.adafruit.com/blog/notebook/2 ... etain-flag)

brubell
 
Posts: 189
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.