So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By hackerjoe
#84794 Hi all,

I have a D1 mini esp8266 powered using an RC Lipo working with a 10k Thermistor displaying temperature on my LAN viewable in a browser. It updates every 5 seconds.
How can I integrate my working code and send the data from the thermistor to ThingSpeak.
The data doesn't have to be updated every 5 seconds to ThingSpeak, I was thinking of like either 15-30 minutes maybe even hourly.
User avatar
By hackerjoe
Bonzo wrote:Have you tried a search on the web?

I have searched and I have found code that gets me random data only ( not the temperature in Fahrenheit to write to Thingspeak.
I have to figure out how to code a thermistor on A0 to write every hour.
Thank you.
I do have a D1 mini coded and working locally on my LAN and can view temps in Celsius or Fahrenheit.
User avatar
By schufti
#84800 If you sample the temp every 5s now, you could just average over 720 samples (1h) and if the count is 720 send them to tsp. But without seeing your existing code noone will be able to give you more detail ...
If you get just random garbage @tsp then your code is probably faulty...
it can bee as short as this:

Code: Select allvoid tsp(float tmp) {
// replace with your channel's thingspeak API key,
#define APIKEY "api key goes here"
#define SERVER ""

  WiFiClient client;
  byte rept = 20;
  while (!client.connect(SERVER, 80) && --rept>0) delay(50);
  if (client.connected()) {
    String payload = "&field1=";
    payload += String(tmp, 2);
    String postStr = "POST /update HTTP/1.1\n";
    postStr += "Host: " + String(SERVER) + "\n";
    postStr += "Connection: close\n";
    postStr += "X-THINGSPEAKAPIKEY: " + String(APIKEY) + "\n";
    postStr += "Content-Type: application/x-www-form-urlencoded\n";
    postStr += "Content-Length: " + String(payload.length()) + "\n";
    postStr += "\n";
    postStr += payload;
//  read status from tsp  or discard status with client.flush();
    while (client.connected()) postStr=client.readStringUntil('\n');