I am unable to connect my arduino ESP 8266 01 with Thinkspeak

6 vues (au cours des 30 derniers jours)
Imrul Hasan
Imrul Hasan le 29 Jan 2020
Réponse apportée : yoyo le 11 Oct 2023
0. at command => AT Fail
0. at command => AT+CWMODE=1 Fail
0. at command => AT+CWJAP="knapsack","namespace" Fail
0. at command => AT+CIPMUX=1 Fail
0. at command => AT+CIPSTART=0,"TCP","api.thingspeak.com",80
#include <SoftwareSerial.h>
#define RX 2
#define TX 3
//#define RX 19
//#define TX 18
String AP = "knapsack"; //AP NAME
String PASS = "namespace"; //AP PASSWORD
String API = "FNFJ7KDHJK4F3IU2"; //Write API KEY
String HOST = "api.thingspeak.com";
String PORT = "80";
String field = "Random";
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); // Replace with your own sensor code
}
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;
}
  1 commentaire
Sarfaraz Khan
Sarfaraz Khan le 17 Mai 2022
connect the Tx pin of esp8266 to the Rx pin of arduino and the Rx pin of esp8266 to Tx pin of arduino

Connectez-vous pour commenter.

Réponses (5)

Vinod
Vinod le 29 Jan 2020
Have you considered using the library here: https://github.com/mathworks/thingspeak-arduino
My recommendation is to start from the examples that are part of the library. For example here: https://github.com/mathworks/thingspeak-arduino/tree/master/examples/ESP8266
  2 commentaires
Imrul Hasan
Imrul Hasan le 30 Jan 2020
I didn't try this.... But I tried many resources on youtube none of the technique help me. in the Serial Monitor when i try to use AT command. It does't give Ok message. ... I am new in IoT... How to use your reference code.... Can you please help me ? :(

Connectez-vous pour commenter.


John Anand
John Anand le 8 Jan 2022
I Had the same problem and I tried the github stuff and it still didn't work.

Sarfaraz Khan
Sarfaraz Khan le 17 Mai 2022
connect the Tx pin of esp8266 to the Rx pin of arduino and the Rx pin of esp8266 to Tx pin of arduino

Dharmaseelan Karthigesu
Dharmaseelan Karthigesu le 7 Nov 2022
22:55:26.930 -> 0. at command => AT+CIPMUX=1 Fail
22:55:31.955 -> 0. at command => AT+CIPSTART=0,"TCP","api.thingspeak.com",80 Fail
22:55:47.064 -> 0. at command => AT+CIPSEND=0,60 Fail
22:55:52.566 -> 1. at command => AT+CIPCLOSE=0 Fail
Why there is no data in thingspeak?
#include <SoftwareSerial.h>
#include <dht11.h>
#define RX 2
#define TX 3
#define dht_apin 11 // Analog Pin sensor is connected to
dht11 dhtObject;
String AP = "dharma"; // AP NAME
String PASS = "03049494"; // AP PASSWORD
String API = "K4OY2DV8KSEB5QVP"; // Write API KEY
String HOST = "api.thingspeak.com";
String PORT = "80";
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() {
String getData = "GET /update?api_key="+ API +"&field1="+getTemperatureValue()+"&field2="+getHumidityValue();
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");
}
String getTemperatureValue(){
dhtObject.read(dht_apin);
Serial.print(" Temperature(C)= ");
int temp = dhtObject.temperature;
Serial.println(temp);
delay(50);
return String(temp);
}
String getHumidityValue(){
dhtObject.read(dht_apin);
Serial.print(" Humidity in %= ");
int humidity = dhtObject.humidity;
Serial.println(humidity);
delay(50);
return String(humidity);
}
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;
}

yoyo
yoyo le 11 Oct 2023
#include <SoftwareSerial.h>
#include <dht11.h>
#define RX 2
#define TX 3
#define dht_apin 11 // Analog Pin sensor is connected to
#define mq 12
#define LDR 13
dht11 dhtObject;
String AP = "Sethu"; // AP NAME
String PASS = "123456789"; // AP PASSWORD
String API = "064CP8EN5CYNDI2U"; // Write API KEY
String HOST = "api.thingspeak.com";
String PORT = "80";
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() {
String getData = "GET /update?api_key="+ API +"&field1="+getTemperatureValue()+"&field2="+getHumidityValue()+"&field3="+getairValue()+"&field4="+getlightValue();
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");
}
String getTemperatureValue(){
dhtObject.read(dht_apin);
Serial.print(" Temperature(C)= ");
int temp = dhtObject.temperature;
Serial.println(temp);
delay(50);
return String(temp);
}
String getHumidityValue(){
dhtObject.read(dht_apin);
Serial.print(" Humidity in %= ");
int humidity = dhtObject.humidity;
Serial.println(humidity);
delay(50);
return String(humidity);
}
String getairValue(){
int airqlty = 0;
Serial.print("AIR QUALITY:");
airqlty = analogRead(mq135_pin);
Serial.print(map(analogRead(mq135_pin), 0, 1024, 99, 0));
Serial.print("%");
delay(50);
return String(map(analogRead(mq135_pin), 0, 1024, 99, 0));
}
String getlightValue(){
Serial.print("LIGHT :");
Serial.print(map(analogRead(LDR), 0, 1024, 0, 99));
Serial.print("%");
delay(50);
return String(map(analogRead(LDR), 0, 1024, 0, 99));
}
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;
}

Communautés

Plus de réponses dans  ThingSpeak Community

Catégories

En savoir plus sur Read Data from Channel dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by