Can I use One ESP32 Device to update 2 ThingSpeak Channels?

14 ビュー (過去 30 日間)
Leo Bobila
Leo Bobila 2021 年 8 月 10 日
I have one ESP32 weather station device with 12 sensors. I use the free version of ThingSpeak with 8 Fields and 4 channels. Can I use 2 channels and updload the data to Fields 1-8 in Channel 1 and Fields 9-12 in Channel 2? Below is my code:
else if (App == "Thingspeak") {
// Send data to ThingSpeak
WiFiClient client1;
if (client1.connect(server,80)) {
Serial.println("");
Serial.println("Connect to ThingSpeak CH1 - OK");
Serial.println("");
Serial.println("********************************************");
String postStr = "";
postStr+="GET /update?api_key1=";
postStr+=api_key1;
postStr+="&field1="; // I want to sent this field to Channel 1
postStr+=String(temperature);
postStr+="&field2="; // I want to send this field to Channel 2
postStr+=" HTTP/1.1\r\nHost: a.c.d\r\nConnection: close\r\n\r\n";
postStr+="";
client1.print(postStr);
delay(5000);

採用された回答

Christopher Stapels
Christopher Stapels 2021 年 8 月 10 日
編集済み: Christopher Stapels 2021 年 8 月 10 日
Yes you can but the code you wrote wont do it. I would start with the ThingSpeak library for Arduino, ESP8266 and ESP32. Use the write multiple fields example and duplicate the writing section for the second channel you want to write to.
...other stuff from the library example...
// set the fields with the values
ThingSpeak.setField(1, number1);
ThingSpeak.setField(2, number2);
ThingSpeak.setField(3, number3);
ThingSpeak.setField(4, number4);
// write to the ThingSpeak channel
int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
if(x == 200){
Serial.println("Channel update successful.");
}
else{
Serial.println("Problem updating channel. HTTP error code " + String(x));
}
and then repeat with the data for channel 2, the channel 2 id, and the write API key.
  2 件のコメント
Leo Bobila
Leo Bobila 2021 年 8 月 13 日
Thank you so much. I am not a programmer, so I'm still figuring out how to integrate it with the other codes.
Christopher Stapels
Christopher Stapels 2021 年 8 月 13 日
You are a programmer now! Welcome to the club. I recommend building your code one step at a time and watching the output to make sure it acts as you expect. Feel free to post here again if you get stuck.

サインインしてコメントする。

その他の回答 (0 件)

コミュニティ

その他の回答  ThingSpeak コミュニティ

カテゴリ

Help Center および File ExchangeRead Data from Channel についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by