ESP32 Library Example WriteMultipleFields fails with HTTP error code 400

Ken 2024 年 10 月 1 日 (編集日時: 2024 年 10 月 1 日)
最新アクティビティ Ken さんによる返信 (2024 年 10 月 4 日)

I left the code unchanged, modifying only secrets.h.
I am using an ESP32-WROOM -32U
Connection to network succeeds, but ThingSpeak.writeFields fails every time, with HTTP error code 400.
The sketch I am really trying to use is loosely based on this example, accesses Time and Weather info with no problems, but ThingSpeak.writeFields fails with HTTP error code 301.
This is my first attempt to use ThingSpeak.
Is this example sketch still valid, or must I look elsewhere? Suggestions please.
Vinod
Vinod 2024 年 10 月 2 日
A 400 error is because of bad inputs. If your only changes are in secrets.h, you might want to look at the sketch again. You definitely need to modify these before it will work. Make sure the values are correct.
unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;
Ken
Ken 2024 年 10 月 3 日
Thanks, I made an error transposing the APIkey
Christopher Stapels
Christopher Stapels 2024 年 10 月 1 日
The examples definitely still work.
Im a big fan of the 32 U layout. The one I use has an independant antenna connection and I get the longest range from those.
400 can mean authorization problem (though thats usually 401), so double check your channel id and api key.
the 301 error code is not an HTTP error, its an error from the library. It means there is a connectivity problem.
First I would check the connection strength (move closer to router), and also try a different network if possible.
It can be casued by an older version of the esp32 library that is the issue. (make sure to upgrade to the latest)
Ken
Ken 2024 年 10 月 3 日
Thank you for the information. It was of great help. I attribute my problem with the example sketch to improper use of the Write APIkey. Fixing that, problems with my own sketch disappeared when I moved the ThingSpeak calls from a function I wrote into the main sketch.
I don't know why this mattered, but otherwise I would get an HTTP error code 401, followed by a msg
"Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.",
then a reboot.
Vinod
Vinod 2024 年 10 月 3 日

Guru mediation errors are typically because of incorrect program crashing the esp. See their documentation .

Ken
Ken 2024 年 10 月 4 日

Thank you for the information.

タグ

タグが未入力です。