RAK2270 Sticker Tracker Nov 2023 update

:grinning: @carlrowan I thought I was done with the RAK2270 Sticker Tracker and then you pulled me back in :grinning:

Not sure why I didnā€™t see those settings. Here are my results for the very simple Sine Wave my version of the Hello World Tensorflow type Machine Learning Program:

After turning off LoRaWan and P2P
Sketch uses 143888 bytes (71%) of program storage space. Maximum is 200704 bytes.
Global variables use 25840 bytes (53%) of dynamic memory, leaving 22800 bytes for local variables. Maximum is 48640 bytes.

And it actually goes fairly fast on the Arduino Plotter screen.

After also as above and turning OFF all LoRaWan regions except US915 the memory was:

No Change
Sketch uses 143888 bytes (71%) of program storage space. Maximum is 200704 bytes.
Global variables use 25840 bytes (53%) of dynamic memory, leaving 22800 bytes for local variables. Maximum is 48640 bytes.

After turning back on only LoRaWan not P2P I get

region `ROMā€™ overflowed by 35848 bytes. THAT IS A CONCERN!

After turning off LoRaWan and turning on P2P I get

Sketch uses 164552 bytes (81%) of program storage space. Maximum is 200704 bytes.
Global variables use 27168 bytes (55%) of dynamic memory, leaving 21472 bytes for local variables. Maximum is 48640 bytes.

The sine wave means nothing if an acceleration program doesnā€™t work, but I fired up the NiclaVision ML program a two label motion ML model and it loaded with 88% of memory used. So now I just have to convert that model over to the IMU used by the Sticker Tracker. It only works for P2P but I have a lot of faith in P2P for large onsite companies and Farms.

I also assume a P2P to LoRaWan device would not be that hard to make, but I have never done it. Does anyone have any ideas about that? The P2P collects several results and then hourly uploads a byte to a LoRaWan network, giving you 255 possible outcomes such as: 0 = All Good, 1= issue with the ā€¦ 2= issues with theā€¦, 3=ā€¦

I will post again eventually.

@carlrowan @beegee I need help with one thing. SerialRead(). The standard Serial.read example given for the RAK3172-SIP and you switch between Serial and Serial1 doesnā€™t work with the RAK2270 because you donā€™t have USB Serial and UART TX RX Serial, you only have UART TX, RX serial. Any suggestions how I can input from the keyboard with the RAK2270 Sticker Tracker? The chip has a second TX, RX line but I donā€™t have access to it.

Am I missing something. I even tried turning off ā€œATā€ commands but they strangely still worked. The best scenario would be that I could do SerialRead and ā€œATā€ commands. Any suggestions?

UPDATE: I am able to make Machine Learning models without SerialRead but I am really curious if the Sticker Tracker can do serialRead.


P.S. I did get a machine learning motion model working with P2P compiled for 2 labels. I will test if more labels are possible. The strange part is I got working my 3 year old model based on Eloquent Arduino, but could not get the more modern EdgeImpulse motion model working. It was about 40 K memory short even with all LoRaWan and P2P options disabled

Hi @jerteach ,

Glad to hear your tiny ML model works.

As for Serial.read, this is supported by RUI3. Hereā€™s the documentation.

1 Like

@carlrowan

Oops Thatā€™s a dangerous bit of code. My Rak2270 Sticker Tracker was using AT+BOOT to get into boot mode to upload code. Basically the code below just bricked my board, since it effectively turns off AT commands and now the board canā€™t automatically get into boot mode. I think we already covered that there is no pin combination that forces boot mode.~

Much safer to use :

Serial.begin(115200, RAK_AT_MODE);
void setup() {
  Serial.begin(115200, RAK_CUSTOM_MODE);
}

void loop() {
  //print if you receive data
  if (Serial.available() > 0) {
    Serial.print("Return Byte = ");
    Serial.println(Serial.read());
  }
}

See comments below.

Hi @jerteach ,

AT+BOOT should still work with RAK_CUSTOM_MODE.

As you see here, I sent AT first (65 and 84) followed by AT+BOOT thatā€™s why there is <BOOT MODE> in the image.

I can reupload firmware successfully even with RAK_CUSTOM_MODE.

Thanks @carlrowan after a bit that did work I will edit the comments above. What kind of worked for me was a space before the AT+BOOT.

I think I will work on that code to tidy it up. It needs to echo the AT commands but ATE seems to have no effect also AT seems not to show the regular ā€œOKā€

I will see what I can do.

That did make me get working on my other 2 stickers. With a heat gun to about 90 degrees Celsius the wrapper came off very easy, then just de-solder the battery positive terminal and place a bit of tape below it. Video coming soon. I still need to make a pogoPin arraignment since that hot-glue stuff looks terrible.

image

@carlrowan I prefer this code much better for the RAK2270 sticker tracker. It shows what you enter and runs the AT commands and allows other entries. I will be able to use this. Thanks for setting me on the correct path.

void setup() {
 // Serial.begin(115200, RAK_CUSTOM_MODE);
  Serial.begin(115200, RAK_AT_MODE);
}

void loop() {

   while(Serial.available() > 0) {
    char myChar = Serial.read();
    Serial.print(myChar);
  }
  
}

Btw @jerteach , you can also use ATE = AT Echo to achieve same functionality of that code.

1 Like

I am now working on 3D printing a rIg here for Pogo pins I have ordered and am working on a p2p sending program to combine with my Machine Learning Motion model example and then a p2p receive / LoRaWan send program.

If anyone has example code for the RAk2270 Sticker Tracker that would be nice.

P.S. I have tested straight AT p2p sending and it works fine even to a different system. I use the Arduino PortentaH7 P2P LoRa code

Here is some working P2P code I wrote:



// Expecting all AT P2P commands to be checked or set using AT command entry
/*

sending api.lorawan.nwm.get(): 0
sending api.lorawan.pfreq.get(): 915000000
sending api.lorawan.psf.get(): 7
sending api.lorawan.pbw.get(): 0
sending api.lorawan.pcr.get(): 0
sending api.lorawan.ppl.get(): 8
sending api.lorawan.ptp.get(): 14

 
 */

void recv_cb(rui_lora_p2p_recv_t data)
{
    //rx_done = true;
    if (data.BufferSize == 0) 
    {
      Serial.println("Empty buffer.");
    }
    else
    {
    char buff[92];
    sprintf(buff, "Incoming message, length: %d, RSSI: %d, SNR: %d",data.BufferSize, data.Rssi, data.Snr);
    Serial.println(buff);
    }
   // Serial.printf("P2P set Rx mode %s\r\n", api.lorawan.precv(30000) ? "Success" : "Fail");
}

void send_cb()
{

}

void setup() {
  // put your setup code here, to run once:
    Serial.begin(115200);
    Serial.println("RAKwireless LoRaWan P2P Example");
    Serial.println("AT+BOOT for boot mode. You got 5 Seconds if issues in your code");
    delay(5000);

    Serial.println("P2P Start");
  
    Serial.printf("Hardware ID: %s\r\n", api.system.chipId.get().c_str());
    Serial.printf("Model ID: %s\r\n", api.system.modelId.get().c_str());
    Serial.printf("RUI API Version: %s\r\n",api.system.apiVersion.get().c_str());
    Serial.printf("Firmware Version: %s\r\n",api.system.firmwareVersion.get().c_str());
    Serial.printf("AT Command Version: %s\r\n",api.system.cliVersion.get().c_str());


    Serial.print("sending api.lorawan.nwm.get(): ");
    Serial.println(api.lorawan.nwm.get());

    Serial.print("sending api.lorawan.pfreq.get(): ");
    Serial.println(api.lorawan.pfreq.get());
    
    Serial.print("sending api.lorawan.psf.get(): ");
    Serial.println(api.lorawan.psf.get());
  
    Serial.print("sending api.lorawan.pbw.get(): ");
    Serial.println(api.lorawan.pbw.get());
    
    Serial.print("sending api.lorawan.pcr.get(): ");
    Serial.println(api.lorawan.pcr.get());
   
    Serial.print("sending api.lorawan.ppl.get(): ");
    Serial.println(api.lorawan.ppl.get());
    
    Serial.print("sending api.lorawan.ptp.get(): ");
    Serial.println(api.lorawan.ptp.get());

    api.lorawan.registerPRecvCallback(recv_cb);
    api.lorawan.registerPSendCallback(send_cb);   // why?

}

void loop() 
{ 
  uint8_t payload[] = "payload";
  bool send_result = false;
  send_result = api.lorawan.psend(sizeof(payload), payload);
  Serial.printf("P2P send %s\r\n", send_result ? "Success" : "Fail");
  api.lorawan.precv(5000); 
  delay(10000);  //wait for a reply
  api.lorawan.precv(0); // back to send mode

}


@carlrowan and @Kongduino I think I have found a bug: you can compile the above code for the RAK3272-SIP board with all the normal settings (LoRaWan and P2P) and it works fine, but change the compile setting to just P2P mode and it does not work.

This should be a bug because as far as I know there isnā€™t any LoRaWan needed in the above code. For my machine learning model I need just P2P as the full LoRaWan and P2P takes up too much memory. Any suggestions for a hack to get the above code working for just P2P?

So this is where I am at:

Using the RAK2270 Sticker Tracker:

  1. I can run a very small motion x,y,z , 2 label (flat and on itā€™s side) machine learning program
  2. While that program is running I can use the serial monitor to send P2P commands to another device such as AT+PSEND=112233
  3. I canā€™t run the P2P commands from code using the API as there is not enough space to load the LoRaWan and P2P command set
  4. The compile setting to just load the P2P command set does not seem to run the P2P API. That is what I think is the bug posted above.

Question: Can the serial monitor AT commands be sent from code just to the Serial monitor? I have tried a simple Serial.println("AT+BOOT"); which obviously doesnā€™t work, but is there another way?

@carlrowan

I thought I had a great idea. I connected TX and RX and tried:

Serial.write("AT+PSEND=112233\r\n");

and also

Serial.println(AT+PSEND=112233);

but no P2P LoRa sending. Any idea why?

Update: The followings code from another MCU allowed sending data from the board, but using another MCU defeats the purpose.



#include <Arduino.h> // Only needed by https://platformio.org/

void setup() {
  Serial1.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);   // try on Portenta LEDB = blue, LEDG or LED_BUILTIN = green, LEDR = red 
}

void loop() {

  const char myBuffer[] = "AT+PSEND=3141616263\r\n";
  Serial1.write(myBuffer, sizeof(myBuffer) - 1);

  digitalWrite(LED_BUILTIN, LOW);   // internal LED LOW = on for onboard LED
  delay(4000);                      // wait for a second
  digitalWrite(LED_BUILTIN, HIGH);  
  delay(6000);               
}

What was better here was using Serial1 and the correct speed. With this setup even a regular Serial1.println also works.

But when I try the same concept on the RAK2270 and connect the RX to TX I donā€™t get any P2P LoRA sent. Too bad it would have been a simple solution.

Back to the original questions. Why doesnā€™t compile P2P work with the api to send a P2P command.? Any ideas for a fix?

@carlrowan

No worries I think I solved it with this trick bit of code I dreamed up


#include <service_lora_p2p.h>

void setup() {
  Serial.begin(115200);
  delay(2000);
  Serial.println("You got 10 seconds to AT+BOOT if things screw up");
  delay(10000);
  // Initialize LoRa module
  // Configure LoRa P2P parameters like frequency, bandwidth, spreading factor, etc.
  // Ensure these settings are compatible with the receiver's settings

  // Initialize LoRa P2P service
  service_lora_p2p_init();
}

void loop() {
  // Define the payload
  uint8_t payload[] = {0x31, 0x34, 0x31, 0x36, 0x31}; // Hex representation of "314161"

  // Send the payload using the service_lora_p2p_send function
  service_lora_p2p_send(payload, sizeof(payload), false);

  // Add a delay to avoid continuously sending data
  delay(5000); // 5-second delay
}

I am so close to being finished with this project (which is 2 or more RAK2270 Sticker Trackers with Machine Learning motion analysis and LoRa P2P communication of the inference using webSerial to put the results onto one static webPage.). I have everything working except the specific serial print after the re-programmed sticker receives information over LoRa P2P.

I am just doing a P2P Receive

Serial.write(data.Bufgfer, data.BufferSize);

which gets the data but then I get this weird data confirmation that I canā€™t seem to find out how to get rid of.

Xflipped over
+EVT:RXP2P:-59:12:41666C6970706564206F73657200

Aflipped over
+EVT:RXP2P:-70:12:58666C6970706564206F73657200



@carlrowan
Is there an AT command that turns of the data confirmation?

Hi @jerteach ,

There is no way to disable these callbacks.

1 Like

I am pleased to say that I have all the hard stuff working. Thank you @carlrowan for your assistance.

I should be able to come up with some kind of tutorial about Machine Learning with the RAK2270 Sticker Tracker using the LoRa P2P capabilities and a webSerial static webpage to track the data from multiple devices.

I would also like to show some motion, temperature and humidity (non-machine learning) data exchange using the LoRaWan capabilities. (I havenā€™t started this but it should be do-able.)

My github about it is here but it is not yet ready for showing demos. A video about it should show up here on Youtube at some point.

Here is a visual of the static webpage, but the images were just what I had with me. Each image would show a machine or object you wanted to track information for at your business.

As I said before, thanks Carl. I will post here when I have some demos available.

2 Likes

@carlrowan Here is my RAK2270 Sticker Tracker Pinout diagram

I am starting my tutorials. The unordered playlist is here

Things will get more organized eventually.

1 Like

Working on my course now in a new thread

1 Like