I have getting The error while connected with GSM kindly help

void write_google_sheet(String params) {
HTTPClient http;
String url="https://script.google.com/macros/s/"+GOOGLE_SCRIPT_ID+"/exec?"+params;
Serial.println(url);
//Serial.println("Updating Temperature & Humidity Status");
http.begin(url.c_str());
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
int httpCode = http.GET();
Serial.print("HTTP Status Code: ");
Serial.println(httpCode);

String payload;
if (httpCode > 0) {
    payload = http.getString();
    Serial.println("Payload: "+payload);     
}
http.end();

}

But this Same code run well when I am connected wi-fi and while I am using GSM I got this error :slightly_frowning_face:

assert failed: tcpip_send_msg_wait_sem IDF/components/lwip/lwip/src/api/tcpip.c:455 (Invalid mbox)

Backtrace:0x400833a1:0x3ffb20500x40087f01:0x3ffb2070 0x4008cf69:0x3ffb2090 0x400ecf42:0x3ffb21c0 0x400f8f39:0x3ffb21f0 0x400f8f99:0x3ffb2210 0x400ecc79:0x3ffb2260 0x400d6b14:0x3ffb2280 0x400d6875:0x3ffb2510 0x400d6980:0x3ffb2550 0x401216c5:0x3ffb2570 0x400d60ae:0x3ffb2590 0x400d6172:0x3ffb25c0 0x400d62d3:0x3ffb2620 0x400d2b0a:0x3ffb2640 0x400d3ce5:0x3ffb2750 0x400d94d1:0x3ffb2820

Welcome to the forum!

For well-informed help, please read and follow the instructions in the "How to get the best out of the forum" linked at the head of every forum category.

I think you are supposed to pass the TCP/IP Client to the HTTPClient::begin() function, along with the URL. I don't see where you created a GSM Client.

thank for your reply sir ,
this was just a part of my code and I have created GSM client. I would like to share my full code with you. I have just deleted the google script id.

#define SIM800L_IP5306_VERSION_20200811
#include "GPRS.h"
#include <WiFi.h>
#include <Wire.h>
#include <TinyGPS++.h>
#include "utilities.h"

#include <HTTPClient.h>
#include "DHT.h"
#define pi 3.14159265358979323846
#define RXD2 14
#define TXD2 12
#define DHTPIN 4
#define LDR 34
#define DHTTYPE DHT22
//#define SIM800L_IP5306_VERSION_20200811
HardwareSerial neogps(1);
#define SerialMon Serial
#define SerialAT  Serial1

TinyGsmClient client(modem);

float h1=0;
float t1=0;
double latt1;
double lang1;
double latt;
double lang;
int dark1=100;
const char server[] = "script.google.com";
String GAS_ID = "AKfycbxYRm_5hcILyQoXRVhNkLKfulwUG7J93d6miH_rEE7qkFjQsT60Zgv8deS1NCqDb742";

TinyGPSPlus gps;

String GOOGLE_SCRIPT_ID = "AKfycbxYRm_5hcILyQoXRVhNkLKfulwUG7J93d6miH_rEE7qkFjQsT60Zgv8deS1NCqDb742";  // Type your App Script id
const int  port = 80;

DHT dht(DHTPIN, DHTTYPE);


void setup() {
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo native USB port only
  }
  Serial.println(F("DHTxx test!"));
  dht.begin();
  neogps.begin(9600, SERIAL_8N1, RXD2, TXD2);

  // This function call sets up the module but in a blocking matter!
  GPRS_wake_up();
  
  
  
  // If you have other modules to set up, you can call GPRS_init()
  // in a conditional loop and put other modules to setup with it 
  // since it actually uses millis() to time its steps, not delays!
  
  
   /* do{
       GPRS_init();
       
       Other_module_init();
       
    }while(gprs_setup_state != GPRS_READY_ 
           && not(Other_module_ready_condition) 
           && ...)
  */
}

void loop() {


  if(GPRS_connectivity_status())
  {
  Serial.println("Connected to cellular network!");
  
  float dark ;
  int ldr = analogRead(LDR) ;
  dark= map(ldr,0,4095,0,100);
  Serial.println(dark);
  delay (1000);

  
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

   if (isnan(h) || isnan(t) || isnan(f))
  {
    Serial.println(F("Failed to read from DHT sensor!"));
    //return ;
  }
  Serial.println(h);
  Serial.println(t); 

  
/// function to get lat long .
  boolean newData = false;
  for (unsigned long start = millis(); millis() - start < 1000;)
  {
    while (neogps.available())
    {
      if (gps.encode(neogps.read()))
      {
        newData = true;
      }
    }
  }

  //If newData is true
  if(newData == true)
  {
    newData = false;
    latt =(gps.location.lat());
    lang =(gps.location.lng());
    //double sat=gps.satellites.value();
    //Serial.print(latt);
    Serial.println(gps.satellites.value());
    Serial.println(gps.location.lng(),15);
    Serial.println(gps.location.lat(),15);

  }
  else
  {
    Serial.println("no data");
  }  

if(latt==0 && lang ==0)
{
  //latt=latt1;
  //lang=lang1;
  }

  
//double d= distance(latt1,lang1,latt,lang);



//if((abs(h-h1)>=2) || (abs (t-t1)>=.5))//||(abs(d)>=1) || abs(dark-dark1)>=10 )
//{
  Serial.print(F("Temperature "));
  Serial.print(t);
  Serial.println(F("°C "));
  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.println(F("%"));
  t1=t;
  h1=h;
  latt1=latt;
  lang1=lang;
  dark1=dark;
// for writting in google sheet
 write_google_sheet( "value1="+ String(t)+"&value2="+String(h)+"&value3="+String(latt)+"&value4="+String(lang)+"&value5="+String(dark));
 /* SerialMon.print("Connecting to ");
    SerialMon.print(server);
    if (!client.connect(server, port)) {
        SerialMon.println(" fail");
        delay(10000);
        return;
    }
    SerialMon.println(" OK");
    String url = "/macros/s/" + GAS_ID + "/exec?value1=" + String(5)+ "&value2=" + String(8);
    // Make a HTTP GET request:
    SerialMon.println("Performing HTTP GET request...");
    client.print(String("GET ") + url + " HTTP/1.1\r\n");
    client.print(String("Host: ") + server + "\r\n");
    client.print("Connection: close\r\n\r\n");
    client.println();

    unsigned long timeout = millis();
    while (client.connected() && millis() - timeout < 10000L) {
        // Print available data
        while (client.available()) {
            char c = client.read();
            SerialMon.print(c);
            timeout = millis();
        }
    }
SerialMon.println();

    // Shutdown
    client.stop();
    SerialMon.println(F("Server disconnected"));

    //modem.gprsDisconnect();
    //SerialMon.println(F("GPRS disconnected"));
  //}*/
  
  
}
else
{
  Serial.println("not connected");
}
  
  
}

double deg2rad(double);
double rad2deg(double);

double distance(double lat1, double lon1, double lat2, double lon2) {
  double theta, dist;
  if ((lat1 == lat2) && (lon1 == lon2)) {
    return 0;
  }
  else {
    theta = lon1 - lon2;
    dist = sin(deg2rad(lat1)) * sin(deg2rad(lat2)) + cos(deg2rad(lat1)) * cos(deg2rad(lat2)) * cos(deg2rad(theta));
    dist = acos(dist);
    dist = rad2deg(dist);
    dist = dist * 60 * 1.1515;
    dist = dist * 1.609344;
    return (dist);
  }
}

/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
/*::  This function converts decimal degrees to radians             :*/
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
double deg2rad(double deg) {
  return (deg * pi / 180);
}

/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
/*::  This function converts radians to decimal degrees             :*/
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
double rad2deg(double rad) {
  return (rad * 180 / pi);
}

void write_google_sheet(String params) {
   HTTPClient http;
   String url="https://script.google.com/macros/s/"+GOOGLE_SCRIPT_ID+"/exec?"+params;
   Serial.println(url);
    //Serial.println("Updating Temperature & Humidity Status");
    http.begin(url.c_str());
    http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
    int httpCode = http.GET();  
    Serial.print("HTTP Status Code: ");
    Serial.println(httpCode);
    
    String payload;
    if (httpCode > 0) {
        payload = http.getString();
        Serial.println("Payload: "+payload);     
    }
    http.end();
}
/*

  SerialMon.print("Connecting to ");
    SerialMon.print(server);
    if (!client.connect(server, port)) {
        SerialMon.println(" fail");
        delay(10000);
        return;
    }
    SerialMon.println(" OK");
    String url = "/macros/s/" + GAS_ID + "/exec?value1=" + String(5)+ "&value2=" + String(8);
    // Make a HTTP GET request:
    SerialMon.println("Performing HTTP GET request...");
    client.print(String("GET ") + url + " HTTP/1.1\r\n");
    client.print(String("Host: ") + server + "\r\n");
    client.print("Connection: close\r\n\r\n");
    client.println();

    unsigned long timeout = millis();
    while (client.connected() && millis() - timeout < 10000L) {
        // Print available data
        while (client.available()) {
            char c = client.read();
            SerialMon.print(c);
            timeout = millis();
        }
    }
SerialMon.println();

    // Shutdown
    client.stop();
    SerialMon.println(F("Server disconnected"));

    modem.gprsDisconnect();
    SerialMon.println(F("GPRS disconnected"));
    */


// GPRS.h

////GSM module specification
#define TINY_GSM_MODEM_SIM800
#include <TinyGsmClient.h> //https://github.com/vshymanskyy/TinyGSM

//#include "GPRS.h"


// TTGO T-Call pin definitions
#define MODEM_RST                5
#define MODEM_PWRKEY            4
#define MODEM_POWER_ON          23
#define MODEM_TX                27
#define MODEM_RX                26
#define I2C_SDA                 21
#define I2C_SCL                 22
#define MODEM_BAUD_RATE         115200  //115.2 Kb/s baud rate

// GPRS init states
#define GPRS_RESET              0
#define GPRS_START_SERIAL       1
#define GPRS_INIT_MODULE        2
#define GPRS_INIT_MODEM         3
#define GPRS_CONNECT            4
#define GPRS_READY_             5

// GPRS data
#define GPRS_USER               ""
#define GPRS_PASS               ""
#define APN                     "airtelgprs.com"      // APN (google the apn of your network provider in your country)
#define SIM_PIN                 ""      // If SIM is locked, provide the PUK code

// Timeout connection before automatically restarting
#define GPRS_CONN_TIMEOUT       10000UL // 10 seconds

// Hardware Serial for builtin GSM Module
#define SerialAT Serial1 //I'm using an esp32, which have 3 hardware serial ports, i'm using the 2nd for the modem !

void setup_modem();
void GPRS_init();
void GPRS_wake_up();
void GPRS_put_to_sleep();
bool GPRS_connectivity_status();


/// cpp
TinyGsm modem(SerialAT);

// Setup variables
unsigned long GPRS_last_update = 0;
int  gprs_setup_state = 0;
bool serial_ready  = false;
bool module_ready  = false;
bool connect_ready = false;

// Functions' declarations
void GPRS_init(){
  switch(gprs_setup_state){
    case GPRS_RESET:{
      
      gprs_setup_state = 0;
      serial_ready  = false;
      module_ready  = false;
      connect_ready = false;
      
      gprs_setup_state = GPRS_START_SERIAL;
      GPRS_last_update = millis();
      break;
    }
    case GPRS_START_SERIAL:{
      if(!serial_ready) {
        serial_ready = true;
        SerialAT.begin(MODEM_BAUD_RATE, SERIAL_8N1, MODEM_RX, MODEM_TX);
      }
      if(millis() - GPRS_last_update >= 100){
        gprs_setup_state = GPRS_INIT_MODULE;
        GPRS_last_update = millis();
      }
      break;
    }
    case GPRS_INIT_MODULE:{
      if(!module_ready) {
        module_ready = true;
        setup_modem();
      }
      if(millis() - GPRS_last_update >= 3000){
        gprs_setup_state = GPRS_INIT_MODEM;
        GPRS_last_update = millis();
      }
      break;
    }
    case GPRS_INIT_MODEM:{
      modem.restart();
      gprs_setup_state = GPRS_CONNECT;
      GPRS_last_update = millis();
      break;
    }
    case GPRS_CONNECT:{
      if(!connect_ready) {
        connect_ready = true;
        
        // Unlock SIM if PIN is required (;provided)
        if (SIM_PIN && modem.getSimStatus() != 3 ) {
          modem.simUnlock(SIM_PIN);
        }
        // Connect
        modem.gprsConnect(APN, GPRS_USER, GPRS_PASS);
      }
      if(millis() - GPRS_last_update >= 500){
        gprs_setup_state = GPRS_READY_;
      }
      break;
    }
    case GPRS_READY_:{
      break;
    }
    default: break;
  }
}

// Please refer to the datasheet of the SIM800 for more details about this process
void setup_modem(){
  pinMode(MODEM_RST, OUTPUT);
  digitalWrite(MODEM_RST, HIGH);    
  pinMode(MODEM_PWRKEY, OUTPUT);
  pinMode(MODEM_POWER_ON, OUTPUT);
  digitalWrite(MODEM_POWER_ON, HIGH);
  // Pull down PWRKEY for 1 second or more according to manual requirements
  digitalWrite(MODEM_PWRKEY, HIGH);
  delay(10);
  digitalWrite(MODEM_PWRKEY, LOW);
  delay(1000);
  digitalWrite(MODEM_PWRKEY, HIGH);
}

void GPRS_put_to_sleep(){
   SerialAT.write("AT+CSCLK=2\r"); // Enable sleep mode until external interrupt
                                   // Consult datasheet: https://www.elecrow.com/download/SIM800%20Series_AT%20Command%20Manual_V1.09.pdf
                                   // (Page 160, AT+CSCLK Configure Slow Clock)
}

void GPRS_wake_up(){
  unsigned long started_init_ = millis();
  do{
    GPRS_init();
  }while(gprs_setup_state != GPRS_READY_
         && (millis() - started_init_ <= GPRS_CONN_TIMEOUT)); 
         
  if(!modem.isGprsConnected()){ // Couldn't connect
    ESP.restart();
  }
}

bool GPRS_connectivity_status(){
  return modem.isGprsConnected();
 }

What model Arduino are you using?

ESP32 board and arduino IDE

Looks like the TinyGSM library has some limitations with the ESP32:

Have you gotten the HttpClient or WebClient examples from the TinyGSM library to work?

Thank you I am trying And will update you.

I have also changed the baud rate but then also problem is not fixed

Problem and error remain same

Have you gotten the HttpClient or WebClient examples from the TinyGSM library to work?

Yes I have used Httpclient

So compare your sketch to the example sketch to see if you are doing anything differently. Or start over with the HttpClient example and build your sketch on that. Make sure you test often so you can detect a failure early.

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