Photon temp data to and from Thingspeak

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

1 Like

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:

1 Like

Can someone tell me why “Temperature” is being published with “Humidity”, but only Humidity is showing up on my channel on Thingspeak? Thanks

It appears that Temperature is working:

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
        // Write the fields that you've set all at once.
	ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);

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.  
1 Like

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

Just out of curiosity, which one fixed the problem?
It may help others in the future.

1 Like

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.