Use ESP32 to display serial output from Arduino MKR 1310 Lora to Blynk

Hi,

While I wait for a proper Lorawan Gateway arrive I’m attempting to display a temperature reading on a Blynk Web dashboard sent from one Arduino MKR 1310 to another that is then connected to an ESP32 WROOM board via the serial port.

There’s a similar project here but that uses MKR 1300s and an ESP8266.

I’ve used the below sketch to connect the ESP32 to Blynk successfully but I think I missing the correct code to take the temperature input coming from the serial output (working, tested) of the MKR 1310 receiver board.

// This code for ESP32 device

#include <WiFi.h>

#include <WiFiClient.h>

#include <BlynkSimpleEsp32.h>

#define BLYNK_TEMPLATE_ID "-"

#define BLYNK_TEMPLATE_NAME "-"

#define BLYNK_AUTH_TOKEN "-"

char auth[] = "-";  // Blynk authentication token

char ssid[] = "-";         // WiFi SSID

char pass[] = "-";     // WiFi password

BlynkTimer timer;

void setup() {

  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);

}

void loop() {

  Blynk.run();

  timer.run();

}

BLYNK_WRITE(V0) {

  float temperature = param.asFloat();

  Serial.print("Received Temperature: ");

  Serial.println(temperature);

  Blynk.virtualWrite(V1, temperature);  // Display temperature on the Value Display widget in Blynk app

}

This is the code from the link I’ve tried to update for the 1310 and ESP32:


#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include<String.h>
#include <SoftwareSerial.h>//libraries needed in communicating with gps and nodemcu
int RXPin = D2;//tx pin of mkr1300 connected to this pin
int TXPin = D1;//rx pin of mkr1300 connected to this pin
SoftwareSerial data_serial(RXPin, TXPin);//declaring the rx,tx pins
int incomingByte = 0;

int data1;
int data2;
int data3;
int data4;
int data5;
String LoRaData;
String jsonBuffer;
float ta;// Temperature details 
float ha; // Humidity details
float rs; //Rssi details

char auth[] = "xxxxxxxxxxxxx";// Your blynk app token id
char ssid[] = "xxxxxxxxxxxx"; // your Wifi name
char pass[] = "xxxxxxxxxxxxxxx"; // your wifi password

BlynkTimer timer;

void setup() {
  Serial.begin(9600);
  data_serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
}

void loop() {
String str1="",str2="",str3="",str4="",str5="";
 int i=0,len;
char commandbuffer[400];
  if (data_serial.available())
  {
    delay(500);
while( data_serial.available() && i< 99) 
{
commandbuffer[i++] = data_serial.read();
}
//commandbuffer[i++]='\0';
  }
  Serial.println((char*)commandbuffer);
  str1=str1+((char*)commandbuffer);
  len=str1.length();
  Serial.println(len);
    if(len-15 > 0)
    {
      str1=str1.substring(0,len);      
      str2=str1.substring(0,2);
      str3 =str1.substring(3,5);
      str4 = str1.substring(6,8);
      str5 = str1.substring(9,15);
      data1 = str2.toInt();
      data2 = str3.toInt();
      data3 = str4.toInt();
      data4 = str5.toInt();
    }
     Serial.print("hum:");
     Serial.print(data1);
     Serial.println();

     Serial.print("temp:");
     Serial.print(data2);
     Serial.println();

     Serial.print("Light:");
     Serial.print(data3);
     Serial.println();

     Serial.print("axis:");
     Serial.print(data4);
     Serial.println();
     
      Blynk.virtualWrite(V0,data1);
      Blynk.virtualWrite(V1,data2);
      Blynk.virtualWrite(V2,data3);
      Blynk.virtualWrite(V3,data4);
  
      Blynk.run();
      timer.run();
      
}


Any advice appreciated.

-//-

Nate

I’m totally lost with what you’re trying to achieve here, and your code doesn’t help at all.

The example you linked tow has three sketches:

One for the MKR transmitter
One for the MKR receiver
One for the ESP8266 WiFi bridge

You’ve posted some ESP32 code that receives data from Blynk (the opposite of what you are trying to do) and one sketch which is basically the ESP8266 WiFi bridge sketch from the example that hasn’t been changed to work with an ESP32, despite you saying…

Have you posted the wrong sketch and omitted the two MKR sketches, or am I missing something?

Pete.

Easy man, easy, I’m new here and looking for help.

I want to emulate the sending and receiving of temperature data (at least) like the code from the Github project but using two MKR 1310 boards rather than 1300 boards and one ESP32 board rather than an ESP8266.

I have the MKR1310s sending and receiving temperature data from each other, that outputs a value to the serial monitor in the Arduino IDE. Rather than post that code which seems to be working fine, I thought I’d post the side I was struggling with.

My sense was that the ESP32 code for Blynk I posted should connect to Blynk via Wifi and then output the temperature reading from the receiver MKR 1310 to V1.

Does that make more sense?

Thanks,

Nate

Is that the first piece of code you posted, or the second?

Pete.