I want to send data to ThingSpeak using Arduino
Show older comments
Currently, GPS data is acquired using Arduino on Simulink.
I want to send this data to ThingSpeak.
How should I set the microcomputer board?
Thank you very much!
6 Comments
Christopher Stapels
on 29 Mar 2022
ThingSpeak has location fields in the feed. When you write an entry, you can have field1, field2...field 8, status, then lattitude, longitude, and elevation.
When you read the data back, be sure to set location=true to get the position data back.
We reccomend using the ThingSpeak library for Arduino, there are some good examples in there of how to write to a channel.
seiya moro
on 31 Mar 2022
Christopher Stapels
on 2 Apr 2022
Edited: Christopher Stapels
on 12 Apr 2022
Where is that error coming from? Is it the Arduino IDE or simulink or something else?
seiya moro
on 2 Apr 2022
Nakul Khadilkar
on 13 Apr 2022
Hi Seiya,
What WiFi shield are you using with the Mega?
seiya moro
on 14 Apr 2022
Edited: seiya moro
on 14 Apr 2022
Answers (2)
The question title says "I want to send data to ThingSpeak using Arduino", which is answered by the answer here.
If you are interested in sending data to ThingSpeak using Simulink and Arduino, I would recommend watching this video as a starting point.
or this one:
1 Comment
seiya moro
on 18 Apr 2022
Karol Lackovic
on 13 Apr 2022
0 votes
Hello,
try bellow code, works for me.
#include <WiFiClientSecure.h> // you need this library, cos Thingspeak use SSL protocoal, so standard WIFIClient is not able to connect there
const char* ssid = "SSID name";
const char* password = "your password";
WiFiClientSecure client;
void connectToWIFI() {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(WiFi.status());
delay(1000);
}
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void setup() {
Serial.begin(115200);
connectToWIFI();
}
void loop() {
httpRequestData = "api_key=YOURAPIKEY&field1=22.32&field22=12.89; //up to field 8
responseTime = millis();
Serial.println(" Starting connection to server thingspeak");
Serial.println(httpRequestData);
client.setInsecure(); //skip SSL verification
if (!client.connect("api.thingspeak.com", 443, 10000)) {
Serial.println("Connection failed! Reconnect!");
connectToWIFI();
} else {
Serial.print(" Connected to server!");
client.println("GET https://api.thingspeak.com/update?" + httpRequestData + " HTTP/1.0");
client.println("Host: api.thingspeak.com");
client.println("Connection: close");
client.println();
while (client.connected()) {
String line = client.readStringUntil('\n');
if (line == "\r") {
Serial.print(" Headers received "); // or display lito to get return code
break;
}
}
Serial.println(millis() - responseTime); //response time in miliseconds
client.stop();
}
}
be carefully, today i found, that only one request per 15 seconds can be send
3 Comments
seiya moro
on 14 Apr 2022
Karol Lackovic
on 14 Apr 2022
Sorry, no idea. This is pure wire language. I use Arduino IDE software, to connect to device via USB and upload code above.
seiya moro
on 15 Apr 2022
Communities
More Answers in the ThingSpeak Community
Categories
Find more on Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!