Arduino to esp32 data transmission using lora

I am using arduino UNO connected with ultrasonic sensor and lora sx1278 as transmitter. At the receiver I have used ESP32 with another lora sx1278. I can receive the data in serial monitor but not in blynk

This is my receiver code esp32

#define BLYNK_TEMPLATE_ID           "TMPL3JDF0IrHM"
#define BLYNK_TEMPLATE_NAME         "Quickstart Template"
#define BLYNK_AUTH_TOKEN            "a7loU68cogNMZzv2SMupfLxDqkhDDY3Y"
#define BLYNK_PRINT Serial

//Incuding arduino default SPI library
#include <SPI.h>
//Incuding LoRa library
#include <LoRa.h>

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

//define the pins used by the transceiver module
#define NSS 4
#define RST 5
#define DI0 2

char ssid[] = "abcdd";
char pass[] = "123456";

BlynkTimer timer;

String LoRaData;

void setup() {
  //initialize Serial Monitor
  Serial.begin(115200);

  Serial.println("LoRa Receiver");

  //setup LoRa transceiver module
  LoRa.setPins(NSS, RST, DI0);

  while (!LoRa.begin(433E6)) {
    Serial.println(".");
    delay(500);
  }
  // Change sync word (0xF1) to match the receiver LoRa
  // This code ensure that you don't get LoRa messages
  // from other LoRa transceivers
  // ranges from 0-0xFF
  LoRa.setSyncWord(0xF1);
  Serial.println("LoRa Initializing Successful!");
  Blynk.begin(BLYNK_AUTH_TOKEN , ssid, pass); 
  timer.setInterval(1000L, sendSensor);
}

void loop()
{
  Blynk.run();        // run Blynk magic
  timer.run();        // run timer every second
}

void sendSensor() {
  // LoRa data packet size received from LoRa sender
   int packetSize = LoRa.parsePacket();
   // if the packer size is not 0, then execute this if condition
  if (packetSize) {
    // received a packet
    Serial.print("Received packet: ");

    // receiving the data from LoRa sender
    while (LoRa.available()) {
      LoRaData = LoRa.readString();
      Blynk.virtualWrite(V0,LoRaData);
    }
    Serial.println(LoRaData);

  }
    //delay(500);  // Adjust delay as needed
}

I’d start by moving the Blynk.virtualWrite outside of the while loop, and put it alongside the serial print statement.

What sort of datastream is V0, and what type of widget is attached to it?

Pete.

V0 is int data type and I have attached a label to it

void sendSensor() {
  // LoRa data packet size received from LoRa sender
   int packetSize = LoRa.parsePacket();
   // if the packer size is not 0, then execute this if condition
  if (packetSize) {
    // received a packet
    Serial.print("Received packet: ");

    // receiving the data from LoRa sender
    while (LoRa.available()) {
      LoRaData = LoRa.readString();
      Serial.println("LoRa Data: " + LoRaData);  // Print for debugging
    }
    Blynk.virtualWrite(V0,distance);
    Serial.println("End of packet.");

  }
    //delay(500);  // Adjust delay as needed
}

I don’t understand why you’ve changed this to distance

Pete.

I’m sorry that code was full of error. But now i can receive in blynk. Is there any possible way that store data

If you’ve turned on “enable history data” in the V0 datastream.
The values will be averaged over a 1 minute period and the average value saved. If you have a subscription that allows you to enable raw data then every value sent will be stored, and retained for whatever period is specified for your subscription type.

Pete.

Thank You for your help.

1 Like