0

I want to write my data on google sheets using ESP 01 and Arduino Nano. So I copied code from some website I don't remember the website "how to send data on a local server" and modified it a bit. But it is directly sending the data to the local server only.

Please help me to call Pushing box API and write on Google Sheets.

Here is my current code:

#include<SoftwareSerial.h>

SoftwareSerial comm(12,11); //setting Tx and Rx pins

String server=""; //variable for sending data to webpage
boolean No_IP=false; //variable to check for ip Address
String IP=""; //variable to store ip Address
char temp1='0';
  
int a=0;
int b=0;


void setup() 
{
Serial.begin(9600);
comm.begin(9600);
wifi_init();
Serial.println("System Ready..");
}

void loop() 
{
b=0;
Serial.println("Refresh Page");
while(b<1000)
{
b++;
while(comm.available())
{
if(comm.find("0,CONNECT"))
{
Serial.println("Starting");
sendToServer();
Serial.println("Finished");
delay(1000);
}
}
delay(1);
}
}


void findIp(int time1) //check for the availability of IP Address
{
int time2=millis();
while(time2+time1>millis())
{
while(comm.available()>0)
{
if(comm.find("IP has been read"))
{
No_IP=true;
}
}
}
}

void showIP()//Display the IP Address 
{
IP="";
char ch=0;
while(1)
{
comm.println("AT+CIFSR");
while(comm.available()>0)
{
if(comm.find("STAIP,"))
{
delay(1000);
Serial.print("IP Address:");
while(comm.available()>0)
{
ch=comm.read();
if(ch=='+')
break;
IP+=ch;
}
}
if(ch=='+')
break;
}
if(ch=='+')
break;
delay(1000);
}
Serial.print(IP);
Serial.print("Port:");
Serial.println(80);
}

void establishConnection(String command, int timeOut) //Define the process for sending AT commands to module
{
int q=0;
while(1)
{
Serial.println(command);
comm.println(command); 
while(comm.available())
{
if(comm.find("OK"))
q=8;
}
delay(timeOut);
if(q>5)
break;
q++;
}
if(q==8)
Serial.println("OK");
else
Serial.println("Error");
}

void wifi_init() //send AT commands to module
{
establishConnection("AT",100);
delay(1000);
establishConnection("AT+CWMODE=3",100);
delay(1000);
establishConnection("AT+CWQAP",100); 
delay(1000); 
establishConnection("AT+RST",5000);
delay(1000);

Serial.println("Connecting Wifi....");
establishConnection("AT+CWJAP=\"Leobotics\",\"leobotics123\"",7000); //provide your WiFi username and password here
delay(2000);
Serial.println("Wifi Connected"); 
showIP();
establishConnection("AT+CIPMUX=1",100);
establishConnection("AT+CIPSERVER=1,80",100);
}

void sendData(String server1)//send data to module
{
int p=0;
while(1)
{
unsigned int l=server1.length();
Serial.print("AT+CIPSEND=0,");
comm.print("AT+CIPSEND=0,");
Serial.println(l+2);
comm.println(l+2);
delay(100);
Serial.println(server1);
comm.println(server1);
}
}
void sendToServer()//send data to webpage
{
//String aquib = "http://busgetbeast.in";
sendData("http://api.pushingbox.com/pushingbox?devid=vBDFF4154ABE4F6F&humidityData=33&celData=44&fehrData=111&hicData=22&hifData=77");
      sendData(" HTTP/1.1"); 
      sendData("Host: ");
      sendData("api.pushingbox.com");
      sendData("User-Agent: ESP8266/1.0");
      sendData("Connection: close");
    // sendData();  
delay(5000);
comm.println("AT+CIPCLOSE=0"); 
}

  • better use a library. it will get too complex for direct use of AT commands. WiFiEsp library or WiFiEspAT if you don't need SSL and you can flash AT 1.7 (SDK 3) to esp-01. or write a sketch for the esp for the networking part – Juraj Sep 20 at 8:05
  • I've used WiFiEsp Library, modifying the WebClient Example but still, its showing Data Packet Error (2) – Ansari Aquib Sep 20 at 8:52
  • where is CIPSTART in your sketch? – Juraj Sep 20 at 8:58
  • when i'm adding CIPSTART it showing me error on serial monitor – Ansari Aquib Sep 20 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.