vshymanskyy / TinyGSM

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

Ajuda para conectar simcom SIM A7670SA #798

Open RulioHT2021 opened 5 months ago

RulioHT2021 commented 5 months ago

[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

include

//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(); } -->