How to send gps data without USB cable connected from seeeduino lorawan to Loriot server

Currently, I’m able to send the gps data to loriot server via the following guidelines:

<LINK_TEXT text=“https://blog.squix.org/2017/11/using-se … ot-io.html”>https://blog.squix.org/2017/11/using-seeeduino-lorawan-with-gps-and-loriot-io.html</LINK_TEXT>

(Using Seeeduino LoRaWAN with GPS and Loriot.io - Squix - TechBlog - blog.squix.org)



The arduino script below is modified to method ABP from the script inside above post where originally is OTAA method.



#include <TinyGPS++.h>

#include <LoRaWan.h>

#include “DHT.h”





TinyGPSPlus gps;

#define DHTPIN A0 // what pin we’re connected to



#define DHTTYPE DHT11 // DHT 11



DHT dht(DHTPIN, DHTTYPE);

char buffer[256];





void setup(void)

{

SerialUSB.begin(115200);

Serial.begin(9600);



lora.init();



memset(buffer, 0, 256);

lora.getVersion(buffer, 256, 1);

SerialUSB.print(buffer);



memset(buffer, 0, 256);

lora.getId(buffer, 256, 1);

SerialUSB.print(buffer);

SerialUSB.println(“That was the id”);

// void setId(char *DevAddr, char *DevEUI, char *AppEUI);

lora.setId(“008Fxxxx”, “4786C58Bxxxxxxxx”, “526973xxxxxxxxxx”);

// setKey(char *NwkSKey, char *AppSKey, char *AppKey);

lora.setKey(“2B7E151628AED2A6ABF7158809CF4F3C”, “2B7E151628AED2A6ABF7158809CF4F3C”, "8413360695ABxxxxxxxxxxxxxxxxxxxx ");



lora.setDeciveMode(LWABP);

lora.setDataRate(DR0, US915HYBRID);



lora.setChannel(0, 923.2);

lora.setChannel(1, 923.4);

lora.setChannel(2, 922.2);

lora.setChannel(3, 922.4);

lora.setChannel(4, 922.6);

lora.setChannel(5, 922.8);

lora.setChannel(6, 923.0);

lora.setChannel(7, 922.1);



lora.setReceiceWindowFirst(0);

lora.setReceiceWindowSecond(923.3, DR2);

lora.setAdaptiveDataRate(false);



lora.setPower(20);



//while(!lora.setOTAAJoin(JOIN, 20000));

//SerialUSB.println(“After OTAA join”);



// Start DHT sensor

dht.begin();

}



void loop(void)

{

while (Serial.available() > 0) {

gps.encode(Serial.read());

}

if (gps.altitude.isUpdated()) {

SerialUSB.println(gps.altitude.meters());

SerialUSB.print(“LAT=”); SerialUSB.println(gps.location.lat(), 6);

SerialUSB.print(“LONG=”); SerialUSB.println(gps.location.lng(), 6);

SerialUSB.print(“ALT=”); SerialUSB.println(gps.altitude.meters());

long latEncoded = (gps.location.lat() * 8388606) / 90;

long lonEncoded = (gps.location.lng() * 8388606) / 180;

SerialUSB.print("Lat encoded: ");

SerialUSB.println(latEncoded);

SerialUSB.print("Lon encoded: ");

SerialUSB.println(lonEncoded);

float h = dht.readHumidity();

float t = dht.readTemperature();

SerialUSB.print("Humidity is: “);

SerialUSB.print(h);

SerialUSB.print(”, Temperature: ");

SerialUSB.print(t);

bool result = false;

byte data[10] = {0};

data[0] = h;

data[1] = t + 100;

data[2] = (byte) (latEncoded >> 16);

data[3] = (byte) (latEncoded >> 8);

data[4] = (byte) latEncoded;



data[5] = (byte) (lonEncoded >> 16);

data[6] = (byte) (lonEncoded >> 8);

data[7] = (byte) lonEncoded;



result = lora.transferPacket(data, 10);

//result = lora.transferPacket(data, 10, 10);



if(result)

{

short length;

short rssi;



memset(buffer, 0, 256);

length = lora.receivePacket(buffer, 256, &rssi);



if(length)

{

SerialUSB.print("Length is: ");

SerialUSB.println(length);

SerialUSB.print("RSSI is: ");

SerialUSB.println(rssi);

SerialUSB.print("Data is: “);

for(unsigned char i = 0; i < length; i ++)

{

SerialUSB.print(“0x”);

SerialUSB.print(buffer[i], HEX);

SerialUSB.print(” ");

}

SerialUSB.println();

}

delay(1000 * 60 * 5);

}

}



}



My seeeduino lorawan w/gps board is connected to USB cable and 3.7 volt 350mAh lipo battery via jst connector. After I uploaded the arduino script attached, the data is shown on the loriot server every 5 minutes. Unfortunately, when I removed the USB cable, the board is unable to send the gps data with tx, red light (in Diagram_01) on (when the first 5 min interval after remove the USB cable).



Can I know how to send data continuously from seeeduino lorawan w/gps board to loriot server as I need to install the seeeduino board in small boat and tracking their gps coordinates? So, I cannot have the USB cable connected while sending gps coordintes.

Hello,

Could you please post how you connect the circuit? I suggest you burn a blink program first to verify if the circuit can work then try programs that are more complicated.

Good luck!

Hello,

I’m sry for my omission that I have not considered you did not connect the USB port.

When there are SerialUsb code but the USB port is not connected, the program might be pended.

So you need to delete all of them.

Hope the information can help you.

Hi, I already comment out all Serial.USB remain Serial,begin(9600) and Serial.available. After I unplugged the transmission is stopped and the red LED light to light up. But If I comment the Serial lines also, the transmission of data cannot start. So, may I know is there any alternative to replace the Serial lines that work under the condition of the USB cable is unpugged?



The following are the code:



#include <TinyGPS++.h>

#include <LoRaWan.h>

#include “DHT.h”





TinyGPSPlus gps;

#define DHTPIN A0 // what pin we’re connected to



#define DHTTYPE DHT11 // DHT 11



DHT dht(DHTPIN, DHTTYPE);

char buffer[256];





void setup(void)

{

//SerialUSB.begin(115200);

Serial.begin(9600);



lora.init();



memset(buffer, 0, 256);

lora.getVersion(buffer, 256, 1);

//SerialUSB.print(buffer);



memset(buffer, 0, 256);

lora.getId(buffer, 256, 1);

//SerialUSB.print(buffer);

//SerialUSB.println(“That was the id”);

// void setId(char *DevAddr, char *DevEUI, char *AppEUI);

lora.setId(NULL, “4786C58B003C002A”, “526973696E674846”);

// setKey(char *NwkSKey, char *AppSKey, char *AppKey);

lora.setKey(NULL, NULL, “2B7E151628AED2A6ABF7158809CF4F3C”);



lora.setDeciveMode(LWOTAA);

lora.setDataRate(DR2, AS923);



lora.setChannel(0, 923.0);

lora.setChannel(1, 923.2);

lora.setChannel(2, 923.4);

lora.setChannel(3, 923.6);

lora.setChannel(4, 923.8);

lora.setChannel(5, 924.0);

lora.setChannel(6, 924.2);

lora.setChannel(7, 924.4);



lora.setReceiceWindowFirst(2, 923.2);

lora.setReceiceWindowSecond(923.2, DR2);

lora.setAdaptiveDataRate(false);



lora.setPower(10);



while(!lora.setOTAAJoin(JOIN, 20000));

//SerialUSB.println(“After OTAA join”);



// Start DHT sensor

dht.begin();

}



void loop(void)

{

while (Serial.available() > 0) {

gps.encode(Serial.read());

}

if (gps.altitude.isUpdated()) {

//SerialUSB.println(gps.altitude.meters());

//SerialUSB.print(“LAT=”); SerialUSB.println(gps.location.lat(), 6);

//SerialUSB.print(“LONG=”); SerialUSB.println(gps.location.lng(), 6);

//SerialUSB.print(“ALT=”); SerialUSB.println(gps.altitude.meters());

long latEncoded = (gps.location.lat() * 8388606) / 90;

long lonEncoded = (gps.location.lng() * 8388606) / 180;

//SerialUSB.print("Lat encoded: ");

//SerialUSB.println(latEncoded);

//SerialUSB.print("Lon encoded: ");

//SerialUSB.println(lonEncoded);

float h = dht.readHumidity();

float t = dht.readTemperature();

//SerialUSB.print("Humidity is: “);

//SerialUSB.print(h);

//SerialUSB.print(”, Temperature: ");

//SerialUSB.print(t);

bool result = false;

//SerialUSB.println(result);

byte data[10] = {0};

data[0] = h;

data[1] = t + 100;

data[2] = (byte) (latEncoded >> 16);

data[3] = (byte) (latEncoded >> 8);

data[4] = (byte) latEncoded;

data[5] = (byte) (lonEncoded >> 16);

data[6] = (byte) (lonEncoded >> 8);

data[7] = (byte) lonEncoded;



result = lora.transferPacket(data, 10);

//result = lora.transferPacket(data, 10, 10);

//SerialUSB.println(result);

if(true)

{

short length;

short rssi;



memset(buffer, 0, 256);

length = lora.receivePacket(buffer, 256, &rssi);



if(length)

{

//SerialUSB.print("Length is: ");

//SerialUSB.println(length);

//SerialUSB.print("RSSI is: ");

//SerialUSB.println(rssi);

//SerialUSB.print("Data is: “);

for(unsigned char i = 0; i < length; i ++)

{

//SerialUSB.print(“0x”);

//SerialUSB.print(buffer[i], HEX);

//SerialUSB.print(” ");

}

//SerialUSB.println();

}

delay(1000 * 60 * (0.5));

}

}



}



Thanks

Hello,

Pls tell me how did you supply the power(a pic of wire connection is primary) and what kind of battery did you use.

Thx!