LTE on GPY using Arduino IDE for faster boot time



  • Hi,

    Are there any examples for using the LTE modem in LTE-M Mode for the GPY in the Arduino IDE? I am working on a bicycle counter using pressure tubes and sensors so I need fast response times to measure the velocity of the passing bikes. The GPY is awakened by a PIR sensor, after that i need to initialise the sensors and be ready to do the measurement. This all needs to be done in less than 1500 ms. Boot time alone is around 1500 ms in Micropython.

    Is there an example available for sending data using MQTT with the Arduino IDE? using the GPY?

    Thanks



  • 807c1d0e-442d-40af-8317-9c070d4cc58c-image.png

    I added an extra line before going to sleep to turn off the modem. The sleep current in this case is 80 uA. Perfect!

      //Set functionallity to 0
      SerialAT.println("AT+CFUN=0");
    


  • I made some progress today using the Tiny GSM Library.

    Here is an example which let the device deep sleep for 1 minute and then wake up and post a MQTT message with the bootCount to an open broker. Then goes to sleep again. The bootCount is stored in RTC memory so it will be saved after going in deep sleep.

    I am using monogoto SIMs, I can advise to use it. It is cheap and lots of debugging possibilities.

    Good luck to anyone who is also looking for examples. If I can help someone you can always send me a message.

    I think the GPY is a great device, we will miss it now it is no longer produced.

    
    #define TINY_GSM_MODEM_SEQUANS_MONARCH
    
    #define SerialMon Serial
    #define SerialAT Serial2
    
    #define GSM_AUTOBAUD_MIN 9600
    #define GSM_AUTOBAUD_MAX 115200
    
    #define TINY_GSM_USE_GPRS true
    #define TINY_GSM_USE_WIFI false
    
    #define GSM_PIN ""
    
    #define uS_TO_S_FACTOR 1000000  /* Conversion factor for micro seconds to seconds */
    #define TIME_TO_SLEEP  60        /* Time ESP32 will go to sleep (in seconds) */
    
    RTC_DATA_ATTR int bootCount = 0;
    
    // Your GPRS credentials, if any
    const char apn[]      = "data.mono";
    const char gprsUser[] = "";
    const char gprsPass[] = "";
    
    // MQTT details
    const char* broker = "broker.hivemq.com";
    
    #include <TinyGsmClient.h>
    #include <PubSubClient.h>
    
    TinyGsm       modem(SerialAT);
    TinyGsmClient client(modem);
    PubSubClient  mqtt(client);
    
    void mqttCallback(char* topic, byte* payload, unsigned int len) {
      SerialMon.print("Message arrived [");
      SerialMon.print(topic);
      SerialMon.print("]: ");
      SerialMon.write(payload, len);
      SerialMon.println();
    }
    
    void setup() {
      // Set console baud rate
      SerialMon.begin(115200);
      delay(10);
    
      bootCount++;
    
      SerialMon.println("Init modem");
    
      SerialAT.begin(LTE_BAUD, SERIAL_8N1, LTE_RX, LTE_TX);
      pinMode(LTE_RTS, OUTPUT);
      digitalWrite(LTE_RTS, LOW);
      delay(6000);
    
      // MQTT Broker setup
      mqtt.setServer(broker, 1883);
      mqtt.setCallback(mqttCallback);
    
      esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
      SerialMon.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) + " Seconds");
    
      SerialMon.println("Initializing modem...");
      modem.restart();
      String modemInfo = modem.getModemInfo();
      SerialMon.print("Modem Info: ");
      SerialMon.println(modemInfo);
      SerialMon.print("Waiting for network...");
      if (!modem.waitForNetwork()) {
        SerialMon.println(" fail");
        delay(10000);
        return;
      }
      SerialMon.println(" success");
    
      if (modem.isNetworkConnected()) {
        SerialMon.println("Network connected");
      }
      SerialMon.print(F("Connecting to "));
      SerialMon.print(apn);
      if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
        SerialMon.println(" fail");
        delay(10000);
        return;
      }
      SerialMon.println(" success");
      if (modem.isGprsConnected()) {
        SerialMon.println("GPRS connected");
      }
      // Make sure we're still registered on the network
      if (!modem.isNetworkConnected()) {
        SerialMon.println("Network disconnected");
        if (!modem.waitForNetwork(180000L, true)) {
          SerialMon.println(" fail");
          delay(10000);
          return;
        }
        if (modem.isNetworkConnected()) {
          SerialMon.println("Network re-connected");
        }
    
        // and make sure GPRS/EPS is still connected
        if (!modem.isGprsConnected()) {
          SerialMon.println("GPRS disconnected!");
          SerialMon.print(F("Connecting to "));
          SerialMon.print(apn);
          if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
            SerialMon.println(" fail");
            delay(10000);
            return;
          }
          if (modem.isGprsConnected()) {
            SerialMon.println("GPRS reconnected");
          }
        }
      }
    
      SerialMon.print("Connecting to ");
      SerialMon.print(broker);
    
      // Connect to MQTT Broker
      boolean status = mqtt.connect("***YourClientName***");
    
      // Or, if you want to authenticate MQTT:
      // boolean status = mqtt.connect("GsmClientName", "mqtt_user", "mqtt_pass");
    
      if (status == false) {
        SerialMon.println(" fail");
      }
      SerialMon.println(" success");
      
      //Convert int to string to char array (might be stupid but it works)
      String str = String(bootCount);
      int str_len = str.length() + 1;
      char char_array[str_len];
      str.toCharArray(char_array, str_len);
    
      mqtt.publish("***YourTopic***, char_array`);
    
      SerialMon.println("Going to sleep now");
      delay(1000);
      SerialMon.flush();
      esp_deep_sleep_start();
      SerialMon.println("Setup Complete");
    }
    
    void loop() {
    }
    

    here is the console output:

    17:17:32.925 -> Init modem
    17:17:38.916 -> Setup ESP32 to sleep for every 60 Seconds
    17:17:38.916 -> Initializing modem...
    17:17:46.733 -> Modem Info: PYCOM FiPy UE5.0.0.0d
    17:17:46.733 -> Waiting for network... success
    17:17:52.386 -> Network connected
    17:17:52.386 -> Connecting to data.mono success
    17:17:56.521 -> GPRS connected
    17:17:56.556 -> Connecting to broker.hivemq.com success
    17:18:01.317 -> Going to sleep now
    
    

Log in to reply
 

Pycom on Twitter