Process class on Arduino IDE sketch won't work with Dragino LG01

I'm trying to upload some sensor data over LoRa to an Amazon AWS account.

I'm using a Dragino LoRa shield + Arduino UNO to read and transmit the sensor data to the LG01 gateway.
I've loaded the Python SDK and all my certificates from AWS into the Linux side of the LG01.

I can get the sensor data from the UNO+Shield to the LG01 and read this out over the console, so I know the data is getting to the LG01 from the sensor.

Separately, if I ssh into the Dragino, I can publish and subscribe to an AWS IoT topic with "made up" data using the python code in the SDK, with mosquitto_pub commands, or with a script, so that works too.

However, I can't seem to call any of these commands from my sketch using the process class.

I'm currently trying the following (which is a sample sketch just to test the Process class connections with AWS):

void mqtt_publish(){
  
  Process p;    
   p.begin("/root/Test");   
   p.run();
 

  // If there's output from Linux,
  // send it out the Console:

  while (p.available()>0) 
  {

    char c = p.read();
    Console.write(c);

  }
  Console.println("Sending..."); // Just to make sure the loop is running in the absence of any other feedback
    
}

where Test is in the root directory and is the command that worked in the Dragino ssh console:

#!/bin/sh


mosquitto_pub -h myuniquedeviceID.amazonaws.com -p 8883 -t TestTopic -m 1973 --cafile root-CA.crt --cert MyCert.cert.pem --key MyKey.private.key

I've also tried:

void mqtt_publish()
{
    Process p;   
    p.begin("mosquitto_pub");
    p.addParameter("-h");
    p.addParameter("mydeviceinfofromAWS.etc..");
    p.addParameter("8883");
    p.addParameter("-t");
    p.addParameter("TestTopic");    
    p.addParameter("-m");
    p.addParameter("1973");
    p.addParameter("--cafile");
    p.addParameter("root-CA.crt");
    p.addParameter("--cert");
    p.addParameter("MyCert.cert.pem");
    p.addParameter("--key");
    p.addParameter("MyKey.private.key");
    p.run();    
  
    while (p.available() > 0) {
      char c = p.read();
      Console.print(c);
    }
    Console.flush();
}

also to no avail. I also tried p.runShellCommand which didn't work either.

I've updated the Bridge library in Arduino IDE and downloaded the latest Firmware (4.3.4) to the Dragino, and I've made sure the MCU is correctly autodetected as ATMega328p and that UART Operation Mode is set to Linux Console/Arduino Bridge.

The problem seems to be in the Process/Bridge, but I can't find out where.

Any help would be appreciated. Thanks!

It looks like you missed the -p flag before the port number (8883).

Oops, I did miss the p flag on my post from a cut and paste error, but not in the actual sketch though

Post complete code! You should make the minimal sketch that shows the problem but the posted code must compile for the target board. These excerpts are a waste of our time.

Ok. That makes sense. Here is the complete code for the sample sketch

#define BAUDRATE 115200

#include <Console.h>
#include <SPI.h>
#include <Process.h>
#include <Bridge.h>


void setup() {
  Bridge.begin(BAUDRATE);
  Console.begin();
  while (!Console) ; 
  Console.println("Start Sketch");

}

void loop() {
  mqtt_publish();
  delay(5000);
}

void mqtt_publish(){
  
  Process p;   
    p.begin("mosquitto_pub");
    p.addParameter("-h");
    p.addParameter("a2y3vq94sucz2m.iot.us-west-2.amazonaws.com");
    p.addParameter("-p");
    p.addParameter("8883");
    p.addParameter("-t");
    p.addParameter("TestTopic");    
    p.addParameter("-m");
    p.addParameter("1973");
    p.addParameter("--cafile");
    p.addParameter("root-CA.crt");
    p.addParameter("--cert");
    p.addParameter("MyCert.cert.pem");
    p.addParameter("--key");
    p.addParameter("MyKey.private.key");
    p.run();    
 

  // If there's output from Linux,
  // send it out to the Console:

  while (p.available()>0) 
  {

    char c = p.read();
    Console.write(c);

  }
  Console.println("Sending..."); // Just to make sure the loop is running since the above lines don't produce any output
    
}

I've also tried changing the mqtt_publish function to run a script as noted elsewhere. Thanks

Do you have any reason to change the default bridge baud rate? Did you change it on the Linux side too? Have you tried to run it using

Bridge.begin();

instead of the version that explicitly selects a non-standard baud rate?

According to the Dragino IoT Mesh Firmware instructions, the baudrate needs to be 115200 to connect to the bridge, so that’s why I changed it in the sketch. That seems to be true because running the sketch with the default baudrate just resulted in the bridge not connecting to the Console and I get the “Is the sketch using the bridge...” message.

I think it’s a Arduino IDE- Dragino compatibility thing at this point. I’m going to try to change the firmware in the gateway to the Arduino Yun version and use the default baudrate, but if that doesn’t work, I guess buy another gateway and node.

Any suggestions on a good gateway and sensor node shield combo?

According to the Dragino IoT Mesh Firmware instructions, the baudrate needs to be 115200 to connect to the bridge

Unfortunately you didn't mention that you changed the firmware. The default firmware is Yun compatible and there 115200 doesn't work.

I don't know if other things were changed in the IoT Mesh Firmware that may make it incompatible with some features the bridge classes offer.

I agree. The gateway came loaded with the IoT Mesh Firmware, so I just upgraded it and stuck with that. I’m hoping going to the Yun firmware will do the trick. Going out of the country for 2 weeks but I’ll update when I get back. Thanks for the help

Problem solved.

The issue was with the directory the mosquitto_pub commands were being run from. I assumed that the commands would run from the root directory on the Linux side of the Dragino gateway, but not so.

I ran the above test script with "pwd" as the Process command, located the directory from the Console output, then added my certificates and keys to that directory.

Everything works fine now.

Thanks for the help