P&S Agriculture Pro 3.0 - Garbage characters when USB not connected

Everything about programming the platform and using the Waspmote API
Post Reply
aschr
Posts: 5
Joined: Mon Aug 12, 2019 10:16 am
Company: Catfish Solutions

P&S Agriculture Pro 3.0 - Garbage characters when USB not connected

Post by aschr » Fri Aug 23, 2019 3:51 pm

Hello,

we have some P&S and configure then (LoRawan app eui; app key etc.) after a reboot via serial/USB connection.

In the sketch we have something like

Code: Select all

...
  USB.flush();
  USB.println(F("wait 10 seconds to receive command from serial..."));
  USB.print(F("> "));

  time = millis();
  while (millis() - time < 10000 || inConfigMode)
  {

    if (USB.available() > 0)
        {
	      inConfigMode = true;
...   
so when a key stroke appeared in the first 10 seconds after boot we enter the CLI. If not the system will continue after 10 seconds.

Everything works fine as long as we have the USB cable connected. But when the USB cable isn't connected we get some strange behavior.
Sometimes the condition USB.available() > 0 seems to bee true and the system stuck inside the cli-mode.

We think there must occur some floating effects on the serial interface when nothing is connected to USB - right?

Any idea how to fix this? Maybe reducing serial speed somehow?

Right now we have a (very inefficient) time-out added to break the cli-mode after some minutes. But this means that any interaction via USB must be completed in that period.

Best regards,
Andreas

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: P&S Agriculture Pro 3.0 - Garbage characters when USB not connected

Post by libelium-dev » Mon Aug 26, 2019 8:28 am

Hi,

We have just performed a brief test and we don't get that behaviour.

Could you please share the full code? The serial uart is shared with the radio module connected to the socket 0. Is there any LoRaWAN function run in the while loop?

What API did you use to upload the code?

Regards

aschr
Posts: 5
Joined: Mon Aug 12, 2019 10:16 am
Company: Catfish Solutions

Re: P&S Agriculture Pro 3.0 - Garbage characters when USB not connected

Post by aschr » Mon Aug 26, 2019 10:35 am

Hello dev,

we call the function handleCommand in the setup routine before initializing the LoRaWAN functionality:

Code: Select all

void handleCommand(Config * conf) {
  uint32_t time = 0;
  int val = 0;
  char buf[128];
  uint8_t i = 0;

  USB.flush();
  USB.println(F("wait 10 seconds to receive command from serial..."));
  USB.print(F("> "));

  time = millis();
  while (millis() - time < 10000 || inConfigMode)
  {

    if (USB.available() > 0)
    {
      inConfigMode = true;
      buf[i] = USB.read();
      if (buf[i] == '\n' || buf[i] == '\r') {
        buf[i] = 0;
        i = 0;

        USB.println(buf);
        time = millis();
        processCmd(buf, conf);
        USB.print(F("> "));
      } else {
        i++;
      }
    }
    if ((millis() - time) % 1000 < 50)
      blinkLED();
    if (inConfigMode  && (millis() - time > 60000))  // break after 1 minute
      inConfigMode = false;
    // Condition to avoid an overflow (DO NOT REMOVE)
    if (millis() < time)
    {
      time = millis();
    }
  }

  USB.println();
  USB.println();
}
in processCmd we handle the typed in commands. blinkLED is used to show that we are inside the cli-mode - especially when no USB cable is connected.

As said before, sometimes we get into the cli-mode when no USB cable is present.

API version v042 i used.


Best regards
Andreas

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: P&S Agriculture Pro 3.0 - Garbage characters when USB not connected

Post by libelium-dev » Thu Aug 29, 2019 8:34 am

Hi,

Apologies for the delay answering.

Please try to add USB.ON() function and a delay at the beginning of the handleCommand() function. We think that it could reduce the noise in the UART.

Code: Select all

void handleCommand(Config * conf) {
  USB.ON();
  delay(100);
  ...
  ...
Regards

aschr
Posts: 5
Joined: Mon Aug 12, 2019 10:16 am
Company: Catfish Solutions

Re: P&S Agriculture Pro 3.0 - Garbage characters when USB not connected

Post by aschr » Thu Aug 29, 2019 3:40 pm

Hi dev,

thank you for the answer but turning on USB again didn't solve my problem - BUT:

I reviewed my code once more. Before calling handleCommand() in the setup routine i print out the device EUI of the LoRa-module.
This seems to be the problem!

An additional delay(100) after calling printDevEUI() and before calling handleCommand() fixed the problem?!

I have no idea why! Does it take some extra time to shut down the LoRa-module?

Here is the test code i used to find and reproduce this:
If there are no keystrokes in ten seconds after 10 times blinking the red LED should stay on

Code: Select all

#include <WaspLoRaWAN.h>
#include <WaspSensorAgr_v30.h>

void printDevEUI() {
  LoRaWAN.ON(SOCKET0);
  USB.print(F("LoRaWAN Device EUI: "));
  LoRaWAN.setDeviceEUI();
  USB.println(LoRaWAN._devEUI);
  LoRaWAN.OFF(SOCKET0);
}

void handleCommand() {
  uint32_t time = 0;
  boolean inConfigMode = false;
  char buf[128];
  uint8_t i = 0;

  USB.flush();
  USB.println(F("wait 10 seconds to receive command from serial..."));
  USB.print(F("> "));
  USB.flush();

  time = millis();
  while (millis() - time < 10000 || inConfigMode)
  {
    if (USB.available() > 0)
    {
      inConfigMode = true;
      buf[i] = USB.read();
      if (buf[i] == '\n' || buf[i] == '\r') {
        buf[i] = 0;
        i = 0;

        USB.println(buf);
        time = millis();
        //processCmd(buf, conf);
        USB.print(F("> "));
      } else {
        i++;
      }
    }

    if ((millis() - time) % 1000 < 50) { // flash once a second while waiting for keystrokes
      Utils.setLED(LED1, LED_ON);
      delay(20);
      Utils.setLED(LED1, LED_OFF);
    }
  }
}
void setup()
{
  USB.ON();
  USB.println(F("Noise on USB?\n"));

  printDevEUI();
  delay(100); // <<-- thats it!

  handleCommand();

  USB.println(F("\ndone."));
  Utils.setLED(LED1, LED_ON);
}

void loop()
{
  // put your main code here, to run repeatedly:

}
Maybe there should be some extra delay(xxx) in LoRaWAN.OFF() by default?


Again, thanks for your support,
best regards
Andreas

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: P&S Agriculture Pro 3.0 - Garbage characters when USB not connected

Post by libelium-dev » Fri Aug 30, 2019 8:16 am

Hi,

The LoRaWAN module and Serial use the UART0 and it is multiplexed. When the multiplexer changes from LoRaWAN to Serial, it could cause noise. Adding a delay, the noise will occur before the code starts to wait for a character.

Regards

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest