Error when trying to use the thingspeak-arduino ESP32 Eaxmples - WriteSingl​eFieldSecu​re.ino

4 ビュー (過去 30 日間)
Jungle Jim
Jungle Jim 2024 年 7 月 22 日
編集済み: Umar 2024 年 9 月 26 日
When I try compile and run the example file
WriteSingleFieldSecure.ino
I get the following error:
Compilation error: 'WiFi' was not declared in this scope
If I add
#include <WiFi.h>
at the top, it compiles but the code does not work.
This is the output I get:
09:41:36.694 -> WARNING: This library doesn't support SSL connection to ThingSpeak. Default HTTP Connection used.
09:41:36.831 -> Attempting to connect to SSID: My-SSID
09:41:36.831 -> .
09:41:41.838 -> Connected.
09:41:41.884 -> Problem updating channel. HTTP error code -301
09:42:01.864 -> Problem updating channel. HTTP error code -301
Additionally I tried the example file
WriteMultipleFieldsSecure.ino
but got similar results.
I would like to be able to write fields securely to ThingSpeak using ESP32. How do I do this?
  8 件のコメント
Jungle Jim
Jungle Jim 2024 年 9 月 24 日
Hi @Umar,
Thanks for that link on the other site. It does help a little. but I'm still struggling to get the correct certificate of Mathworks to use in my code.
Those examples that Mathworks provided here: https://github.com/mathworks/thingspeak-arduino/tree/master/examples/ESP32 and in particular this one does not work: examples/ESP32/WriteSingleFieldSecure/WriteSingleFieldSecure.ino
Umar
Umar 2024 年 9 月 25 日
編集済み: Umar 2024 年 9 月 26 日

Hi @Jungle Jim,

I did some research and let me address the issues you're facing with the WriteSingleFieldSecure.ino example,

Include Necessary Libraries: Make sure you have included both the WiFi.h and WiFiClientSecure.h libraries at the top of your code:



#include <WiFi.h>
#include <WiFiClientSecure.h>


Correct API Endpoint: Verify that you are using the correct ThingSpeak API endpoint. The HTTP error code -301 indicates that the URL may have changed. The correct endpoint for secure connections is:

 const char* server = "api.thingspeak.com";



Use SSL for Secure Connections: Modify your HTTP request function to utilize SSL. Here’s a basic example of how to set up a secure connection:

 WiFiClientSecure client;

client.setInsecure(); // Use this for testing; for production, use a     valid certificate
if (!client.connect(server, 443)) {
  Serial.println("Connection failed");
  return;
}


Certificate Handling: If you need to use a specific certificate, you can obtain it from the ThingSpeak documentation or their support.

Please let me know if you have any further questions.

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

回答 (1 件)

Jungle Jim
Jungle Jim 2024 年 9 月 25 日
When I try compile and run the example file
WriteSingleFieldSecure.ino
I get the following error:
Compilation error: 'WiFi' was not declared in this scope
If I add
#include <WiFi.h>
at the top, it compiles but the code does not work.
This is the output I get:
09:41:36.694 -> WARNING: This library doesn't support SSL connection to ThingSpeak. Default HTTP Connection used.
09:41:36.831 -> Attempting to connect to SSID: My-SSID
09:41:36.831 -> .
09:41:41.838 -> Connected.
09:41:41.884 -> Problem updating channel. HTTP error code -301
09:42:01.864 -> Problem updating channel. HTTP error code -301
Additionally I tried the example file
WriteMultipleFieldsSecure.ino
but got similar results

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by