Help, with esp32 and lora

Hi, previously I made a data transmission program from esp32 to another esp32 using LoRa, and using thinger io as the interface resulting from sending the sensor data.
Well before I tried to connect and send data to thinger io and it worked.
but now the data from esp32(receiver) not showing on thinger io.

and this is when i try again now I got nan

my code :

#include <LoRa.h>
#include <SPI.h>
 
#define ss 5
#define rst 14
#define dio0 2

#define THINGER_SERIAL_DEBUG

#include <ThingerESP32.h>
#include "arduino_secrets.h"

ThingerESP32 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

int rssi;
String LoRaMessage;
String jarak;
String sensorValue;
String sensorVoltage;
String tinggiAir;
String readingID;

// Replaces placeholder with Sensor values
String processor(const String& var){
  //Serial.println(var);
  if(var == "jarak"){
    return jarak;
  }
  else if(var == "tinggiair"){
    return tinggiAir;
  }
  else if(var == "sensorValue"){
    return sensorValue;
  }
  else if (var == "RRSI"){
    return String(rssi);
  }
  return String();
}

void setup() {
  // open serial for debugging
  Serial.begin(115200);
  thing.add_wifi(SSID, SSID_PASSWORD);

 
while (!Serial);
  Serial.println("LoRa Receiver");
 int counter;
  LoRa.setPins(ss, rst, dio0);    //setup LoRa transceiver module
 
  while (!LoRa.begin(433E6) && counter < 10)     //433E6 - Asia, 866E6 - Europe, 915E6 - North America
  {
    Serial.println(".");
    counter++;
    delay(500);
  }
  LoRa.setSyncWord(0xA5);
  Serial.println("LoRa Initializing OK!");

  thing["SONIC"] >> [](pson& out){
  out ["jarak"] = jarak;
  };
  thing["WaterLevel"] >> [](pson& out){
  out ["tinggiAir"] = tinggiAir;
  };

  

  
}

void loop() {
 
  int packetSize = LoRa.parsePacket();    // try to parse packet
  if (packetSize) 
  {
    
    Serial.print("Received packet '");
 
    while (LoRa.available())              // read packet
    {
      String LoRaData = LoRa.readString();
      Serial.print(LoRaData); 
      
    int pos1 = LoRaData.indexOf('/');
    int pos2 = LoRaData.indexOf('&');
    readingID = LoRaData.substring(0, pos1);
    jarak = LoRaData.substring(pos1 +1, pos2);
    tinggiAir = LoRaData.substring(pos2+1, LoRaData.length()); 
    }
    Serial.print("' with RSSI ");         // print RSSI of packet
    Serial.println(LoRa.packetRssi());
  }
   thing.handle();
  
}

Hi,

The code seems to be ok, it should connect and report data to thinger.

The issue should be at LoRa segment, are you able to see received data debugging by serial console?

yes i can see the data from serial monitor

I’ve found the problem, I changed the code as below

int pos1 = LoRaData.indexOf("Jarak : ");
    int pos2 = LoRaData.indexOf("cm");
    int pos3 = LoRaData.indexOf("Tinggi Air = ");
    int pos4 = LoRaData.indexOf('/');
    readingID = LoRaData.substring(0, pos1);
    Jarak = LoRaData.substring(pos1 +8, pos2);
    tinggiAir = LoRaData.substring(pos3 +13, pos4); 

but i want to create an email endpoint but i got error

exit status 1

converting to 'String' from initializer list would use explicit constructor 'String::String(int, unsigned char)'

my full code

#include <LoRa.h>
#include <SPI.h>
#include <WiFi.h>

#define THINGER_SERIAL_DEBUG
#define ss 5
#define rst 14
#define dio0 2

#include <ThingerESP32.h>
#include "arduino_secrets.h"

ThingerESP32 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
int rssi;
int locked;
String Jarak;
String tinggiAir;
String readingID;

// Replaces placeholder with DHT values
String processor(const String& var){
  //Serial.println(var);
  if(var == "Jarak"){
    return Jarak;
  }
  else if(var == "tinggiAir"){
    return tinggiAir;
  }
  else if (var == "RRSI"){
    return String(rssi);
  }
  return String();
}

void setup() {
  // open serial for debugging
  Serial.begin(115200);

  thing.add_wifi(SSID, SSID_PASSWORD);

while (!Serial);
  Serial.println("LoRa Receiver");
 int counter;
  LoRa.setPins(ss, rst, dio0);    //setup LoRa transceiver module
 
  while (!LoRa.begin(433E6) && counter < 10)     //433E6 - Asia, 866E6 - Europe, 915E6 - North America
  {
    Serial.println(".");
    counter++;
    delay(500);
  }
  LoRa.setSyncWord(0xA5);
  Serial.println("LoRa Initializing OK!");

  thing["SONIC"] >> [](pson& out){
  out ["Jarak"] = Jarak;
  };
  thing["WaterLevel"] >> [](pson& out){
  out ["tinggiAir"] = tinggiAir;
  };

}

void loop() {
  int packetSize = LoRa.parsePacket();
  if (packetSize) { Serial.print("Received packet '");
 
    while (LoRa.available())              // read packet
    {
      String LoRaData = LoRa.readString();
      Serial.print(LoRaData); 
      
    int pos1 = LoRaData.indexOf("Jarak : ");
    int pos2 = LoRaData.indexOf("cm");
    int pos3 = LoRaData.indexOf("Tinggi Air = ");
    int pos4 = LoRaData.indexOf('/');
    readingID = LoRaData.substring(0, pos1);
    Jarak = LoRaData.substring(pos1 +8, pos2);
    tinggiAir = LoRaData.substring(pos3 +13, pos4); 
    }
    Serial.print("' with RSSI ");         // print RSSI of packet
    Serial.println(LoRa.packetRssi());
  }
  thing.handle();
  
   if(Jarak <=50 && locked==0){
      thing.call_endpoint( EMAIL_ENDPOINT,"SONIC");
      locked=1;
    }else{
      locked = 0;
    }
}

Hi,

Seeing this:

I recommend you to invoque the email endpoint as the example at the documentation:

pson data;
data["temperature"] = dht.readTemperature();
data["humidity"] = dht.readHumidity();
thing.call_endpoint("ExampleEmail", data);

You can check the detailed documentation here → ENDPOINTS - Thinger.io Documentation

Hope this helps.