Hi there
I’m currently doing a Lora project, trying to build a Lora communication via multiple nodes to one gateway.
I have tested one esp32 as the device measuring UV light then connected to Thinger and display the value successfully.
The codes for esp32_sender_thinger are shown roughly like:
void setup(void) {
pinMode(LED_BUILTIN, OUTPUT);
thing.add_wifi(SSID, SSID_PASSWORD);
thing[“UV reading”] >> [](pson& out){
out = analogRead(36);
};
}
void loop(void) {
thing.handle();
}
In addition, tested that one node measured UV light and send the value to esp32 as the gateway then connects to Thinger. However, the results are not good.
Codes for the sender node as:
void setup()
{
if (!LoRa.begin(BAND)) {
Serial.println(“Starting LoRa failed!”);
while (1);
}
Serial.println(“LoRa Initial OK!”);
}
void loop()
{
float sensorValue;
sensorValue = analogRead(36);
Serial.print(“UV = “);
Serial.print(sensorValue);
Serial.println(””);
// send packet
LoRa.beginPacket();
LoRa.print("UV = ");
LoRa.print(sensorValue);
LoRa.endPacket();
delay(5000);
}
Codes for gateway :
char qwe= 0;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
thing.add_wifi(SSID, SSID_PASSWORD);
SPI.begin(5,19,27,18);
LoRa.setPins(SS,RST,DI0);
LoRa.begin(BAND);
// register the receive callback
LoRa.onReceive(onReceive);
//define thinger resource
thing [“UV”] >>outputValue(qwe);
// put the radio into receive mode
LoRa.receive();
void loop() {
thing.handle();
}
void onReceive(int packetSize) {
// read packet
for (int i = 0; i < packetSize; i++) {
qwe=(char)LoRa.read();
Serial.print(qwe);
}
}
}
In this case, the result shown at Thinger is a constant number and I guess ‘qwe’ is not updated after receiving Lora packet.
But if I out ’ thing [“UV”] >>outputValue(qwe); ’ within onreceive() like this way :
void onReceive(int packetSize) {
// read packet
for (int i = 0; i < packetSize; i++) {
qwe=(char)LoRa.read();
Serial.print(qwe);
thing [“UV”] >>outputValue(qwe);
}
Thinger will not even display UV source so I guess that thinger resource must be written within setup().
Does anyone have similar experience like what I’m doing? How people normally to deal with the Lora packet data to thinger.io.
So appreciate if someone can give me some advice.