Professional Documents
Culture Documents
IOT With Cellular Network With ESP32 PDF
IOT With Cellular Network With ESP32 PDF
by Fernando Koyanagi
Today we’ll discuss about the GPRS modem, or SIM800L and a cell phone chip. With this project,
rather, the ESP32 and its use with the cellular therefore, we will send temperature and humidity data
telephone network. This is something that works very through GPRS and MQTT, and visualize the data in a
well. Using the MQTT protocol, we will then send line chart.
data to the Ubidots dashboard. Use in this assembly
a display for feedback of the circuit, in addition to the
https://youtu.be/U_KYGe7ZyKM
Step 1: Demonstration
Step 4: Ubidots
Install SimpleDHT
Install PubSubClient
Install TinyGSM
Install TFT_eSPI
Log in to Ubidots with your account and click on A popup will appear. Click on "Raw."
Devices
Click the text box, and enter the name of the property.
Click the "+" button in the upper right corner
It has to be exactly what we will send in the json of
Click Blank the .ino. Repeat this for the other property.
Enter the device name. Note the "device label," as Go back to the dashboard by clicking on the Ubidots
this will be used in the "topic" that we will use in .ino logo.
In the list of devices, the device you just created will In the dashboard, click on "Add new Widget"
appear. Click on it.
In the list of Widgets, choose "Double axis"
On the screen that appears, click on "Add Variable."
//Tópico onde vamos postar os dados de temperatura e umidade (esp32_gprs é o nome do dispositivo no Ubidots)
#define TOPIC "/v1.6/devices/esp32_gprs"
//Canal serial que vamos usar para comunicarmos com o modem. Utilize sempre 1
HardwareSerial SerialGSM(1);
TinyGsm modemGSM(SerialGSM);
TinyGsmClient gsmClient(modemGSM);
void setup()
{
Serial.begin(115200);
setupDisplay(); //Inicializa e configura o display
setupGSM(); //Inicializa e configura o modem GSM
connectMQTTServer(); //Conectamos ao mqtt server
void setupDisplay()
{
display.init();
display.setRotation(1);
display.fillScreen(TFT_BLUE); //Limpa o display com a cor azul
display.setTextColor(TFT_WHITE, TFT_BLUE); //Coloca o texto como branco com fundo azul
display.setTextWrap(true, true);//Ativa quebra de linha
display.setTextSize(1);
display.setCursor(0, 0, 2); //Posicção x, y e fonte do texto
display.println("Setup Display Complete");
}
void setupGSM()
{
display.println("Setup GSM...");
//Inicializamos a serial onde está o modem
SerialGSM.begin(9600, SERIAL_8N1, 4, 2, false);
delay(3000);
//Inicializa o modem
if (!modemGSM.restart())
{
display.println("Restarting GSM Modem failed");
delay(10000);
ESP.restart();
return;
}
void connectMQTTServer() {
display.println("Connecting to MQTT Server...");
//Se conecta ao device que definimos
if (client.connect(DEVICE_ID, TOKEN, "")) {
//Se a conexão foi bem sucedida
display.println("Connected");
} else {
//Se ocorreu algum erro
display.print("error = ");
display.println(client.state());
delay(10000);
ESP.restart();
}
}
void loop()
{
//Faz a leitura da umidade e temperatura
readDHT();
void readDHT()
{
float t, h;
//Faz a leitura da umidade e temperatura e apenas atualiza as variáveis se foi bem sucedido
if (dht.read2(DHT_PIN, &t, &h, NULL) == SimpleDHTErrSuccess)
{
temperature = t;
humidity = h;
}
}
void publishMQTT()
{
//Cria o json que iremos enviar para o server MQTT
String msg = createJsonString();
Serial.print("Publish message: ");
Serial.println(msg);
//Publicamos no tópico
int status = client.publish(TOPIC, msg.c_str());
Serial.println("Status: " + String(status));//Status 1 se sucesso ou 0 se deu erro
}
String createJsonString()
{
String data = "{";
if(!isnan(humidity) && !isnan(temperature))
{
data+="\"humidity\":";
data+=String(humidity, 2);
data+=",";
data+="\"temperature\":";
data+=String(temperature, 2);
}
data+="}";
return data;
}
void showDataOnDisplay()
{
//Reseta a posição do cursor e mostra umidade e temperatura lidas
display.setCursor(0, 0, 2);
display.println("Humidity: " + String(humidity, 2));
display.println("Temperature: " + String(temperature, 2));
}
INO