Error when trying to use the thingspeak-arduino ESP32 Eaxmples - WriteSingleFieldSecure.ino
8 Kommentare
Hi @Jungle Jim,
Based on your comments, you encountered following errors listed below.
So, the first error you encountered was due to the wifi library not included in the initial code. When you included it #include wifi.h , it helped resolved this issue. However, then you encountered HTTP Error Code -301 which indicates a "Moved Permanently" response from the server and suggests that the URL used for the HTTP request is incorrect or outdated. The ThingSpeak API endpoint may have changed, or the request may not be formatted correctly. So, I would recommend the following to the issues. First, make sure the line #include wifi.h is present at the top of your code. Modify the httpRequest function to make sure the correct endpoint is used and writeAPIKey is correctly set and valid. An invalid API key will also lead to errors when trying to update the channel. Now, if you want to write fields securely, consider using the HTTPS library. You may need to include the WiFiClientSecure.h library and modify the connection method to use SSL. Here is an example of how to modify the httpRequest function for secure connections based on the documentation provided below.
https://www.mathworks.com/help/thingspeak/measure-arduino-wifi-signal-strength-with-esp32.html
Please let me know if the code provided in the link above resolves your problem.
Hi @Jungle Jim,
What makes you think that example code is completely wrong provided in the link below,
https://www.mathworks.com/help/thingspeak/measure-arduino-wifi-signal-strength-with-esp32.html
Hi @Jungle Jim,
I did some further research regarding Firstly your example does not solve my issue - my issue is that I need to do SSL. The example you gave does not use SSL.
https://randomnerdtutorials.com/esp32-https-requests/
Please let me know if clicking the above link resolves SSL problem.
Secondly, I was referring to the examples provided by MathWorks that do NOT work. Those examples are here: https://github.com/mathworks/thingspeak-arduino/tree/master/examples/ESP32
If you need any help with these examples, please let me know.
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.
Antworten (1)
Kategorien
Mehr zu C Shared Library Integration finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!