ESP 8266 , arduino UNO and thingspeak

I want to use ESP8266 with arduino UNO , and send random data to thingspeak but i get error code at "CIP+CLOSE= 0 Fail" can someone help ASAP

#include <SoftwareSerial.h>
#define RX 2
#define TX 3
String AP = "wif";       // AP NAME
String PASS = "nis12345"; // AP PASSWORD
String API = "63GSPYBS2LQPY6KQ";   // 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(9600);
  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;
 }
0:33:24.522 -> 0. at command => AT OYI
10:33:26.889 -> 1. at command => AT+CWMODE=1 OYI
10:33:26.935 -> 2. at command => AT+CWJAP="wif","nis12345" OYI
10:33:31.967 -> 3. at command => AT+CIPMUX=1 OYI
10:33:32.013 -> 4. at command => AT+CIPSTART=0,"TCP","api.thingspeak.com",80 OYI
10:33:32.342 -> 5. at command => AT+CIPSEND=0,58 OYI
10:33:33.967 -> 7. at command => AT+CIPCLOSE=0 Fail
10:33:39.311 -> 0. at command => AT+CIPMUX=1 OYI
10:33:39.311 -> 1. at command => AT+CIPSTART=0,"TCP","api.thingspeak.com",80 OYI

@nornisdalina, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project :wink: See About the Installation & Troubleshooting category.

Note that all people here are volunteers and hence ASAP has no meaning.

hm alright sorry, im newbie here

Why?

What is the purpose of the UNO? :astonished:

The ESP is far more capable.

i want to use 3 sensor later, so i just test signal with random number in thingspeak :frowning: but got error

Interesting enough I suppose, but I really am wondering why you are doing this the hard way, using a UNO where it is clearly not needed. :thinking:

do know how to solve my error?

i guess he'll use uno to serial communication during the thesis , because I used arduino mega and esp 01 to send data sensor in server thingspeak

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.