🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Uploading mqtt certificates to LTE module

    General
    3
    8
    5.0k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      jkeyser
      last edited by jkeyser

      How should i go about uploading certificates for mqtt to the LTE module?

      Mainly im looking for how they should be formatted. Currently im just copy-pasting the raw text from the .pem file and uploading it over UART/AT commands, but i keep getting ssl errors and i suspect its because the certificates are not being read in correctly. Ive also tried a string with \n after each line.

      EX:

      AT+CCERTDOWN="clientcert.pem", 1219
      > {raw string of .pem cert}

      1 Reply Last reply Reply Quote 0
      • ajb2k3A
        ajb2k3
        last edited by

        how are you programming the core?

        UIFlow, so easy an adult can learn it!
        If I don't know it, be patient!
        I've ether not learned it or am too drunk to remember it!
        Author of the WIP UIFlow Handbook!
        M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

        J 1 Reply Last reply Reply Quote 0
        • J
          jkeyser @ajb2k3
          last edited by

          @ajb2k3 normally I use the vscode extension, but for basic testing right now im using uiflow

          1 Reply Last reply Reply Quote 0
          • ajb2k3A
            ajb2k3
            last edited by

            In UIFlow you upload the files to the device and use the MQTT setup block to select them

            UIFlow, so easy an adult can learn it!
            If I don't know it, be patient!
            I've ether not learned it or am too drunk to remember it!
            Author of the WIP UIFlow Handbook!
            M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

            J 1 Reply Last reply Reply Quote 0
            • J
              jkeyser @ajb2k3
              last edited by

              @ajb2k3 Maybe im misunderstanding how it works, but I believe you have to upload the certificates to the modem itself using AT commands.

              What i ended up doing was uploading the certs to the device, then just doing an open() in python, then sent those over UART using AT commands to the modem. Everything is working fine now, but not sure if this is the 'proper' way to do it.

              ajb2k3A 1 Reply Last reply Reply Quote 0
              • felmueF
                felmue
                last edited by

                Hello @jkeyser

                I think an MQTT connection can be done in two (maybe more) ways:

                Either by using AT commands to upload the certificates into the modem and the use the built in AT commands for the MQTT connection.

                I assume UIFlow takes another route. It is not using the built-in MQTT AT commands, but rather makes plain internet connection and then uses micropython MQTT commands; hence no need to upload the certificates into the modem.

                Note: above is just a guess, so I could be wrong.

                BTW: I don't think there is a right or wrong way to do it.

                Thanks
                Felix

                GPIO translation table M5Stack / M5Core2
                Information about various M5Stack products.
                Code examples

                1 Reply Last reply Reply Quote 0
                • felmueF
                  felmue
                  last edited by

                  Hello @jkeyser

                  just for fun I asked ChatGPT to provide code to upload a certificate into an SIM7600G modem and after some tweaking I think it could actually work.

                  Note: I have not tested below code myself.

                  #include <SoftwareSerial.h>
                  
                  SoftwareSerial sim7600gSerial(14, 12); // RX, TX pins for ESP32
                  
                  const char* ROOT_CERTIFICATE =
                    "-----BEGIN CERTIFICATE-----\n" \
                    "yrvhNk3cRUBDjAfQ/hp8nQmfQIUpq95CE7Qw8Ty4ekOBL0BtLJjgsL4AqKK1Xf5K\n" \
                    "c6kCqKYW4H8xBjJYlFe//KkF1X8tBRR7ZYh3tBpoaiG4IQKerf6DRd1eQ2qBvA7Y\n" \
                    "OvG+K/8dLQ7BScscx9fJWxkFtXv+j4I2VpO3F8Z9sQHHlk49xdmMxEi2J1U5JBAu\n" \
                    "jyAVhysYtdnE+1p4KhLSWmCU1rlMj54BQrKy38szmR0EzOxZKIZFvywIPkkNcXx2\n" \
                    "aa3CzgIKJVf8AhsgthD9Wp6qu1vkxN0tJj2kF4/shtv4/z2Jj4mDN1/0Cg2hOsQQ\n" \
                    "0PipV/nMhOF0fu8x7n3P9+q8U6SWANJyvKXh3OLjWhS/iPp89xQaC4xlGzTTvwiE\n" \
                    "Zg==\n" \
                    "-----END CERTIFICATE-----\n";
                  
                  void setup() {
                    Serial.begin(9600);
                    sim7600gSerial.begin(9600);
                    delay(1000);
                  
                    // Upload the root certificate to the SIM7600G modem
                    sim7600gSerial.println("AT+CFUN=1"); // Turn on the modem
                    sim7600gSerial.print("AT+CCERTDOWN=\"root_cert.pem\",");
                    sim7600gSerial.println(strlen(ROOT_CERTIFICATE)); // Send the length of the certificate data
                    sim7600gSerial.print(ROOT_CERTIFICATE);
                  }
                  
                  void loop() {
                    // do nothing
                  }
                  

                  Thanks
                  Felix

                  GPIO translation table M5Stack / M5Core2
                  Information about various M5Stack products.
                  Code examples

                  1 Reply Last reply Reply Quote 0
                  • ajb2k3A
                    ajb2k3 @jkeyser
                    last edited by ajb2k3

                    @jkeyser As far as I understand, The certs are held on the processor and the processing in done on the processor not the modem.
                    From the various services I tested (AWS/Azure/Private server and others I cant remember name off without checking my book) all certs are save device side and server side and never transmitted during communications.

                    UIFlow, so easy an adult can learn it!
                    If I don't know it, be patient!
                    I've ether not learned it or am too drunk to remember it!
                    Author of the WIP UIFlow Handbook!
                    M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post