Getting Channel to work

Edward on 30 Apr 2023 (Edited on 3 May 2023)
Latest activity Edit by Christopher Stapels on 16 Apr 2024

I have used this code but nothing is showing in my channel any suggesrtions please- the internet connects and the temperature output shows but nothing in my channel
#include <OneWire.h>
#include <DallasTemperature.h>
#include <WiFiNINA.h>
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS A0
// WiFi credentials
const char* ssid = "xxxxxxx";
const char* password = "xxxxxxxxx";
// ThingSpeak settings
const char* server = "api.thingspeak.com";
const char* apiKey = "xxxxxxxxxxxxxxxx";
const int httpPort = 80;
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// create an instance of the WiFi class
WiFiClient client;
void setup(void)
{
// start serial port
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// Connect to WiFi network
Serial.print("Connecting to WiFi...");
while (WiFi.status() != WL_CONNECTED) {
WiFi.begin(ssid, password);
delay(1000);
Serial.print(".");
}
Serial.println();
Serial.println("WiFi connected");
// Start up the library
sensors.begin();
}
void loop(void)
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
Serial.println(",");
Serial.print("Temperature for the device 1 (index 0) is: ");
float tempC = sensors.getTempCByIndex(0);
Serial.println(tempC);
delay(1000); // update sensor reading each one second
// Send data to ThingSpeak
if (client.connect(server, httpPort)) {
String data = "&Field 1=" + String(tempC);
Serial.println("Connecting to ThingSpeak...");
client.println("POST /update HTTP/1.1");
client.println("Host: api.thingspeak.com");
client.println("Connection: close");
client.println("Content-Type: application/x-www-form-urlencoded");
client.println("Content-Length: " + String(data.length()));
client.println();
client.println(data);
client.println();
Serial.println("Data sent to ThingSpeak");
} else {
Serial.println("Error connecting to ThingSpeak");
}
client.stop();
delay(15000); // Send data to ThingSpeak every 15 seconds
}
Christopher Stapels
Christopher Stapels on 30 Apr 2023 (Edited on 16 Apr 2024)
We strongly reccomend using theThingSpeak library. Your code is missing a write of the API key in the POST. You can see the correct format at the write data page in the documentation. There are great examples in the examples tab in the doc, or try the library examples to see.
Edward
Edward on 1 May 2023
Thanks Christopher
The lates library has been installed I have checked the API key is correct.
Through the serial Monitor on the Arduino the output is: -
10:15:35.932 -> Dallas Temperature IC Control Library Demo
10:15:35.978 -> Connecting to WiFi....
10:15:41.133 -> WiFi connected
10:15:41.133 -> Requesting temperatures...DONE
10:15:41.855 -> ,
10:15:41.855 -> Temperature for the device 1 (index 0) is: 31.56
10:15:43.492 -> Connecting to ThingSpeak...
10:15:43.537 -> Data sent to ThingSpeak
But nothing showing in the channel - please advise
Christopher Stapels
Christopher Stapels on 1 May 2023 (Edited on 1 May 2023)
Did you use the examples in the library? Just installing the library won't change anything, you need to use the code that comes with it.
Is your channel public? Can you share the channel ID?
Edward
Edward on 1 May 2023
I have set its as private
Channel ID: 2128586
Thanks
Christopher Stapels
Christopher Stapels on 1 May 2023 (Edited on 16 Apr 2024)
If it is private, I wont be able to look at the data. But I dont think its an issue with the display on your channel, looking at the code above. if you use the example code from the library, you should be able to get data into your channel, then you can modify your own code to use the sensor or modify the example code to include your sensor.
Edward
Edward on 2 May 2023
can you tell me exactly where I find the example code please
Christopher Stapels
Christopher Stapels on 2 May 2023 (Edited on 16 Apr 2024)
Sure, click the link I shared above, for ThingSpeak library. Then click the folder called "examples". Then select your hardware or something similar.
If you are using the Arduino IDE, you can see the examples in the file menu, you choose the appropriate library.
There are a bunch of ThingSpeak examples in the ThingSpeak documentation examples area.
The post tempreature data example is similar to your case.
Edward
Edward on 3 May 2023
Thanks - A combination of I do not know what has got it working!!!!
Edward
4
Posts
8
Replies