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

jokerper
Posts: 2
Joined: Thu Jun 27, 2024 10:05 pm

esp-01 http send request simple arduino google sheet

Postby jokerper » Thu Jun 27, 2024 10:19 pm

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.
Last edited by jokerper on Fri Jun 28, 2024 10:36 pm, edited 1 time in total.

AcmeUK
Posts: 23
Joined: Wed Dec 06, 2023 5:14 pm

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

Postby AcmeUK » Fri Jun 28, 2024 9:15 am

Where has the original question gone?
And now it is back!!!!
I will not repost my input.
Last edited by AcmeUK on Mon Jul 01, 2024 10:48 pm, edited 4 times in total.

jokerper
Posts: 2
Joined: Thu Jun 27, 2024 10:05 pm

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

Postby jokerper » Fri Jun 28, 2024 2:29 pm

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.

aliarifat794
Posts: 200
Joined: Sun Jun 23, 2024 6:18 pm

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

Postby aliarifat794 » Sat Jun 29, 2024 7:31 pm

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.

AcmeUK
Posts: 23
Joined: Wed Dec 06, 2023 5:14 pm

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

Postby AcmeUK » Tue Jul 02, 2024 6:37 pm

@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.

ESP_Sprite
Posts: 9764
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » Wed Jul 03, 2024 2:06 am

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.

AcmeUK
Posts: 23
Joined: Wed Dec 06, 2023 5:14 pm

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

Postby AcmeUK » Wed Jul 03, 2024 9:32 am

@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.

ESP_Sprite
Posts: 9764
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » Thu Jul 04, 2024 2:06 am

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.

User avatar
Inq720
Posts: 38
Joined: Fri Dec 22, 2023 1:36 pm
Location: North Carolina, USA
Contact:

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

Postby Inq720 » Thu Jul 04, 2024 5:56 am

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.

AcmeUK
Posts: 23
Joined: Wed Dec 06, 2023 5:14 pm

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

Postby AcmeUK » Thu Jul 04, 2024 8:38 am

@ESP_Sprite
Agreed. If you are clueless about the tech even the online tutorials will leave you floundering!

Who is online

Users browsing this forum: No registered users and 14 guests