I have a photon with a temp and humidity sensor (DHT11) sending the data to ThingSpeak. I also have another DHT22 connected to another microcontroller (huzzah 8266 something) that I will also program to send to the same channel on ThingSpeak. How can I use the data being sent by both sensors to make certain commands on the photon.
The photon is on a relay shield that is connected to a dehumidifier. I want the relay to activate(dehumidifier come on) when the humidity hits a certain level.
The hints given in this thread might help you forward
Thank you.
I now am trying to work on my loop. I have the commands that send data to thingspeak that send every 15 seconds with the delays. I want to discard the delays and put the whole set of commands into a timer or a counter so that set runs once every 15 seconds instead. How do i code this?
@Dsradley5, take a look at this tutorial:
https://www.norwegiancreations.com/2017/09/arduino-tutorial-using-millis-instead-of-delay/
Can someone tell me why “Temperature” is being published with “Humidity”, but only Humidity is showing up on my channel on Thingspeak? Thanks
Sorry, no, I switched the humidity to that graph to see if it would work, and it did then i switched it back.
Hmmm… I don’t see why it wouldn’t work like you have it.
I haven’t used the DHT library in a long time. You might not be giving the DHT eneough time to return the Temperature value ? Adding a safe delay might help after each DHT reading:
for (uint32_t ms = millis(); millis() - ms <2000; Particle.process());
You can write both ThingSpeak Fields at once if you want and see if that cures your problem:
// set fields one at a time
ThingSpeak.setField(1,humidity);
ThingSpeak.setField(2,temperature);
// Write the fields that you've set all at once.
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
Also:
You should remove the long 30 second delay().
You can Wrap all your publishing & ThinkSpeak code to only fire once every 30 seconds.
Declare a couple of Global variable (before Setup)
unsigned long publish_delay = 30000;
unsigned long previousPublish = 0 ;
Then wrap your code using
if (millis() - previousPublish >= publish_delay) { // it's time to publish, 30 seconds after the last one.
// do your stuff here
previousPublish = millis(); // update the previousPublish Time
} // End code for every 30 seconds.
I like that, thank you. I will see if that fixes the other issue as well.
That seems to have fixed the issue! Thanks @Rftop
SOLVED
Just out of curiosity, which one fixed the problem?
It may help others in the future.
Well, I did both because I hated the delay like that too. But I adjusted the Thingspeak code like you suggested and I worked immediately inside the new timer.