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