0% found this document useful (0 votes)
7 views4 pages

Programa Modem 4G

This document is a C++ program for a 4G modem using an ESP32 microcontroller. It initializes the modem, checks the SIM card status, and sends temperature and humidity data to ThingSpeak via HTTP requests. The program includes debugging options and uses specific pins for RX and TX communication with the modem.

Uploaded by

Jfgf.20087010
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Programa Modem 4G

This document is a C++ program for a 4G modem using an ESP32 microcontroller. It initializes the modem, checks the SIM card status, and sends temperature and humidity data to ThingSpeak via HTTP requests. The program includes debugging options and uses specific pins for RX and TX communication with the modem.

Uploaded by

Jfgf.20087010
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

// Programa modem 4G

#include <stdio.h>

#include <string.h>

String Apikey = "************"; // PASTE YOUR THINGSPEAK API KEY HERE

#define DEBUG true

#define RXD2 27 // RXD INTERNALLY CONNECTED

#define TXD2 26 // TXD INTERNALLY CONNECTED

#define powerPin 4 // MODULE ESP32 PIN D4 CONNECTED TO POWER PIN OF (A7670C)


CHIPSET, INTERNALLY CONNECTED

int rx = -1;

#define SerialAT Serial1

String rxString;

int _timeout;

String _buffer;

void setup()

pinMode(powerPin, OUTPUT);

digitalWrite(powerPin, LOW);

Serial.begin(115200);

delay(100);

SerialAT.begin(115200, SERIAL_8N1, RXD2, TXD2);


delay(10000); //WAITING FOR MODEM RESET

delay(2000);

Serial.println("Modem Reset, Please Wait");

SerialAT.println("AT+CRESET");

delay(1000);

SerialAT.println("AT+CRESET");

delay(20000);

SerialAT.flush();

Serial.println("Echo Off");

SerialAT.println("ATE0"); //120s

delay(1000);

SerialAT.println("ATE0"); //120s

rxString = SerialAT.readString();

Serial.print("Got: ");

Serial.println(rxString);

rx = rxString.indexOf("OK");

if (rx!= -1)

Serial.println("Modem Ready");

delay(1000);

Serial.println("SIM card check");

SerialAT.println("AT+CPIN?"); //9s

rxString = SerialAT.readString();
Serial.print("Got: ");

Serial.println(rxString);

rx = rxString.indexOf("+CPIN: READY");

if (rx!= -1)

Serial.println("SIM Card Ready");

delay(1000);

Serial.print("rx = ");

Serial.print(rx);

Serial.println("4G HTTP Test Begin!");

delay(1000);

void loop()

//--------Get temperature and humidity-------------

float h = random(25, 75);

float t = random(5, 35);;

Serial.print("Humidity: ");

Serial.print(h);

Serial.println("%");

Serial.print("Temperature: ");

Serial.print(t);

Serial.println("°C");
SerialAT.print("Humidity: ");

SerialAT.print(h);

SerialAT.println("%");

SerialAT.print("Temperature: ");

SerialAT.print(t);

SerialAT.println("°C");

delay(1000);

//-----------HTTP---------------------

String http_str = "AT+HTTPPARA=\"URL\",\"https://api.thingspeak.com/update?api_key=" +


Apikey + "&field1=" + (String)t + "&field2=" + (String)h + "\"\r\n";

Serial.println(http_str);

SerialAT.println("AT+HTTPINIT");

delay(200);

SerialAT.println(http_str);

delay(200);

SerialAT.println("AT+HTTPACTION=1");

delay(200);

SerialAT.println("AT+HTTPTERM");

delay(30000);

You might also like