Sim800L cannot Init error

I have moved it to the top but it still has a connection error


#define BLYNK_TEMPLATE_ID "TMPLrKAvPedF"
#define BLYNK_DEVICE_NAME "Dev 2 GSM"
#define BLYNK_AUTH_TOKEN "OTQ0an_SSlPvkE6r7fZU46h2IZx0mxPi"
//-----------------------------------------------------------------------
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG
//-----------------------------------------------------------------------

//-----------------------------------------------------------------------
// Select your modem:
#define TINY_GSM_MODEM_SIM800
//#define TINY_GSM_MODEM_SIM900
//#define TINY_GSM_MODEM_M590
//#define TINY_GSM_MODEM_A6
//#define TINY_GSM_MODEM_A7
//#define TINY_GSM_MODEM_BG96
//#define TINY_GSM_MODEM_XBEE
//-----------------------------------------------------------------------
// Default heartbeat interval for GSM is 60
// If you want override this value, uncomment and set this option:
//#define BLYNK_HEARTBEAT 30
//-----------------------------------------------------------------------
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>
//-----------------------------------------------------------------------
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = BLYNK_AUTH_TOKEN;
//-----------------------------------------------------------------------
// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[]  = "lte.vodacom.za";
char user[] = "";
char pass[] = "";
//-----------------------------------------------------------------------
// Hardware Serial on Mega, Leonardo, Micro
//#define SerialAT Serial1
//-----------------------------------------------------------------------
// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(2, 3); // RX, TX
TinyGsm modem(SerialAT);
//-----------------------------------------------------------------------
#include <DHT.h>
#define DHT11_PIN 4
#define DHTTYPE DHT11
DHT dht(DHT11_PIN, DHTTYPE);
//-----------------------------------------------------------------------
BlynkTimer timer;
#define INTERVAL 1000L
//-----------------------------------------------------------------------



/************************************************************************************
 *  This function sends Arduino's up time every second to Virtual Pin.
 *  In the app, Widget's reading frequency should be set to PUSH. This means
 *  that you define how often to send data to Blynk App.
 **********************************************************************************/
void SendDhtData()
{
  //-----------------------------------------------------------------------
  //Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  //-----------------------------------------------------------------------
  //Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  //-----------------------------------------------------------------------
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }
  //-----------------------------------------------------------------------
  //Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);
  //-----------------------------------------------------------------------
  Serial.print("Temperature: ");
  Serial.println(t);
  Serial.print("Humidity: ");
  Serial.println(h);
  Serial.println("------------------------------------------");
  //-----------------------------------------------------------------------
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V0, t);
  Blynk.virtualWrite(V1, h);
  //-----------------------------------------------------------------------
}


/************************************************************************************
 *  setup() function
 **********************************************************************************/
void setup()
{
  //-----------------------------------------------------------
  // Debug console
  Serial.begin(115200);
  delay(10);
  //-----------------------------------------------------------
  // Set GSM module baud rate
  SerialAT.begin(9600);
  //SerialAT.begin(9600,SWSERIAL_8N1,D3,D4);
  delay(3000);
  //-----------------------------------------------------------
  dht.begin();
  //-----------------------------------------------------------
  // Restart takes quite some time
  // To skip it, call init() instead of restart()
  Serial.println("Initializing modem...");
  //modem.restart();
  // Unlock your SIM card with a PIN
  //modem.simUnlock("1234");
  //-----------------------------------------------------------
Blynk.begin(auth, modem, apn, user, pass, "blynk-cloud.com", 8080);
  //-----------------------------------------------------------
  // Setup a function to be called every second
  timer.setInterval(INTERVAL, SendDhtData);
  //-----------------------------------------------------------  
}


/************************************************************************************
 *  loop() function
 **********************************************************************************/
void loop()
{
  Blynk.run();
  timer.run();
}

blynk-cloud.com belongs to the old blynk, now it’s blynk.cloud

I have changed it to

  // To skip it, call init() instead of restart()
  Serial.println("Initializing modem...");
  //modem.restart();
  // Unlock your SIM card with a PIN
  //modem.simUnlock("1234");
  //-----------------------------------------------------------
Blynk.begin(auth, modem, apn, user, pass, "blynk.cloud", 8080);
  //-----------------------------------------------------------
  // Setup a function to be called every second
  timer.setInterval(INTERVAL, SendDhtData);
  //-----------------------------------------------------------  
}

But still get an Login timeout

You should probably be using port 80, not 8080, but I’d just go with…

Blynk.begin(auth, modem, apn, user, pass);

Pete.

And if that doesn’t work then you should probably read this…

Pete.

Hi Pete

I managed to get it to connect with a global sim card, the issue was with Vodacom.
I now have a error
13:56:03.389 → [33099] >ny3.blynk.cloud[00]80
13:56:03.389 → [33099] Redirecting to ny3.blynk.cloud:80
13:56:03.482 → [33185] Connecting to ny3.blynk.cloud:80
13:56:04.700 → [34425] <[1D|00|01|00] JKKBMrNTb6SM12jWdBtilx6gEFzhASCd
13:56:05.447 → [35168] >[00|00|01|00|C8]
13:56:05.447 → [35169] Ready (ping: 641ms).
13:56:05.447 → [35170] Free RAM: 598
13:56:05.447 → [35171] >[14|00|01|00|08]
13:56:05.447 → [35173] >pm[00]3[00]out
13:56:05.541 → [35236] <[11|00|02|00|8C]ver[00]1.0.1[00]h-beat[00]60[00]buff-in[00]256[00]dev[00]Arduino Uno[00]cpu[00]ATmega328P[00]con[00]SIM800[00]fw-type[00]TMPLV2vFKdqU[00]build[00]Feb 21 2022 13:55:16[00]tmpl[00]TMPLV2vFKdqU[00]
13:56:06.581 → [36269] Cmd error

Please see my code below


#define BLYNK_TEMPLATE_ID "TMPLV2vFKdqU"
#define BLYNK_DEVICE_NAME "Dev1"
#define BLYNK_AUTH_TOKEN "JKKBMrNTb6SM12jWdBtilx6gEFzhASCd"
//-----------------------------------------------------------------------
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG
//-----------------------------------------------------------------------

//-----------------------------------------------------------------------
// Select your modem:
#define TINY_GSM_MODEM_SIM800
//#define TINY_GSM_MODEM_SIM900
//#define TINY_GSM_MODEM_M590
//#define TINY_GSM_MODEM_A6
//#define TINY_GSM_MODEM_A7
//#define TINY_GSM_MODEM_BG96
//#define TINY_GSM_MODEM_XBEE
//-----------------------------------------------------------------------
// Default heartbeat interval for GSM is 60
// If you want override this value, uncomment and set this option:
//#define BLYNK_HEARTBEAT 30
//-----------------------------------------------------------------------
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>
#include "DFRobot_INA219.h"
//-----------------------------------------------------------------------
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = BLYNK_AUTH_TOKEN;
//-----------------------------------------------------------------------
// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[]  = "Justworx";
char user[] = "";
char pass[] = "";
//-----------------------------------------------------------------------
// Hardware Serial on Mega, Leonardo, Micro
//#define SerialAT Serial1
//-----------------------------------------------------------------------
// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(2, 3); // RX, TX
TinyGsm modem(SerialAT);
//-----------------------------------------------------------------------
#include <DHT.h>
#define DHT11_PIN 7
#define DHTTYPE DHT22
DHT dht(DHT11_PIN, DHTTYPE);
DFRobot_INA219_IIC     ina219(&Wire, INA219_I2C_ADDRESS4);

//-----------------------------------------------------------------------

//-----------------------------------------------------------------------
BlynkTimer timer;
#define INTERVAL 1000L

//-----------------------------------------------------------------------
float busvoltage = 0;
float ina219Reading_mA = 1000;
float extMeterReading_mA = 1000;
//-----------------------------------------------------------------------


/************************************************************************************
 *  This function sends Arduino's up time every second to Virtual Pin.
 *  In the app, Widget's reading frequency should be set to PUSH. This means
 *  that you define how often to send data to Blynk App.
 **********************************************************************************/


void SendDhtData()
{
  //-----------------------------------------------------------------------
  //Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  //-----------------------------------------------------------------------
  //Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  //-----------------------------------------------------------------------
 float Voltage = ina219.getBusVoltage_V();
 //------------------------------------------------------------------------
 
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }
  //-----------------------------------------------------------------------
  //Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);
  //-----------------------------------------------------------------------
  Serial.print("Temperature: ");
  Serial.println(t);
  Serial.print("Humidity: ");
  Serial.println(h);
  Serial.println("------------------------------------------");
  //-----------------------------------------------------------------------
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, t);
  Blynk.virtualWrite(V6, h);
  Blynk.virtualWrite(V2,Voltage);
  //-----------------------------------------------------------------------
}


/************************************************************************************
 *  setup() function
 **********************************************************************************/
void setup()
{
  //-----------------------------------------------------------
  // Debug console
  Serial.begin(115200);
  delay(10);
  //-----------------------------------------------------------
  // Set GSM module baud rate
  SerialAT.begin(9600);
  //SerialAT.begin(9600,SWSERIAL_8N1,D3,D4);
  delay(3000);
  //-----------------------------------------------------------
  dht.begin();
  //-----------------------------------------------------------
  // Restart takes quite some time
  // To skip it, call init() instead of restart()
  Serial.println("Initializing modem...");
  //modem.restart();
  // Unlock your SIM card with a PIN
  //modem.simUnlock("1234");
  //-----------------------------------------------------------
  Serial.println();
  while (ina219.begin() != true) {
    Serial.println("INA219 begin faild");
    delay(2000);
  }
  ina219.linearCalibrate(ina219Reading_mA, extMeterReading_mA);
  Serial.println();
  
  //-----------------------------------------------------------
Blynk.begin(auth, modem, apn, user, pass);
  //-----------------------------------------------------------
  // Setup a function to be called every second
  timer.setInterval(INTERVAL, SendDhtData);
  //-----------------------------------------------------------  
}


/************************************************************************************
 *  loop() function
 **********************************************************************************/
void loop()
{
  Blynk.run();
  timer.run();
}

That seems like a very low number.

Pete.

Would that cause the Cmd Error?

I am using the same code with an ethernet shield an it is working

It seems you are commenting the lines where SIM800 is being initialized…
Use mode.init() or modem.restart(), but use one of them…

HTH

Would that affect the cmd error