I am unable to connect my arduino ESP 8266 01 with Thinkspeak
조회 수: 19 (최근 30일)
이전 댓글 표시
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
Sarfaraz Khan
2022년 5월 17일
connect the Tx pin of esp8266 to the Rx pin of arduino and the Rx pin of esp8266 to Tx pin of arduino
답변 (5개)
Vinod
2020년 1월 29일
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
John Anand
2022년 1월 8일
I Had the same problem and I tried the github stuff and it still didn't work.
댓글 수: 0
Sarfaraz Khan
2022년 5월 17일
connect the Tx pin of esp8266 to the Rx pin of arduino and the Rx pin of esp8266 to Tx pin of arduino
댓글 수: 0
Dharmaseelan Karthigesu
2022년 11월 7일
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;
}
댓글 수: 0
yoyo
2023년 10월 11일
#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;
}
댓글 수: 0
커뮤니티
더 많은 답변 보기: ThingSpeak 커뮤니티
참고 항목
카테고리
Help Center 및 File Exchange에서 Run on Target Hardware에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!