ESP8266 and IoT Cloud Help Request

Hi all! Advice Request here:

I am using an esp8266 board to link to Arduino IoT cloud to control an LED via a switch and display the values of a DHT11 temperature sensor. While I am able to control the LED without too much of a problem, I am struggling to integrate the temperature sensor. Specifically, I am able to get the code to compile, but I can't get any value to display on the IoT Dashboard.

Any help would be greatly appreciated, thanks!
(Photos include the code and the Prototype Setup.)



Hi!

I would suggest removing the delays in the loop(). The loop() function includes the ArduinoCloud.update(); call, which sends data to the cloud and receives updates. In order to get the best responsiveness in your cloud-connected projects, the loop() function should run as fast as possible. This means that no blocking commands should be used inside, and you should prefer a non-blocking programming approach whenever possible.
You can learn more about recommended code practices here.

And you can find an example without delays here: https://docs.arduino.cc/built-in-examples/digital/BlinkWithoutDelay#code

Your code would look something like this:

void loop() {
  ArduinoCloud.update();
  // Your code here
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= 2000) { // If you want to read every 2secs
    // save the last time you blinked the LED
    previousMillis = currentMillis;
   
    /* Here you can include the code that repeats every 2secs */
  }
}

I hope this helps

1 Like

Hi @spudtech_now

You need to add the temperature variable to the IoT Setup Cloud Variables list as a Float variable.
Then remove the float variable from within your void loop, then the IoT cloud will show your temperature readings .:slightly_smiling_face:

HTH

2 Likes
CloudTemperatureSensor temperature
...
float temperature = dht.readTemperature(true);

You have two variables with the same name, and the local one is shadowing the global cloud variable.

1 Like

Thank you!

Thank you for your help!!

Ok, good news! I think... I have the code able to be uploaded to the IoT dashboard, and it functions on the esp8266 and the Serial Monitor...however, the temperature values and controls don't display on the dashboard. (The last image contains a bit of the ThingProperties.h tab, which I'm thinking might have some errors?) Ideas? Thank you!



I have merged your cross-posts @spudtech_now.

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting can result in a suspension from the forum.

In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Pert,
Oh dear! You have my sincerest apologies for this most egregious violation of mine - it was not my intention in the slightest to violate the basic forum etiquette! I have skimmed the guide you mentioned, and agree that it does make far more sense to post all related material to the same post. I'm afraid I had simply grown used to forums that simply closed discussions after a day or so, rather than leaving them open for sufficient time to actually come to a resolution as appears the case here.
Thank you Pert for your diligence in ensuring that the Arduino Platform stays clean, simple, easy to use, and in accordance with both the official Arduino Forum community guidelines and the "How to get the best out of this forum" guide. I will strive to better follow it where possible in the future.

1 Like

That is a fantastic idea! I am definitely going to switch to that in my IoT sketches in the future - thank you!

Thank you again!

General Note to those with a similar problem: It looks like @robrs and @pennam were right on the money - there was a weird error between my thingProperties.h and main tabs, which ultimately ended up being a variable shadowing. There is also another forum post as well that troubleshoots a similar issue.

Thank you to all who helped me troubleshoot my issue, and best of luck to anyone with a similar issue to mine!

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.