BLYNK
BLYNK.IO       📲 GETTING STARTED       đź“— DOCS       👉 SKETCH BUILDER

Uno as sender, Nodemcu as Reciever using Lora ra-02

I need help to figure out whats wrong in my code connecting in blynk app

Arduino Code

#include <LoRa.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 7
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
const int sensorpin = A0;
int counter = 0;
String data = "Jex";
int temp, volt;

void setup() {
  Serial.begin(9600);
  while (!Serial);

  Serial.println("LoRa Sender");

  LoRa.setPins(10, 9, 2); // 10, 9 for UNO, 53, 9 for Mega, 15, 16, for ESP8266

  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
}

void loop() {
   float sensorValue = analogRead(sensorpin);
  float volt = sensorValue * (3.3 / 1025.0) * 3;  // Convertion
  DS18B20.requestTemperatures();
  temp = DS18B20.getTempCByIndex(0);  // Celcius
  
  Serial.print("Sending packet: ");
  Serial.println(counter);
  Serial.print("Temperature: ");
  Serial.println(temp);
  Serial.print("Turbidity: ");
  Serial.println(volt);
  // send packet
  LoRa.beginPacket();
  LoRa.println(data);
  LoRa.println(temp);
  LoRa.println(volt);
  LoRa.print(counter);
  LoRa.endPacket(); 

  counter++;

  delay(5000);
}

Nodemcu Code

#include <LoRa.h>
#include<ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#define BLYNK_TEMPLATE_ID "TMPLu_JPWrOy"
#define BLYNK_TEMPLATE_NAME "WATER QUALITY MONITORING SYSTEM USING LORA"
#define BLYNK_AUTH_TOKEN "XUkl9QTecRSQCYd7y2KDUTqyv9zNcn9C"
#define BLYNK_PRINT Serial

char auth[] = "XUkl9QTecRSQCYd7y2KDUTqyv9zNcn9C";
char ssid[]="Pro";
char password[]="123456789";
float temp,ph,volt;

BlynkTimer timer;

void setup() {
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass, "blynk.cloud"); 
    timer.setInterval(1000L, sendSensor);
  while (!Serial);

  Serial.println("LoRa Receiver");

  LoRa.setPins(15, 16, 2); // 10, 9 for UNO, 53, 9 for Mega, 15, 16, for ESP8266
  
  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
 
}

void loop() {
  Blynk.run();
      timer.run();
  // try to parse packet
  
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    // received a packet
    Serial.print("Received packet '");
    Serial.println("Temperature: ");
    Serial.println("Turbidity: ");   
    Serial.println("pH: ");

    // read packet
     while (LoRa.available()){
      String data = LoRa.readString();
      Serial.println(data);
      String temp = LoRa.readString();
      Serial.println(temp);      
      String volt = LoRa.readString();
      Serial.print(volt);     
      String ph = LoRa.readString();
      Serial.println(ph);
    }
    // print RSSI of packet

    Serial.print("' with RSSI ");
    Serial.println(LoRa.packetRssi());
  }
 
}

 void sendSensor()
      {
        Blynk.virtualWrite(V0,temp);
        Blynk.virtualWrite(V1,ph);
        Blynk.virtualWrite(V2,volt);
        }

There’s lots of things wrong with your NodeMCU code from a Blynk point of view, but what are you seeing in your NodeMCU’s serial monitor with your current code?

Pete.

this my new code in nodemcu

#define BLYNK_TEMPLATE_NAME "WATER QUALITY MONITORING SYSTEM USING LORA"
#define BLYNK_AUTH_TOKEN "XUkl9QTecRSQCYd7y2KDUTqyv9zNcn9C"
#define BLYNK_PRINT Serial

#include <SPI.h>
#include <LoRa.h>
#include<ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>


char auth[] = "XUkl9QTecRSQCYd7y2KDUTqyv9zNcn9C";
char ssid[]="Pro";
char pass[]="123456789";
float temp,ph,volt;

BlynkTimer timer;

void setup() {
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass, "blynk.cloud"); 
    timer.setInterval(1000L, loop);
  while (!Serial);

  Serial.println("LoRa Receiver");

  LoRa.setPins(15, 16, 2); // 10, 9 for UNO, 53, 9 for Mega, 15, 16, for ESP8266
  
  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
 
}

void loop() {
  Blynk.run();
      timer.run();
  // try to parse packet
  
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    // received a packet
    Serial.print("Received packet '");

    // read packet
     while (LoRa.available()){
      String data = LoRa.readString();
      Serial.println(data);
      String temp = LoRa.readString();
      Serial.println(temp);      
      String volt = LoRa.readString();
      Serial.print(volt);     
      String ph = LoRa.readString();
      Serial.println(ph);
          Blynk.virtualWrite(V0, temp.toInt());
        Blynk.virtualWrite(V1, temp.toInt());
        Blynk.virtualWrite(V2, temp.toInt());
    }
    // print RSSI of packet

    Serial.print("' with RSSI ");
    Serial.println(LoRa.packetRssi());
  }
 
}


Serial Monitor



' with RSSI -44
Received packet 'Jex
29
9.41
326


' with RSSI -44

its already recieve the uno data but in the blynk it didnt display

Your new code is even worse.
Please revert to your original code and answer my original question.

Pete.

[19504] Ready (ping: 49ms).
LoRa Receiver
Received packet 'Temperature: 
Turbidity: 
pH: 
Jex
29
9.42
951

this the thing in my serial monitor.

Okay, your original sketch declares the variables temp, ph and volt as global variables…

but you then re-declare these same variables as local string types in your void loop…

this means that the vales that you assign to these variables in your void loop only exist in side your void loop, so when you try to do this…

you’re sending the global float variable values (which are all zero, because you didn’t give them any initial values when declared them at the top of your sketch).

You should read this…

https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean

and re-structure your vid loop so that it contains only…

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

then move your LoRa and Blynk code into a function that is called with a BlynkTimer say once every 1000ms.

You also need to stop re-declaring your variables, and be careful about converting between string and float variable types.

I’d also recommend putting these at the very top of your sketch…

deleting this line…

and changing this line…

to this…

Blynk.begin(BLYNK_AUTH_TOKEN , ssid, pass);

Pete.

can i seperate this three output ?

can you give me example code to seperate this three output, because in blynk app they together

From what you’ve said in your previous posts, your original code was already doing this.
What have you changed?

Pete.

Arduino Uno Code

#include <SPI.h>
#include <LoRa.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ArduinoJson.h> //REQUIRES ARDUINO JSON V6
#include<String.h>

#define ONE_WIRE_BUS 7
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
const int sensorpin = A0;
int counter = 0;
String data = "Jex";
int temp, volt;

void setup() {
  Serial.begin(9600);
  while (!Serial);

  Serial.println("LoRa Sender");

  LoRa.setPins(10, 9, 2); // 10, 9 for UNO, 53, 9 for Mega, 15, 16, for ESP8266

  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
}

void loop() {
   float sensorValue = analogRead(sensorpin);
  float volt = sensorValue * (3.3 / 1025.0) * 3;  // Convertion
  DS18B20.requestTemperatures();
  temp = DS18B20.getTempCByIndex(0);  // Celcius
  
  Serial.print("Sending packet: ");
  Serial.println(counter);
  Serial.print("Temperature: ");
  Serial.println(temp);
  Serial.print("Turbidity: ");
  Serial.println(volt);

  // send packet
  LoRa.beginPacket();
  LoRa.println(data);
  LoRa.println(temp);
  LoRa.println(volt);
  LoRa.print(counter);
  LoRa.endPacket(); 

  counter++;

  delay(5000);
}

#include <SPI.h>
#include <LoRa.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ArduinoJson.h> //REQUIRES ARDUINO JSON V6
#include<String.h>

#define ONE_WIRE_BUS 7
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
const int sensorpin = A0;
int counter = 0;
String data = "Jex";
int temp, volt;

void setup() {
  Serial.begin(9600);
  while (!Serial);

  Serial.println("LoRa Sender");

  LoRa.setPins(10, 9, 2); // 10, 9 for UNO, 53, 9 for Mega, 15, 16, for ESP8266

  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
}

void loop() {
   float sensorValue = analogRead(sensorpin);
  float volt = sensorValue * (3.3 / 1025.0) * 3;  // Convertion
  DS18B20.requestTemperatures();
  temp = DS18B20.getTempCByIndex(0);  // Celcius
  
  Serial.print("Sending packet: ");
  Serial.println(counter);
  Serial.print("Temperature: ");
  Serial.println(temp);
  Serial.print("Turbidity: ");
  Serial.println(volt);

  // send packet
  LoRa.beginPacket();
  LoRa.println(data);
  LoRa.println(temp);
  LoRa.println(volt);
  LoRa.print(counter);
  LoRa.endPacket(); 

  counter++;

  delay(5000);
}
#include <SPI.h>
#include <LoRa.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ArduinoJson.h> //REQUIRES ARDUINO JSON V6
#include<String.h>

#define ONE_WIRE_BUS 7
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
const int sensorpin = A0;
int counter = 0;
String data = "Jex";
int temp, volt;

void setup() {
  Serial.begin(9600);
  while (!Serial);

  Serial.println("LoRa Sender");

  LoRa.setPins(10, 9, 2); // 10, 9 for UNO, 53, 9 for Mega, 15, 16, for ESP8266

  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
}

void loop() {
   float sensorValue = analogRead(sensorpin);
  float volt = sensorValue * (3.3 / 1025.0) * 3;  // Convertion
  DS18B20.requestTemperatures();
  temp = DS18B20.getTempCByIndex(0);  // Celcius
  
  Serial.print("Sending packet: ");
  Serial.println(counter);
  Serial.print("Temperature: ");
  Serial.println(temp);
  Serial.print("Turbidity: ");
  Serial.println(volt);

  // send packet
  LoRa.beginPacket();
  LoRa.println(data);
  LoRa.println(temp);
  LoRa.println(volt);
  LoRa.print(counter);
  LoRa.endPacket(); 

  counter++;

  delay(5000);
}

Serial Monitor

Sending packet: 15
Temperature: 27
Turbidity: 9.37
Sending packet: 16
Temperature: 27
Turbidity: 9.37

Nodemcu Code

#define BLYNK_TEMPLATE_ID "TMPLu_JPWrOy"
#define BLYNK_TEMPLATE_NAME "WATER QUALITY MONITORING SYSTEM USING LORA"
#define BLYNK_AUTH_TOKEN "XUkl9QTecRSQCYd7y2KDUTqyv9zNcn9C"
#define BLYNK_PRINT Serial

#include <LoRa.h>
#include<ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char ssid[]="Pro";
char pass[]="123456789";

 

BlynkTimer timer;

void setup() {
  Serial.begin(9600);
 
  while (!Serial);

  Serial.println("LoRa Receiver");

  LoRa.setPins(15, 16, 2); // 10, 9 for UNO, 53, 9 for Mega, 15, 16, for ESP8266
  
  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
  Blynk.begin(BLYNK_AUTH_TOKEN , ssid, pass); 
  timer.setInterval(1000L, sendSensor);
}

void loop() {
  Blynk.run();
  timer.run();
}
void sendSensor(){
   // try to parse packet
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    // received a packet
    Serial.print("Received packet '");

    // read packet
     while (LoRa.available()){
      String data = LoRa.readString();
      Serial.println(data);
      float temp = LoRa.read();
      Serial.println(temp);      
      float volt = LoRa.read();
      Serial.println(volt);      
      Blynk.virtualWrite(V1,data);
    }
    // print RSSI of packet
    Serial.print("' with RSSI ");
    Serial.println(LoRa.packetRssi());

  }

}

Serial Monitor

Received packet 'Jex
27
9.42
63
-1.00
-1.00
' with RSSI -50

this my updated code, my problem is when i gonna put it to blynk app all of the sensored data show in one data stream

That’s because you’re writing all of tge incoming data to one datastream…

and previously you were doing this…

Pete.

even i do this the output still the same, or im using lora and it transmit all of the data in one string

So how did you previously achieve this output from your NodeMCU?…

and what have you changed since?

Pete.