Page 1 of 2

esp-01 http send request simple arduino google sheet

Posted: Thu Jun 27, 2024 10:19 pm
by jokerper
Hi

I have this code and I want to send it to a google sheet.

Code: Select all

[Codebox]
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
WiFiClient client;
const char* ssid = "HomeNetWork";
const char* password = "XXXXXX";
 
const char* serverName = "https://script.google.com/macros/XXXXXX/exec?name=jokerper";
 
 
void setup() {


  Serial.begin(115200);
  
  WiFi.begin(ssid, password);
  Serial.println("Connecting to the Wifi Network");
  while(WiFi.status() != WL_CONNECTED) { 
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("WiFi is Connected at this IP Address : ");
  Serial.println(WiFi.localIP());
 
 
}
 
void loop() {
  
  //Check WiFi connection status
  if(WiFi.status()== WL_CONNECTED){
    HTTPClient http;
    
    http.begin(client,serverName);
    
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");

    // Prepare your HTTP POST request data
    String httpRequestData = "https://XXXXXXXX/exec?name=Per";

    Serial.print("httpRequestData: ");
    Serial.println(httpRequestData);
    
 
    int httpResponseCode = http.POST(httpRequestData);
     
 
    if (httpResponseCode>0) {
      Serial.print("HTTP Response code: ");
      Serial.println(httpResponseCode);
    }
    else {
      Serial.print("Error code: ");
      Serial.println(httpResponseCode);
    }
 
    http.end();
  }
  else {
    Serial.println("WiFi Disconnected");
  }
  delay(15000);  
}

[/Codebox]
This should just be a simple send function to hit my google sheet, but I got error a message code -05.

Anyone who can help me sending a simple way to send to google sheet, from my esp-01 module.

Re: esp-01 http send request simple arduino google sheet

Posted: Fri Jun 28, 2024 9:15 am
by AcmeUK
Where has the original question gone?
And now it is back!!!!
I will not repost my input.

Re: esp-01 http send request simple arduino google sheet

Posted: Fri Jun 28, 2024 2:29 pm
by jokerper
Hi


Yes I have tried to look around but it all seems to be to complicated tutorials.

I just want to send a simple request with no return from the server.

I have this code.gs

Code: Select all


var ss = SpreadsheetApp.openById('MY URL'); //Enter your googlesheets URL Id here
var sheet = SpreadsheetApp.getActiveSheet();
var timezone = "Europe/Copenhagen"; //Set your timezone


function doGet(e){
  Logger.log( JSON.stringify(e) );
  //----------------------------------------------------------------------------------
  //write_google_sheet() function in esp32 sketch, is send data to this code block
  //----------------------------------------------------------------------------------
  //get gps data from ESP32
  if (e.parameter == 'undefined') {
    return ContentService.createTextOutput("Received data is undefined");
  }
  //----------------------------------------------------------------------------------
  var Curr_Date = new Date();
  var Curr_Time = Utilities.formatDate(Curr_Date, timezone, 'HH:mm:ss');
  var name = stripQuotes(e.parameters.name);
  
  Logger.log('name=' + name);
  //----------------------------------------------------------------------------------
  var nextRow = sheet.getLastRow() + 1;
  sheet.getRange("A" + nextRow).setValue(Curr_Date);
  sheet.getRange("B" + nextRow).setValue(Curr_Time);
  sheet.getRange("C" + nextRow).setValue(name);
  //----------------------------------------------------------------------------------

  //returns response back to ESP32
  return ContentService.createTextOutput("Card holder name is stored in column C");
  //----------------------------------------------------------------------------------
}



function stripQuotes( value ) {
  return value.toString().replace(/^["']|['"]$/g, "");
}

//Extra Function. Not used in this project.
//planning to use in future projects.
//this function is used to handle POST request
function doPost(e) {
  var val = e.parameter.value;
  
  if (e.parameter.value !== undefined){
    var range = sheet.getRange('A2');
    range.setValue(val);
  }
}


I want to set in some text in colunm C, the rest do the code.gs

Want a simple call to my "GAS" from my esp-01 module.

Re: esp-01 http send request simple arduino google sheet

Posted: Sat Jun 29, 2024 7:31 pm
by aliarifat794
Personally, I have not tried any yet. But yes, I have seen many projects about how to integrate ESP8266 with Google Sheets. I have found this one quite informative:
https://www.pcbway.com/project/sharepro ... 3663b.html
This project is helpful in every shopping place for billing purposes. They have implemented this project using RFID Reader. They used nodemcu esp8266 microcontroller, LCD display, em-18 reader module, and Arduino IDE. When people go shopping, they have to wait in a queue for the billing process. This solution allows people can make a bill for their purchases by themselves.

Re: esp-01 http send request simple arduino google sheet

Posted: Tue Jul 02, 2024 6:37 pm
by AcmeUK
@jokerper
I just want to send a simple request with no return from the server.
If the online examples are too complex for you, try asking ChatGPT to write some simple code for you.

Re: esp-01 http send request simple arduino google sheet

Posted: Wed Jul 03, 2024 2:06 am
by ESP_Sprite
AcmeUK wrote:
Tue Jul 02, 2024 6:37 pm
If the online examples are too complex for you, try asking ChatGPT to write some simple code for you.
Or do not and rather try to understand the issue and code first. Otherwise, if ChatGPT bullshits faulty or buggy code, you have no way of figuring out what the issue is.

Re: esp-01 http send request simple arduino google sheet

Posted: Wed Jul 03, 2024 9:32 am
by AcmeUK
@ESP_Sprite
if ChatGPT bullshits faulty or buggy code
Is this your experience?
For me, ChatGPT gave me v.b.a. code for the Graph interface where MS did not give examples.
It was not perfect, but was a workable starting point.

Re: esp-01 http send request simple arduino google sheet

Posted: Thu Jul 04, 2024 2:06 am
by ESP_Sprite
AcmeUK wrote:
Wed Jul 03, 2024 9:32 am
It was not perfect, but was a workable starting point.
Exactly. My point is that it can only be a starting point if you know what you need to add, change or fix. If you're clueless about the tech and use ChatGPT as a magic box that comes up with code for all your problems, you're gonna run into trouble.

Re: esp-01 http send request simple arduino google sheet

Posted: Thu Jul 04, 2024 5:56 am
by Inq720
I guess professional developers aren't going to lose jobs yet to AI. :) Give it a day or three more though... I'm glad I'm retired.

Re: esp-01 http send request simple arduino google sheet

Posted: Thu Jul 04, 2024 8:38 am
by AcmeUK
@ESP_Sprite
Agreed. If you are clueless about the tech even the online tutorials will leave you floundering!