Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajuda para conectar simcom SIM A7670SA #798

Open
RulioHT2021 opened this issue Jun 14, 2024 · 0 comments
Open

Ajuda para conectar simcom SIM A7670SA #798

RulioHT2021 opened this issue Jun 14, 2024 · 0 comments

Comments

@RulioHT2021
Copy link

[X] Question or request for help

What are you working with?

Modem:
Main processor board:
TinyGSM version:
Code: <!--
#define TINY_GSM_MODEM_A7672X
//Libraries
#include <TinyGsmClient.h>
#include <PubSubClient.h>

//Config SimCom
#define TINY_GSM_RX_BUFFER 1024
#define SerialAT Serial1
#define TINY_GSM_USE_WIFI false

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

const char apn[] = "claro.com.br";
const char gprsUser[] = "claro";
const char gprsPass[] = "claro";

const char* mqtt_server = "message.hidroview.com.br";
const int mqtt_port = 1883;//Your Port
const char* mqtt_topic = "TESTEGSM";
char mqttServer[50] = "X.X.com.br"; //NOME DO SERVIDOR MQTT
char mqttPort[6] = "1883"; //PORTA DO SERVIDOR MQTT >>> INT
char mqttUser[50] = "X"; //USUÁRIO DO SERVIDOR MQTT
char mqttPassword[50] = "X"; //SENHA DO SERVIDOR MQTT

void reconnect() {
while (!mqtt.connected()) {
Serial.println("Conectando ao broker MQTT...");
if (mqtt.connect(mqtt_topic, mqttUser, mqttPassword)) {
Serial.println("Conectado ao broker MQTT");
} else {
Serial.print("Error ao conectar no broker MQTT, rc=");
Serial.print(mqtt.state());
Serial.println(" Reconectando em 5 segundos");
delay(5000);
}
}
}

void setup() {
Serial.begin(115200);
SerialAT.begin(115200, SERIAL_8N1,16,17 );
delay(3000); // Espera para que el módem se inicialice correctamente

String name = modem.getModemName();
Serial.print("Modem Name: "); // Change println to print
Serial.println(name); // Add println for newline

// obtem informações do modem
String ccid = modem.getSimCCID();
Serial.println("CCID: " + ccid);

String imei = modem.getIMEI();
Serial.println("IMEI: " + imei);

String cop = modem.getOperator();
Serial.println("Operator: " + cop);

IPAddress local = modem.localIP();
Serial.println("Local IP: " + String(local));

int csq = modem.getSignalQuality();
Serial.println("Qualidade de sinal: " + String(csq));

// Conectando a VPN
Serial.print("Aguardando a rede...");
if (!modem.waitForNetwork()) {
Serial.println(" falha");
delay(10000);
return;
}
Serial.println(" éxito");

Serial.print(F("Conectando a "));
Serial.print(apn);
if (!modem.gprsConnect(apn)) {
Serial.println(" falha");
delay(10000);
return;
}

// Config mqtt
mqtt.setServer(mqtt_server, mqtt_port);
}

void loop() {
if (!modem.isNetworkConnected()) {
Serial.println("Rede desconectada");
if (!modem.waitForNetwork(180000L, true)) {
Serial.println(" falha");
delay(10000);
return;
}
if (modem.isNetworkConnected()) {
Serial.println("Rede reconectada");
}

if (!modem.isGprsConnected()) {
  Serial.println("GPRS desconectado!");
  Serial.print(F("Conectando a "));
  Serial.print(apn);
  if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
    Serial.println(" falha");
    delay(10000);
    return;
  }
  if (modem.isGprsConnected()) { Serial.println("GPRS reconectado"); }
}

}

if (!mqtt.connected()) {
reconnect();
}
mqtt.loop();
}
-->

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant