Don't upload data to Thingspeak

Walter Diego Spaltro on 30 Mar 2022
Latest activity Reply by Walter Diego Spaltro on 31 Mar 2022

Hi all, don't upload data to Thingspeak (sorry my english) I'm build this counter geiger https://www.electronics-lab.com/project/new-improved-geiger-counter-now-wifi/ but not upload data, only appear this to my channel:

29T23:17:58Z","entry_id":112,"field1":null},{"created_at":"2022-03-29T23:22:58Z","entry_id":113,"field1":null},{"created_at":"2022-03-29T23:27:58Z","entry_id":114,"field1":null},{"created_at":"2022-03-29T23:32:58Z","entry_id":115,"field1":null},{"created_at":"2022-03-30T18:43:09Z","entry_id":116,"field1":null},{"created_at":"2022-03-30T19:00:19Z","entry_id":117,"field1":null},{"created_at":"2022-03-30T19:05:19Z","entry_id":118,"field1":null},{"created_at":"2022-03-30T19:10:19Z","entry_id":119,"field1":null}]}

The code I'm use is there https://www.electronics-lab.com/project/new-improved-geiger-counter-now-wifi/ sorry it does not allow me to upload it because it is long

Christopher Stapels
Christopher Stapels on 30 Mar 2022

Did you export only field 1 above by the way? The code that I found writes to field 2. Make sure field 2 is enabled.

Christopher Stapels
Christopher Stapels on 30 Mar 2022 (Edited on 30 Mar 2022)

ok found the code here . In the section below, replace all the variables with string numbers, for example:

String(averageCount) --> "22.34" 

and so on. Then watch your ThingSpeak channel and see if those numbers show up. that will help isolate the problem.

    if (deviceMode)    // deviceMode is 1 when in monitoring station mode. Uploads CPM to thingspeak every 5 minutes
    {
      currentUploadTime = millis();
      if ((currentUploadTime - previousUploadTime) > 300000)
      {
        previousUploadTime = currentUploadTime;
        if (client.connect(server, 80))
        {
          String postStr = channelAPIkey;
          postStr += "&field2=";
          postStr += String(averageCount);
          postStr += "\r\n\r\n";
          char temp[50] = "X-THINGSPEAKAPIKEY:";
          strcat(temp, channelAPIkey);
          strcat(temp, "\n");
          client.print("POST /update HTTP/1.1\n");
          client.print("Host: api.thingspeak.com\n");
          client.print("Connection: close\n");
          client.print(temp);
          client.print("Content-Type: application/x-www-form-urlencoded\n");
          client.print("Content-Length: ");
          client.print(postStr.length());
          client.print("\n\n");
          client.print(postStr);
          Serial.println(postStr);
        }
        client.stop();
      }
Christopher Stapels
Christopher Stapels on 30 Mar 2022 (Edited on 30 Mar 2022)

Also, I cant really see in the code where it handles the POST to ThingSpeak. Can you show that part of the code? (just the HTTP post part, and possible where the data is formed)

Walter Diego Spaltro
Walter Diego Spaltro on 31 Mar 2022

Hi Christopher, thanks for your answer, I solved it with your answer of activating "field2", and now it works fine, but it restarts after I turn it off and I have to reprogram it to make it work again. Tell me what is the problem? Thanks a lot!!!

Christopher Stapels
Christopher Stapels on 30 Mar 2022

That's a neat demo, thanks for sharing, I think Ill make one! Are you sure there is data coming from the detector? Can you see data on the serial monitor? Try hardcoding a number in your code instead of using a variable. If the hard coded number works, then the problem is the data in your variable.