Hi,
Im creatig a 4G GPS tracker with arduino and a SIM7600.
At the botton of this post you can see the program, the same for both version.
I connect the arduino Uno to the computer using USB and with the next circuit, I power the SIM 7600 using other usb in which I only use the ground and the 5 volts, and connect the ground with the Uno so both share the same ground.
Everything works I can send data to the mqtt broker.
So after see that works, I try to do it with my Nano every, to reduce the size. As you can see is connected to the same pin number.
My problem is with nano, doesnt work, so there is any problem with my connection, or something I have to modify? There is any limitation on the Nano?
//DEFINITION
#define TINY_GSM_MODEM_SIM7600 //have to be before the include
#define Terminal Serial
#define SIM7600TX_PIN 3
#define SIM7600RX_PIN 4
#define SIM7600PWR_PIN 5
#define SIM7600SLP_PIN 6
//GPRS credentials
const char apn[] = "";
const char gprsUser[] = "";
const char gprsPass[] = "";
//MQTT
const char* broker = "broker.hivemq.com";
const char* topic = "/testPablo/init";
const char* topiclstWill = "/testPablo/last";
const int mqttPort = 1883;
uint32_t lastReconnectAttempt = 0;
//INCLUDE LIBRARIES
#include <SoftwareSerial.h>
#include <TinyGsmClient.h>
#include <PubSubClient.h>
//VARIABLE
SoftwareSerial SIM7600(SIM7600RX_PIN, SIM7600TX_PIN);
TinyGsm modem(SIM7600);
TinyGsmClient client(modem);
PubSubClient mqtt(client);
//Function
void activateSIM7600(){
Terminal.println("Starting 4G Module...");
pinMode(SIM7600PWR_PIN, OUTPUT);
digitalWrite(SIM7600PWR_PIN,HIGH);
delay(15000); //wait SIM7600 to start
Terminal.println("wait...");
}
bool connectNetwork(){
Terminal.print("Connecting to network...");
modem.gprsConnect(apn, gprsUser, gprsPass);
Terminal.print("Waiting for network...");
if (!modem.waitForNetwork()) {
Terminal.println(" fail");
delay(5000);
return false;
}
Terminal.println(" success");
if (modem.isNetworkConnected()) {
Terminal.println("Network connected");
}
}
void configureSIM7600(){
SIM7600.begin(115200);
modem.init();
String modemInfo = modem.getModemInfo();
Terminal.print("Modem Info: ");
Terminal.println(modemInfo);
connectNetwork();
}
void mqttCallback(char* topic, byte* payload, unsigned int len) {
Terminal.print("Message arrived [");
}
void configureMQTT(){
// MQTT Broker setup
mqtt.setServer(broker, 1883);
mqtt.setCallback(mqttCallback);
}
boolean mqttConnect() {
Terminal.print("Connecting to ");
Terminal.print(broker);
// Connect to MQTT Broker
boolean status = mqtt.connect("GsmClientTest");
//authenticate MQTT:
//boolean status = mqtt.connect("GsmClientName", "mqtt_user", "mqtt_pass");
if (status == false) {
Terminal.println(" fail");
return false;
}
Terminal.println(" success");
mqtt.publish(topic, "GsmClientTest started");
//mqtt.subscribe(topicLed);
return mqtt.connected();
}
void setup() {
Terminal.begin(115200);
delay(10);
activateSIM7600();
configureSIM7600();
configureMQTT();
Terminal.println("Finish configuration");
}
void loop() {
if (!mqtt.connected()) {
Terminal.println("=== MQTT NOT CONNECTED ===");
uint32_t t = millis(); // Reconnect every 10 seconds
if (t - lastReconnectAttempt > 10000L) {
lastReconnectAttempt = t;
if (mqttConnect()) {
lastReconnectAttempt = 0;
}
}
delay(100);
return;
}
mqtt.loop();
}