Estimados, muy buenas. Es mi 1er post, soy principante en estos temas. Tomando info de todos lados mi idea es en principio hacer un control de bomba de agua para el llenado de un tanque elevado dónde éste tiene una placa HELTEC ESP32 WiFi LoRa dónde tomo el nivel del agua con un sensor ultrasónico HC SR04 y/o un sensor de presión diferencial MPX1050DP y en el otro extremo otra placa igual más un display Nextion Intelligent NX4827P043-011R, en la pantalla por ahora muestro un dibujo del tanque con el nivel % de llenado del mismo a través de una barra de progreso y también como dato de control la distancia (cm) de altura del nivel del agua... no cuento el resto del equipamiento eléctrico del tablero.
Armé el programa que pongo abajo, copiando info de varios temas de Youtube. Tuve un enorme problema que me demandó muchas horas para solucionarlo y es que me presentaba un error al enviar los datos a la pantalla, el error era "recvretcommandfinished err", creo que ya se solucionó, ya que el monitor serie no me lo muestra más.
Para probar que todo funcione realizo el debug con la placa ESP32 conectada a la PC y uso el Editor de Nextion.
Ahora que se solucionó ese problema no me aparecen los datos en la pantalla, ya no sé por dónde ver.
Esto es lo que tengo por ahora, una placa enviando y la otra recibiendo
Con esto es lo que envío los datos a la pantalla Nextion
NivelTQ.setValue(waterLevelPer);
distancia = distance;
const char* distancia;
NumTQ.setText(distancia);
Agradezco enormemente vuestra ayuda.
Saludos.
#include <SPI.h>
#include <LoRa.h>
#include "Nextion.h"
//Libraries for OLED Display
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
//define the pins used by the LoRa transceiver module
#define SCK 5
#define MISO 19
#define MOSI 27
#define SS 18
#define RST 14
#define DIO0 26
#define led 12
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define BAND 915E6
//OLED pins
#define OLED_SDA 4
#define OLED_SCL 15
#define OLED_RST 16
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
NexProgressBar NivelTQ = NexProgressBar(0, 1, "j0");
NexText NumTQ = NexText(0, 2, "t0");
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RST);
byte msgCount = 0; // count of outgoing messages
String outgoing; // outgoing message
String LoRaData;
byte localAddress = 0xFF; // address of this device
byte destination = 0xBB; // destination to send to
long lastSendTime = 0; // last send time
int interval = 50; // interval between sends
String statusmessage = "";
String distancia;
void setup() {
//initialize Serial Monitor
Serial.begin(115200);
nexInit();
//reset OLED display via software
pinMode(OLED_RST, OUTPUT);
pinMode(led,OUTPUT);
digitalWrite(OLED_RST, LOW);
delay(20);
digitalWrite(OLED_RST, HIGH);
//initialize OLED
Wire.begin(OLED_SDA, OLED_SCL);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) { // Address 0x3C for 128x32
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(0,0);
display.print("LORA RECEIVER ");
display.display();
Serial.println("LoRa Receiver Test");
//SPI LoRa pins
SPI.begin(SCK, MISO, MOSI, SS);
//setup LoRa transceiver module
LoRa.setPins(SS, RST, DIO0);
if (!LoRa.begin(BAND)) {
Serial.println("Starting LoRa failed!");
while (1);
}
Serial.println("LoRa Initializing OK!");
display.setCursor(0,10);
display.println("LoRa Initializing OK!");
display.display();
}
void loop() {
// parse for a packet, and call onReceive with the result:
onReceive(LoRa.parsePacket());
}
void onReceive(int packetSize) {
if (packetSize == 0) return; // if there's no packet, return
// read packet header bytes:
int recipient = LoRa.read(); // recipient address
byte sender = LoRa.read(); // sender address
byte incomingMsgId = LoRa.read(); // incoming msg ID
byte incomingLength = LoRa.read(); // incoming msg length
String incoming = "";
while (LoRa.available()) {
LoRaData = LoRa.readString();
//Serial.print(LoRaData);
}
String q = getValue(LoRaData, ',', 0);
String r = getValue(LoRaData, ',', 1);
int distance = q.toInt();
int waterLevelPer = r.toInt();
Serial.print("distance = ");
Serial.println(distance);
Serial.print("waterLevelPer = ");
Serial.println(waterLevelPer);
// ************************************************************************************************
NivelTQ.setValue(waterLevelPer);
distancia = distance;
const char* distancia;
NumTQ.setText(distancia);
delay(5000);
String rssi = "RSSI " + String(LoRa.packetRssi(), DEC) ;
//Serial.println(rssi);
delay(10);
// Dsiplay information
display.clearDisplay();
display.setCursor(5,0);
display.setTextSize(2);
display.print("W-L-Meter");
display.setCursor(0,25);
display.setTextSize(2);
// display.print("Dist:");
// display.setCursor(70,15);
// display.setTextSize(2);
// display.print(distance);
display.print("Dist:"+String(distance)+"cm");
display.setCursor(0,50);
display.setTextSize(2);
//display.print("W-L:");
display.print("W-L:"+String(waterLevelPer)+"%");
// display.setCursor(92,40);
// display.setTextSize(2);
// display.print(waterLevelPer);
display.display();
}
String getValue(String data, char separator, int index)
{
int found = 0;
int strIndex[] = { 0, -1 };
int maxIndex = data.length() - 1;
for (int i = 0; i <= maxIndex && found <= index; i++) {
if (data.charAt(i) == separator || i == maxIndex) {
found++;
strIndex[0] = strIndex[1] + 1;
strIndex[1] = (i == maxIndex) ? i+1 : i;
}
}
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}
Texto en cursiva
En el editor de Nextion, en la parte de datos del MCU me muestra esto, entiendo que entonces le entran los datos, pero no los muestra.
64 69 73 74 61 6E 63 65 20 3D 20 30 0D 0A 77 61 74 65 72 4C 65 76 65 6C 50 65 72 20 3D 20 31 30 30 0D 0A
distance = 0\x0D\x0AwaterLevelPer = 100\x0D\x0A