I want to send data to ThingSpeak using Arduino

조회 수: 4 (최근 30일)
seiya moro
seiya moro 2022년 3월 29일
댓글: seiya moro 2022년 4월 18일
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
Nakul Khadilkar
Nakul Khadilkar 2022년 4월 13일
Hi Seiya,
What WiFi shield are you using with the Mega?
seiya moro
seiya moro 2022년 4월 14일
편집: seiya moro 2022년 4월 14일
Hi,
Now, I am using SHIELD-ESP-WIFI REV 2.0. with the Mega.
Also, is there a Wifi shield that I should buy?
Thank you very much.

댓글을 달려면 로그인하십시오.

답변 (2개)

Vinod
Vinod 2022년 4월 14일
편집: Vinod 2022년 4월 14일
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
seiya moro
seiya moro 2022년 4월 18일
Hi Vinod,
Sorry for the late reply.
I think it will be very helpful.
I will try this method.
Thank you very much!

댓글을 달려면 로그인하십시오.


Jan Maly
Jan Maly 2022년 4월 13일
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
Jan Maly
Jan Maly 2022년 4월 14일
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
seiya moro 2022년 4월 15일
I understand.
Thank you very much!

댓글을 달려면 로그인하십시오.

커뮤니티

더 많은 답변 보기:  ThingSpeak 커뮤니티

카테고리

Help CenterFile Exchange에서 Arduino Hardware에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by