vshymanskyy / TinyGSM

A small Arduino library for GSM modules, that just works
GNU Lesser General Public License v3.0
1.91k stars 709 forks source link

Sim7600E wont connect to network #653

Open HansieHertzog opened 2 years ago

HansieHertzog commented 2 years ago

I have a LilyGO-T-SIM7600 with esp board that I am trying to connect to the internet to post data to a server the problem is that the board does not connect to a network and I get this in my serial monitor.:Wait...Initializing modem...Waiting for network... fail. My sim Is fine as it is the sim I am using in my day-to-day fone. When running an AT command to check the signal I get +CSQ: 18,99 OK.

For now, I just need my board to connect to the internet and then I will work on the rest of the code.

`// Arduino file start here

define TINY_GSM_MODEM_SIM7600

define SerialMon Serial

//#define TINY_GSM_DEBUG SerialMon

include

define SOUND_SPEED 0.034

define CM_TO_INCH 0.393701

HardwareSerial SerialAT(1);

if !defined(TINY_GSM_RX_BUFFER)

define TINY_GSM_RX_BUFFER 1024 // Set RX buffer to 1Kb

endif

define TINY_GSM_YIELD() { delay(2); }

const char apn[] = "myMTN"; const char gprsUser[] = ""; const char gprsPass[] = ""; const char server[] = ""; const char resource[] = ""; const int port = 80; unsigned long timeout;

const int trigPin = 25;
const int echoPin = 26; long duration; int distance;

include

TinyGsm modem(SerialAT); TinyGsmClient client(modem);

void setup() { pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT);

SerialMon.begin(115200); delay(10); SerialMon.println("Wait..."); SerialAT.begin(115200,SERIAL_8N1,27,26, false); delay(600); SerialMon.println("Initializing modem..."); }

void loop() { digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = duration * 0.034 / 2;

modem.restart(); SerialMon.print("Waiting for network..."); if (!modem.waitForNetwork()) { SerialMon.println(" fail"); delay(100); return; } SerialMon.println(" success"); if (modem.isNetworkConnected()) { SerialMon.println("Network connected"); }

SerialMon.print(F("Connecting to ")); SerialMon.print(apn); if (!modem.gprsConnect(apn, gprsUser, gprsPass)) { SerialMon.println(" fail"); delay(1000); return; } SerialMon.println(" success");

if (modem.isGprsConnected()) { SerialMon.println("GPRS connected"); }

if (!client.connect(server, port)) { SerialMon.println(" fail"); } SerialMon.println("Performing HTTP POST request..."); String httpRequestData = "key=a@4K%3&distance="+ String(distance) +""; client.print(String("POST ") + resource + " HTTP/1.1\r\n"); client.print(String("Host: ") + server + "\r\n"); client.println("Connection: close"); client.println("Content-Type: application/x-www-form-urlencoded"); client.print("Content-Length: "); client.println(httpRequestData.length()); client.println(); client.println(httpRequestData); timeout = millis(); while (client.connected() && millis() - timeout < 10000L) { while (client.available()) { char c = client.read(); SerialMon.print(c); timeout = millis(); } } SerialMon.println(); client.stop(); SerialMon.println(F("Server disconnected")); modem.gprsDisconnect(); SerialMon.println(F("GPRS disconnected")); } // End of Arduino file`

JDDV commented 2 years ago

Hi @HansieHertzog, are you sure you're connecting to the right APN? 'myMTN' as APN seems off to me, but I can be wrong. Have you tried using the example code, and see if you can get anything to work? maybe the networkmode is not set correctly or something.