Hi,
I am trying to upload data collected by the Arduino to the internet with the aid of a sim7600 G-H. i have been able to do so using AT+MQTT style commands and now want to do it without MQTT. Nothing seems to work and after running the code below, the module completely refused to connect to the network. Could anyone please help with this.
Thank you.
// Define the APN (Access Point Name) for your cellular network provider
const char* apn = "telstra.m2m";
// Define the server and resource
const char* server = "httpbin.org";
const int serverPort = 80;
const char* resource = "/get"; // This endpoint returns information about the request
void setup() {
Serial.begin(115200);
Serial1.begin(115200); // Use Hardware Serial 1 for LTE module communication
// Initialize the LTE module
lteInit();
Serial.println("Ready to make HTTP requests.");
}
void loop() {
// Connect to the internet
if (lteConnect()) {
// Make an HTTP GET request to httpbin.org
sendHttpRequest(server, serverPort, resource);
// Disconnect from the internet
lteDisconnect();
}
delay(5000); // Wait for 5 seconds before making the next request
}
void lteInit() {
Serial1.println("AT"); // Send AT command to wake up the module
delay(1000);
Serial1.println("AT+CGATT=1"); // Attach to the network
delay(2000);
Serial1.println("AT+CNMP=13"); // Set network mode to LTE
delay(1000);
Serial1.print("AT+CGDCONT=1,\"IP\",\"");
Serial1.print(apn);
Serial1.println("\""); // Set the APN
delay(1000);
}
bool lteConnect() {
Serial1.println("AT+CGATT?");
delay(500);
while (!Serial1.find("+CGATT: 1")) {
Serial.println("Connecting to LTE network...");
delay(2000);
Serial1.println("AT+CGATT=1");
delay(2000);
}
Serial.println("Connected to LTE network.");
return true;
}
void lteDisconnect() {
Serial1.println("AT+CGATT=0"); // Detach from the network
delay(2000);
Serial1.println("AT+CFUN=0"); // Turn off the module
delay(2000);
}
void sendHttpRequest(const char* server, int port, const char* resource) {
Serial1.print("AT+HTTPPARA=\"CID\",1\r\n");
delay(1000);
Serial1.print("AT+HTTPPARA=\"URL\",\"http://");
Serial1.print(server);
Serial1.print(":");
Serial1.print(port);
Serial1.print(resource);
Serial1.println("\"\r\n");
delay(1000);
Serial1.println("AT+HTTPACTION=0\r\n");
delay(1000);
}