Connecting to ThinkSpeak With Esp8266 and FireBeetle board Errors

6 Ansichten (letzte 30 Tage)
I am connecting to ThinkSpeak using a Esp8266 chip on a FireBeetle board. And I am using this code:
#include <SoftwareSerial.h>
#define RX 2
#define TX 3
String AP = "**********"; // AP NAME
String PASS = "*********"; // AP PASSWORD
String API = "*************"; // Write API KEY
String HOST = "api.thingspeak.com";
String PORT = "80";
String field = "field1";
int countTrueCommand;
int countTimeCommand;
boolean found = false;
int valSensor = 1;
SoftwareSerial esp8266(RX, TX);
void setup() {
Serial.begin(9600);
esp8266.begin(115200);
sendCommand("AT", 5, "OK");
sendCommand("AT+CWMODE=1", 5, "OK");
sendCommand("AT+CWJAP=\"" + AP + "\",\"" + PASS + "\"", 20, "OK");
}
void loop() {
valSensor = getSensorData();
String getData = "GET /update?api_key=" + API + "&" + field + "=" + String(valSensor);
sendCommand("AT+CIPMUX=1", 5, "OK");
sendCommand("AT+CIPSTART=0,\"TCP\",\"" + HOST + "\"," + PORT, 15, "OK");
sendCommand("AT+CIPSEND=0," + String(getData.length() + 4), 4, ">");
esp8266.println(getData); delay(1500); countTrueCommand++;
sendCommand("AT+CIPCLOSE=0", 5, "OK");
}
int getSensorData() {
return random(1000); // Test
}
void sendCommand(String command, int maxTime, char readReplay[]) {
Serial.print(countTrueCommand);
Serial.print(". at command => ");
Serial.print(command);
Serial.print(" ");
while (countTimeCommand < (maxTime * 1))
{
esp8266.println(command);//at+cipsend
if (esp8266.find(readReplay)) //ok
{
found = true;
break;
}
countTimeCommand++;
}
if (found == true)
{
Serial.println("OYI");
countTrueCommand++;
countTimeCommand = 0;
}
if (found == false)
{
Serial.println("Fail");
countTrueCommand = 0;
countTimeCommand = 0;
}
found = false;
}
__________________________________________________________________________________________________________________
I get this (error?) In the serial monitor when I run it.
Output:
Fail
0. at command => AT+CWMODE=1 Fail
0. at command => AT+CWJAP="******","********" Fail
0. at command => AT+CIPMUX=1 Fail
0. at command => AT+CIPSTART=0,"TCP","api.thingspeak.com",80 Fail
0. at command => AT+CIPSEND=0,51 Fail
1. at command => AT+CIPCLOSE=0 Fail
0. at command => AT+CIPMUX=1 Fail
0. at command => AT+CIPSTART=0,"TCP","api.thingspeak.com",80 Fail
0. at command => AT+CIPSEND=0,51 Fail
1. at command => AT+CIPCLOSE=0 Fail
0. at command => AT+CIPMUX=1 Fail
0. at command => AT+CIPSTART=0,"TCP","api.thingspeak.com",80 Fail
0. at command => AT+CIPSEND=0,51 Fail
1. at command => AT+CIPCLOSE=0 Fail
0. at command => AT+CIPMUX=1 Fail
_________________________________________________________________________________________________________________
What am I doing wrong? The Wifi password and name are correct. I really couldn't find anything online to help. And I'm honestly out of ideas, I've been trying to fix it all day.

Akzeptierte Antwort

John Anand
John Anand am 9 Jan. 2022
I replaced #include "ThingSpeak.h" with a Wifi library, I also changed some of the other code as well so that there are no errors. And one more thing,I changed the baud rate from 115200 to 9600.
_____________________________________________________________________________
#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>
___________________________________________________________________________________
Also in the examples in the github for the esp8266 you have to change the code to this or it gives you this error (below) or a "does not recognize char or int".
(Code)
#include <ESP8266WiFi.h>
#include "secrets.h"
String ssid = "########r"; // AP NAME
String pass = "########"; // AP PASSWORD
String API = "#########"; // Write API KEY
WiFiClient client;
_____________________________________________________________________________________
(Error)
test:1:15: error: 'Name' was not declared in this scope
1 | char ssid[] = Name; // your network SSID (name)
| ^~~~~~~~~~~
test:2:15: error: 'Password' was not declared in this scope
2 | char pass[] = Password ; // your network password
| ^~~~~~~~~~~
test:4:1: error: 'WiFiEspClient' does not name a type
4 | WiFiEspClient client;
| ^~~~~~~~~~~~~
test:7:1: error: expected declaration before '}' token
7 | }
| ^
exit status 1
'SECRET_SSID' was not declared in this scope
____________________________________________________________
But I figured it out and got it working, Thanks for all your help and good luck with your project with the firebeetle boards, I love the firebeetle board, but they have a lot of problems sometimes also if you ever are using the esp8266 I highly recommend using these. Thanks again and have a great day.
http://arduino.esp8266.com/stable/package_esp8266com_index.json
http://download.dfrobot.top/FireBeetle/package_firebeetle8266_index.json

Weitere Antworten (2)

Christopher Stapels
Christopher Stapels am 9 Jan. 2022
Why not try the ThingSpeak library for Arduino and ESP and others ? I think its a lot easier than using the AT command set.
  1 Kommentar
John Anand
John Anand am 9 Jan. 2022
I did and it didn't work with the rest of my code (I am doing a project with other parts). Do you think its a good idea to use a different board than the esp? if so what board?

Melden Sie sich an, um zu kommentieren.


John Anand
John Anand am 9 Jan. 2022
Sorry to bother you again. But I was trying each of the github ones, like you suggested and I got this error.
Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "FireBeetle-ESP8266, 80 MHz, 921600, 4M (3M SPIFFS)"
WARNING: library ESP8266WiFi claims to run on esp8266 architecture(s) and may be incompatible with your current board which runs on firebeetle8266 architecture(s).
WARNING: library ThingSpeak claims to run on avr, esp8266, sam, samd, esp32, samd_beta, megaavr architecture(s) and may be incompatible with your current board which runs on firebeetle8266 architecture(s).
github_second_try_for_esp:32:17: error: invalid conversion from 'const char*' to 'char' [-fpermissive]
char keyIndex = ; // your network key Index number (needed only for WEP)
^
Multiple libraries were found for "ThingSpeak.h"
Used: C:\Users\john\Documents\Arduino\libraries\ThingSpeak
Not used: C:\Users\john\Documents\Arduino\libraries\ThingSpeak-2.0.1
exit status 1
invalid conversion from 'const char*' to 'char' [-fpermissive]
______________________________________________________________________________________________________
But I only have one ThinkSpeak file on my computer.
  2 Kommentare
Christopher Stapels
Christopher Stapels am 9 Jan. 2022
Bearbeitet: Christopher Stapels am 9 Jan. 2023
I am sorry to have led you astray. I didnt realize that the libraries didnt work for Firebeetle esp8266. Ill add it to our list as an enhancement request. There are plenty of other esp8266 board that they work with, for example the node MCU version. I woud suggest an esp32 or an arduino board, such as the nano 33 iot or even the partile Argon. That said, I just ordered two firebeetle esp32 boards, I hope they work with the library. Ill let you know when they arrive. You can generally ignore the multiple library errors, but just in case, you can go in your library manager and make sure the ThingSpeak library is up to the latest version. Do you get the same warning if you try to compile with a blank sketch?
If we truly cant get the ThingSpeak library to work, this examle in the documentation shows you how to make HTTP requests without the ThingSpeak library. (and without the barely any fun AT command list)
John Anand
John Anand am 9 Jan. 2022
I Love braking my head open figuring out the AT commands, I give them an +A for if you want a head ache. I basically made a smart phone with them and LoRa (highly recommend trying Lora out), but there where sooo many errors with the at commands.

Melden Sie sich an, um zu kommentieren.

Communitys

Weitere Antworten in  ThingSpeak Community

Kategorien

Mehr zu REST API finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by