(RESOLVIDO) Comunicação de mâo dupla via LoRa - Esp32LoRa da Heltec

Bom dia

Eu estou começando a mexer com o Esp32Lora da Heltec agora, pois vi que ele possui um tipo de rede de alto alcance 


Consegui fazer uma comunicação via LoRa de 2 Esp32LoRa da Heltec em uma área industrial que não foi muito longe pois existe muitos obstáculos para a rede mas também fiz e em uma area residencial consegui da a volta no meu quarteirão tranquilo sem perda de dados o ponto mais longe foi de 200 metros de um Esp32LoRa da Heltec do outro

Mas isto eu fiz configurando um como Receptor e outro como Transmissor, mas eu queria utiliza-los como os 2 sendo Receptor e Transmissor para fazer uma comunicação de mão dupla os 2 mandam informações e os 2 recebe informações

Tentei simplesmente misturar os 2 programas o do Receptor com Transmissor mas parece que não estou conseguindo configura-lo...
Fiquei ate na duvida se e possível mesmo fazer com mão dupla ?

Alguém teria alguma ideia de como fazer ?

PROGRAMA DO RECEPTOR

/*
This is a simple example show the Heltec.LoRa recived data in OLED.

The onboard OLED display is SSD1306 driver and I2C interface. In order to make the
OLED correctly operation, you should output a high-low-high(1-0-1) signal by soft-
ware to OLED's reset pin, the low-level signal at least 5ms.

OLED pins to ESP32 GPIOs via this connecthin:
OLED_SDA -- GPIO4
OLED_SCL -- GPIO15
OLED_RST -- GPIO16

by Aaron.Lee from HelTec AutoMation, ChengDu, China
成都惠利特自动化科技有限公司
www.heltec.cn

This project is also available on GitHub:
https://github.com/Heltec-Aaron-Lee/WiFi_Kit_series
*/
#include "heltec.h"

#define BAND 915E6 //you can set band here directly,e.g. 868E6,915E6,433E6
String rssi = "RSSI --";
String packSize = "--";
String packet ;

void LoRaData() {
Heltec.display->clear();
Heltec.display->setTextAlignment(TEXT_ALIGN_LEFT);
Heltec.display->setFont(ArialMT_Plain_10);
Heltec.display->drawString(0 , 15 , "Recebido " + packSize + " bytes");
Heltec.display->drawStringMaxWidth(0 , 26 , 128, packet);
Heltec.display->drawString(0, 0, rssi);
Heltec.display->display();
}

void cbk(int packetSize) {
packet = "";
packSize = String(packetSize, DEC);
for (int i = 0; i < packetSize; i++) {
packet += (char) LoRa.read();
}
rssi = "RSSI " + String(LoRa.packetRssi(), DEC) ;
LoRaData();

}

void setup() {

Serial.begin(115200);
//WIFI Kit series V1 not support Vext control
Heltec.begin(true /*DisplayEnable Enable*/, true /*Heltec.Heltec.Heltec.LoRa Disable*/, true /*Serial Enable*/, true /*PABOOST Enable*/, BAND /*long BAND*/);

Heltec.display->init();
Heltec.display->flipScreenVertically();
Heltec.display->setFont(ArialMT_Plain_10);
delay(1500);
Heltec.display->clear();

Heltec.display->drawString(0, 0, "CNCTEX.Lora Iniciado!");
Heltec.display->drawString(0, 10, "Espere o dado recebido ...");
Heltec.display->display();
delay(1000);
//LoRa.onReceive(cbk);
LoRa.receive();
}

void loop() {
int packetSize = LoRa.parsePacket();
if (packetSize) {
cbk(packetSize);
}
}

PROGRAMA DO TRANSMISSOR

/*
This is a simple example show the Heltec.LoRa sended data in OLED.

The onboard OLED display is SSD1306 driver and I2C interface. In order to make the
OLED correctly operation, you should output a high-low-high(1-0-1) signal by soft-
ware to OLED's reset pin, the low-level signal at least 5ms.

OLED pins to ESP32 GPIOs via this connecthin:
OLED_SDA -- GPIO4
OLED_SCL -- GPIO15
OLED_RST -- GPIO16

by Aaron.Lee from HelTec AutoMation, ChengDu, China
成都惠利特自动化科技有限公司
https://heltec.org

this project also realess in GitHub:
https://github.com/Heltec-Aaron-Lee/WiFi_Kit_series
*/

#include "heltec.h"

#define BAND 915E6 //you can set band here directly,e.g. 868E6,915E6,433E6

unsigned int counter = 0;
String rssi = "RSSI --";
String packSize = "--";
String packet ;

void setup()
{
//WIFI Kit series V1 not support Vext control
Heltec.begin(true /*DisplayEnable Enable*/, true /*Heltec.Heltec.Heltec.LoRa Disable*/, true /*Serial Enable*/, true /*PABOOST Enable*/, BAND /*long BAND*/);

Heltec.display->init();
Heltec.display->flipScreenVertically();
Heltec.display->setFont(ArialMT_Plain_10);
delay(1500);
Heltec.display->clear();

Heltec.display->drawString(0, 0, "CNCTEX.Lora Iniciado!");
Heltec.display->display();
delay(1000);
}
void loop()
{
Heltec.display->clear();
Heltec.display->setTextAlignment(TEXT_ALIGN_LEFT);
Heltec.display->setFont(ArialMT_Plain_10);

Heltec.display->drawString(0, 0, "Sending packet: ");
Heltec.display->drawString(90, 0, String(counter));
Heltec.display->display();

// send packet
LoRa.beginPacket();
/*
LoRa.setTxPower(txPower,RFOUT_pin);
txPower -- 0 ~ 20
RFOUT_pin could be RF_PACONFIG_PASELECT_PABOOST or RF_PACONFIG_PASELECT_RFO
- RF_PACONFIG_PASELECT_PABOOST -- LoRa single output via PABOOST, maximum output 20dBm
- RF_PACONFIG_PASELECT_RFO -- LoRa single output via RFO_HF / RFO_LF, maximum output 14dBm
*/
LoRa.setTxPower(14, RF_PACONFIG_PASELECT_PABOOST);
LoRa.print("Hello ");
LoRa.print(counter);
LoRa.endPacket();

counter++;
digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)
delay(10); // wait for a second
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
delay(10); // wait for a second
}

// =========================================================== //


RESOLVIDO

Eu mudei o código para facilitar, ao invés de mandar informações escrita no display fiz ele apenas com 2 botoes e 2 leds um acedendo um lede do outro 

Um liga o led do outro com um interruptor que eu fiz pelo software usando um micro swith


lembrando os botoes tem que esta cons resistores pro pull down

PROGRAMA DO TRANSMISSOR RECEPTOR (so passar esse programa no 2 microcontrolador)

/*
This is a simple example show the Heltec.LoRa sended data in OLED.

The onboard OLED display is SSD1306 driver and I2C interface. In order to make the
OLED correctly operation, you should output a high-low-high(1-0-1) signal by soft-
ware to OLED's reset pin, the low-level signal at least 5ms.

OLED pins to ESP32 GPIOs via this connecthin:
OLED_SDA -- GPIO4
OLED_SCL -- GPIO15
OLED_RST -- GPIO16

by Aaron.Lee from HelTec AutoMation, ChengDu, China
成都惠利特自动化科技有限公司
https://heltec.org

this project also realess in GitHub:
https://github.com/Heltec-Aaron-Lee/WiFi_Kit_series
*/

#include "heltec.h"

#define BAND 915E6 //you can set band here directly,e.g. 868E6,915E6,433E6

#define botao 36
#define led 12

boolean status_Botao = LOW;
boolean statusAnt_Botao = LOW;
boolean sinal = 0;
String packSize = "--";
String packet ;

void cbk(int packetSize) { // recebe e converte dos dados recebidos em texto para facilitar o manuzeio
packet = "";
packSize = String(packetSize, DEC);
for (int i = 0; i < packetSize; i++) {
packet += (char) LoRa.read();
}
}

void setup() {

pinMode (botao, INPUT);
pinMode (led , OUTPUT);

//WIFI Kit series V1 not support Vext control
Heltec.begin(true /*DisplayEnable Enable*/, true /*Heltec.Heltec.Heltec.LoRa Disable*/, true /*Serial Enable*/, true /*PABOOST Enable*/, BAND /*long BAND*/);
LoRa.receive();
}
void loop() {

status_Botao = digitalRead (botao);
delay(5);

if (status_Botao == HIGH) statusAnt_Botao = HIGH;
if (status_Botao == LOW && statusAnt_Botao == HIGH) {
sinal = !sinal;
statusAnt_Botao = LOW;
LoRa.beginPacket(); // liga o envio
LoRa.setTxPower(14, RF_PACONFIG_PASELECT_PABOOST);
LoRa.print(sinal);
LoRa.endPacket(); // deliga o envio
}

// LoRa.onReceive(cbk);


int packetSize = LoRa.parsePacket();
if (packetSize) {
cbk(packetSize);
}


if (packet == "1") {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
//delay(10); // wait for a second
}

if (packet == "0") {
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
//delay(10);
}
}

Exibições: 1543

Anexos

Responder esta

Respostas a este tópico

Bom dia. Está um poco complicado de entender o código postado aqui. O que vc deve fazer em primeiro lugar é isolar as configurações do lora em funções.

Quando o código começar as duas devem estar em configuração de receptor. Quando alguma quiser enviar alguma informação vc chama a função de configurar para transmissor,  envio o dado e chama a função de receptor para ela voltar a ouvir. Deve funcionar.

ok vou tentar

Conseguiiiii !!! 

Exatamente isso mesmo muito OBG!

conseguiu enviar e receber com o mesmo módulo? Se sim, por favor coloque os códigos aqui para que possa ajudar outras pessoas e coloque RESOLVIDO no tópico. Parabéns.

poderia nos fornecer o codigo?

mandei 

nao esquece de postar os resultados aqui. Para começar, tenta isolar as funções de configuração do lora nesse mesmo codigo que vc esta usando, um para transmissor e um para receptor

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço