Ora capiremo i vari tipi di trasmissione del nostro dispositivo Ebyte E220 UART LoRa basato sui moduli wireless LLCC68.
Qui una selezione di dispositivi LoRa AliExpress (433MHz 5.5Km) - AliExpress (433MHz 10Km) - AliExpress (868MHz 915Mhz 5.5Km) - AliExpress (868MHz 915Mhz 10Km)
Nella prima parte abbiamo utilizzato una trasmissione trasparente, e inviavamo da tutti e ricevamo da tutti i dispositivi che hanno lo stesso indirizzo e canale.
Ma non è uno scenario standard e di solito vogliamo inviare a un punto specifico e ricevere una risposta.
Se hai problemi di blocco del dispositivo, devi inserire una resistenza di pull-up da 4,7k o meglio collegare il pin AUX del dispositivo.
Modalità normale
Per la trasmissione normale, devi impostare M0 e M1 su LOW, ed è meglio se colleghi il pin AUX per avere una sincronizzazione migliore, ma non necessaria. È possibile verificare la connessione del pin AUX nell’esempio di connessione completo della libreria e è necessario aggiungere solo i PIN al costruttore.
M0 | GND (Set normal mode) |
M1 | GND (Set normal mode) |
TX | PIN 2 (PullUP 4,7KΩ) |
RX | PIN 3 (PullUP 4,7KΩ & Voltage divider) |
AUX | Not connected (PullUP 4,7KΩ) |
VCC | 5v |
GND | GND |
e questa configurazione per Wemos D1 mini:
M0 | GND (Set normal mode) |
M1 | GND (Set normal mode) |
TX | PIN D2 (PullUP 4,7KΩ) |
RX | PIN D3 (PullUP 4,7KΩ) |
AUX | Not connected (PullUP 4,7KΩ) |
VCC | 3.3v/5v |
GND | GND |
ESP-32:
M0 | GND (Set normal mode) |
M1 | GND (Set normal mode) |
RX | TX2 (PullUP 4,7KΩ) |
TX | RX2 (PullUP 4,7KΩ) |
AUX | Not connected (PullUP 4,7KΩ) |
VCC | 3.3v/5v |
GND | GND |
Arduino MKR WiFi 1010:
M0 | GND (Set normal mode) |
M1 | GND (Set normal mode) |
TX | PIN 14 Tx (PullUP 4,7KΩ) |
RX | PIN 13 Rx (PullUP 4,7KΩ) |
AUX | Not connected (PullUP 4,7KΩ) |
VCC | 3.3v/5v |
GND | GND |
Quindi devi solo istanziare il costruttore corretto.
// ---------- esp8266 pins --------------
//LoRa_E220 e220ttl(RX, TX, AUX, M0, M1); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
//LoRa_E220 e220ttl(D3, D4, D5, D7, D6); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX AUX M0 M1
//LoRa_E220 e220ttl(D2, D3); // Config without connect AUX and M0 M1
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(D2, D3); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
//LoRa_E220 e220ttl(&mySerial, D5, D7, D6); // AUX M0 M1
// -------------------------------------
// ---------- Arduino pins --------------
LoRa_E220 e220ttl(4, 5, 3, 7, 6); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX AUX M0 M1
//LoRa_E220 e220ttl(4, 5); // Config without connect AUX and M0 M1
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(4, 5); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
//LoRa_E220 e220ttl(&mySerial, 3, 7, 6); // AUX M0 M1
// -------------------------------------
// ------------- Arduino MKR WiFi 1010 -------------
// LoRa_E220 e220ttl(&Serial1, 2, 4, 6); // RX AUX M0 M1
// -------------------------------------------------
// ------------- Arduino MKR WiFi 1010 -------------
// LoRa_E220 e220ttl(&Serial1, 0, 2, 4); // RX AUX M0 M1
// -------------------------------------------------
// ---------- esp32 pins --------------
// LoRa_E220 e220ttl(&Serial2, 15, 21, 19); // RX AUX M0 M1
//LoRa_E220 e220ttl(&Serial2, 22, 4, 18, 21, 19, UART_BPS_RATE_9600); // esp32 RX <-- e220 TX, esp32 TX --> e220 RX AUX M0 M1
// -------------------------------------
Trasmissione trasparente
Schizzo generico, seleziona il costruttore corretto per ogni dispositivo:
/*
* EBYTE LoRa E220
* send a transparent message, you must check that the transmitter and receiver have the same
* CHANNEL ADDL and ADDH
*
* You must uncommend the correct constructor.
*
* by Renzo Mischianti <https://mischianti.org>
*
* https://mischianti.org
*
* E220 ----- WeMos D1 mini ----- esp32 ----- Arduino Nano 33 IoT ----- Arduino MKR ----- ArduinoUNO
* M0 ----- D7 (or GND) ----- 19 (or GND) ----- 2 (or GND) ----- 2 (or GND) ----- 7 Volt div (or GND)
* M1 ----- D6 (or GND) ----- 21 (or GND) ----- 4 (or GND) ----- 4 (or GND) ----- 6 Volt div (or GND)
* TX ----- D3 (PullUP) ----- TX2 (PullUP) ----- TX1 (PullUP) ----- 14 (PullUP) ----- 4 (PullUP)
* RX ----- D4 (PullUP) ----- RX2 (PullUP) ----- RX1 (PullUP) ----- 13 (PullUP) ----- 5 Volt div (PullUP)
* AUX ----- D5 (PullUP) ----- 18 (PullUP) ----- 0 (PullUP) ----- 0 (PullUP) ----- 3 (PullUP)
* VCC ----- 3.3v/5v ----- 3.3v/5v ----- 3.3v/5v ----- 3.3v/5v ----- 3.3v/5v
* GND ----- GND ----- GND ----- GND ----- GND ----- GND
*
*/
#define ENABLE_RSSI true
#include "Arduino.h"
#include "LoRa_E220.h"
// ---------- esp8266 pins --------------
//LoRa_E220 e220ttl(RX, TX, AUX, M0, M1); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
//LoRa_E220 e220ttl(D3, D4, D5, D7, D6); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX AUX M0 M1
//LoRa_E220 e220ttl(D2, D3); // Config without connect AUX and M0 M1
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(D2, D3); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
//LoRa_E220 e220ttl(&mySerial, D5, D7, D6); // AUX M0 M1
// -------------------------------------
// ---------- Arduino pins --------------
LoRa_E220 e220ttl(4, 5, 3, 7, 6); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX AUX M0 M1
//LoRa_E220 e220ttl(4, 5); // Config without connect AUX and M0 M1
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(4, 5); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
//LoRa_E220 e220ttl(&mySerial, 3, 7, 6); // AUX M0 M1
// -------------------------------------
// ------------- Arduino MKR WiFi 1010 -------------
// LoRa_E220 e220ttl(&Serial1, 2, 4, 6); // RX AUX M0 M1
// -------------------------------------------------
// ------------- Arduino MKR WiFi 1010 -------------
// LoRa_E220 e220ttl(&Serial1, 0, 2, 4); // RX AUX M0 M1
// -------------------------------------------------
// ---------- esp32 pins --------------
// LoRa_E220 e220ttl(&Serial2, 15, 21, 19); // RX AUX M0 M1
//LoRa_E220 e220ttl(&Serial2, 22, 4, 18, 21, 19, UART_BPS_RATE_9600); // esp32 RX <-- e220 TX, esp32 TX --> e220 RX AUX M0 M1
// -------------------------------------
void setup() {
Serial.begin(9600);
delay(500);
// Startup all pins and UART
e220ttl.begin();
// If you have ever change configuration you must restore It
Serial.println("Hi, I'm going to send message!");
// Send message
ResponseStatus rs = e220ttl.sendMessage("Hello, world?");
// Check If there is some problem of succesfully send
Serial.println(rs.getResponseDescription());
}
void loop() {
// If something available
if (e220ttl.available()>1) {
// read the String message
ResponseContainer rc = e220ttl.receiveMessage();
// Is something goes wrong print error
if (rc.status.code!=1){
Serial.println(rc.status.getResponseDescription());
}else{
// Print the data received
Serial.println(rc.status.getResponseDescription());
Serial.println(rc.data);
}
}
if (Serial.available()) {
String input = Serial.readString();
e220ttl.sendMessage(input);
}
}
Se hai già modificato la configurazione, devi ripristinare i parametri di default:
// If you have ever change configuration you must restore It
ResponseStructContainer c;
c = e220ttl.getConfiguration();
Configuration configuration = *(Configuration*) c.data;
Serial.println(c.status.getResponseDescription());
configuration.ADDL = 0x03; // First part of address
configuration.ADDH = 0x00; // Second part
configuration.CHAN = 23; // Communication channel
configuration.SPED.uartBaudRate = UART_BPS_9600; // Serial baud rate
configuration.SPED.airDataRate = AIR_DATA_RATE_010_24; // Air baud rate
configuration.SPED.uartParity = MODE_00_8N1; // Parity bit
configuration.OPTION.subPacketSetting = SPS_200_00; // Packet size
configuration.OPTION.RSSIAmbientNoise = RSSI_AMBIENT_NOISE_DISABLED; // Need to send special command
configuration.OPTION.transmissionPower = POWER_22; // Device power
configuration.TRANSMISSION_MODE.enableRSSI = RSSI_DISABLED; // Enable RSSI info
configuration.TRANSMISSION_MODE.fixedTransmission = FT_TRANSPARENT_TRANSMISSION; // Enable repeater mode
configuration.TRANSMISSION_MODE.enableLBT = LBT_DISABLED; // Check interference
configuration.TRANSMISSION_MODE.WORPeriod = WOR_2000_011; // WOR timing
e220ttl.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
c.close();
Trasmissione trasparente e RSSI
Un indicatore di potenza del segnale ricevuto (RSSI) nelle telecomunicazioni misura la potenza presente in un segnale radio ricevuto.
L’RSSI è solitamente invisibile all’utente di un dispositivo ricevente. Tuttavia, poiché la potenza del segnale può variare notevolmente e influire sulla funzionalità nelle reti wireless, i dispositivi IEEE 802.11 spesso mettono a disposizione degli utenti la misurazione.
Questo dispositivo supporta RSSI e, in alcune situazioni, è molto utile. Per utilizzarlo è necessario attivare il flag di configurazione.
// If you have ever change configuration you must restore It
ResponseStructContainer c;
c = e220ttl.getConfiguration();
Configuration configuration = *(Configuration*) c.data;
Serial.println(c.status.getResponseDescription());
configuration.ADDL = 0x03;
configuration.ADDH = 0x00;
configuration.CHAN = 23;
configuration.SPED.uartBaudRate = UART_BPS_9600;
configuration.SPED.airDataRate = AIR_DATA_RATE_010_24;
configuration.SPED.uartParity = MODE_00_8N1;
configuration.OPTION.subPacketSetting = SPS_200_00;
configuration.OPTION.RSSIAmbientNoise = RSSI_AMBIENT_NOISE_DISABLED;
configuration.OPTION.transmissionPower = POWER_22;
configuration.TRANSMISSION_MODE.enableRSSI = RSSI_ENABLED;
configuration.TRANSMISSION_MODE.fixedTransmission = FT_TRANSPARENT_TRANSMISSION;
configuration.TRANSMISSION_MODE.enableLBT = LBT_DISABLED;
configuration.TRANSMISSION_MODE.WORPeriod = WOR_2000_011;
e220ttl.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
c.close();
Dopo la configurazione, possiamo passare ad utilizzare il metodo creato per gestire il valore RSSI: receiveMessageRSSI()
.
Per il trasmettitore tutto il processo è stato gestito dalla configurazione; solo il destinatario deve utilizzare un metodo “speciale” per recuperare il valore. Quindi lo Sketch precedente diventa così:
/*
* EBYTE LoRa E220
* send a transparent message, you must check that the transmitter and receiver have the same
* CHANNEL ADDL and ADDH
*
* You must uncommend the correct constructor.
*
* by Renzo Mischianti <https://mischianti.org>
*
* https://mischianti.org
*
* E220 ----- WeMos D1 mini ----- esp32 ----- Arduino Nano 33 IoT ----- Arduino MKR ----- ArduinoUNO
* M0 ----- D7 (or GND) ----- 19 (or GND) ----- 2 (or GND) ----- 2 (or GND) ----- 7 Volt div (or GND)
* M1 ----- D6 (or GND) ----- 21 (or GND) ----- 4 (or GND) ----- 4 (or GND) ----- 6 Volt div (or GND)
* TX ----- D3 (PullUP) ----- TX2 (PullUP) ----- TX1 (PullUP) ----- 14 (PullUP) ----- 4 (PullUP)
* RX ----- D4 (PullUP) ----- RX2 (PullUP) ----- RX1 (PullUP) ----- 13 (PullUP) ----- 5 Volt div (PullUP)
* AUX ----- D5 (PullUP) ----- 18 (PullUP) ----- 0 (PullUP) ----- 0 (PullUP) ----- 3 (PullUP)
* VCC ----- 3.3v/5v ----- 3.3v/5v ----- 3.3v/5v ----- 3.3v/5v ----- 3.3v/5v
* GND ----- GND ----- GND ----- GND ----- GND ----- GND
*
*/
#define ENABLE_RSSI true
#include "Arduino.h"
#include "LoRa_E220.h"
// ---------- esp8266 pins --------------
//LoRa_E220 e220ttl(RX, TX, AUX, M0, M1); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
//LoRa_E220 e220ttl(D3, D4, D5, D7, D6); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX AUX M0 M1
//LoRa_E220 e220ttl(D2, D3); // Config without connect AUX and M0 M1
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(D2, D3); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
//LoRa_E220 e220ttl(&mySerial, D5, D7, D6); // AUX M0 M1
// -------------------------------------
// ---------- Arduino pins --------------
LoRa_E220 e220ttl(4, 5, 3, 7, 6); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX AUX M0 M1
//LoRa_E220 e220ttl(4, 5); // Config without connect AUX and M0 M1
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(4, 5); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
//LoRa_E220 e220ttl(&mySerial, 3, 7, 6); // AUX M0 M1
// -------------------------------------
// ------------- Arduino MKR WiFi 1010 -------------
// LoRa_E220 e220ttl(&Serial1, 2, 4, 6); // RX AUX M0 M1
// -------------------------------------------------
// ------------- Arduino MKR WiFi 1010 -------------
// LoRa_E220 e220ttl(&Serial1, 0, 2, 4); // RX AUX M0 M1
// -------------------------------------------------
// ---------- esp32 pins --------------
// LoRa_E220 e220ttl(&Serial2, 15, 21, 19); // RX AUX M0 M1
//LoRa_E220 e220ttl(&Serial2, 22, 4, 18, 21, 19, UART_BPS_RATE_9600); // esp32 RX <-- e220 TX, esp32 TX --> e220 RX AUX M0 M1
// -------------------------------------
void setup() {
Serial.begin(9600);
delay(500);
// Startup all pins and UART
e220ttl.begin();
// If you have ever change configuration you must restore It
Serial.println("Hi, I'm going to send message!");
// Send message
ResponseStatus rs = e220ttl.sendMessage("Hello, world?");
// Check If there is some problem of succesfully send
Serial.println(rs.getResponseDescription());
}
void loop() {
// If something available
if (e220ttl.available()>1) {
// read the String message
ResponseContainer rc = e220ttl.receiveMessageRSSI();
// Is something goes wrong print error
if (rc.status.code!=1){
Serial.println(rc.status.getResponseDescription());
}else{
// Print the data received
Serial.println(rc.status.getResponseDescription());
Serial.println(rc.data);
Serial.print("RSSI: "); Serial.println(rc.rssi, DEC);
}
}
if (Serial.available()) {
String input = Serial.readString();
e220ttl.sendMessage(input);
}
}
Trasmissione fissa
Per la trasmissione fissa, è necessario impostare M0 e M1 su LOW, ed è meglio collegare il pin AUX per avere una migliore sincronizzazione.
Trasmissione fissa: punto a punto
Per utilizzare questo tipo di trasmissione, dobbiamo impostare un parametro sulla configurazione e impostare un indirizzo specifico per ogni dispositivo.
Quindi, per prima cosa, dobbiamo impostare M0 e M1 su HIGH per entrare in modalità programma/sleep e impostare l’indirizzo corretto e il flag di trasmissione fisso.
Se vogliamo replicare la condizione del mittente nell’immagine in alto, dobbiamo eseguire questa configurazione.
ResponseStructContainer c;
c = e220ttl.getConfiguration();
Configuration configuration = *(Configuration*) c.data;
configuration.ADDL = 0x02;
configuration.ADDH = 0x00;
configuration.CHAN = 23;
configuration.SPED.uartBaudRate = UART_BPS_9600;
configuration.SPED.airDataRate = AIR_DATA_RATE_010_24;
configuration.SPED.uartParity = MODE_00_8N1;
configuration.OPTION.subPacketSetting = SPS_200_00;
configuration.OPTION.RSSIAmbientNoise = RSSI_AMBIENT_NOISE_ENABLED;
configuration.OPTION.transmissionPower = POWER_22;
configuration.TRANSMISSION_MODE.enableRSSI = RSSI_DISABLED;
configuration.TRANSMISSION_MODE.fixedTransmission = FT_FIXED_TRANSMISSION;
configuration.TRANSMISSION_MODE.enableLBT = LBT_DISABLED;
configuration.TRANSMISSION_MODE.WORPeriod = WOR_2000_011;
e220ttl.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
c.close();
Quindi per il dispositivo ricevitore, dobbiamo impostare questa configurazione.
ResponseStructContainer c;
c = e220ttl.getConfiguration();
Configuration configuration = *(Configuration*) c.data;
configuration.ADDL = 0x03;
configuration.ADDH = 0x00;
configuration.CHAN = 23;
configuration.SPED.uartBaudRate = UART_BPS_9600;
configuration.SPED.airDataRate = AIR_DATA_RATE_010_24;
configuration.SPED.uartParity = MODE_00_8N1;
configuration.OPTION.subPacketSetting = SPS_200_00;
configuration.OPTION.RSSIAmbientNoise = RSSI_AMBIENT_NOISE_DISABLED;
configuration.OPTION.transmissionPower = POWER_22;
configuration.TRANSMISSION_MODE.enableRSSI = RSSI_DISABLED;
configuration.TRANSMISSION_MODE.fixedTransmission = FT_FIXED_TRANSMISSION;
configuration.TRANSMISSION_MODE.enableLBT = LBT_DISABLED;
configuration.TRANSMISSION_MODE.WORPeriod = WOR_2000_011;
e220ttl.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
c.close();
Ora possiamo inviare un messaggio al dispositivo specificato.
#define DESTINATION_ADDL 2
// Send message
ResponseStatus rs = e220ttl.sendFixedMessage(0, DESTINATION_ADDL, 23, "Hello, world?");
// Check If there is some problem of succesfully send
Serial.println(rs.getResponseDescription());
Il codice del ricevitore è come quello trasparente perché il dispositivo gestisce l’indirizzo e il canale.
void loop()
{
// If something available
if (e220ttl.available()>1) {
// read the String message
ResponseContainer rc = e220ttl.receiveMessage();
// Is something goes wrong print error
if (rc.status.code!=1){
Serial.println(rc.status.getResponseDescription());
}else{
// Print the data received
Serial.println(rc.status.getResponseDescription());
Serial.println(rc.data);
}
}
}
Presta attenzione a queste righe di codice:
// With FIXED SENDER configuration
// #define DESTINATION_ADDL 3
// With FIXED RECEIVER configuration
#define DESTINATION_ADDL 2
È necessario rimuovere il commento dalla corretta DESTINATION_ADDL per il mittente e il destinatario.
Nello sketch mittente e ricevente, decommenta il costruttore giusto relativo al tuo dispositivo:
/*
* EBYTE LoRa E220
* Send a string message to a fixed point ADDH ADDL CHAN
*
* You must configure 2 device: one as SENDER (with FIXED SENDER config) and uncomment the relative
* define with the correct DESTINATION_ADDL, and one as RECEIVER (with FIXED RECEIVER config)
* and uncomment the relative define with the correct DESTINATION_ADDL.
*
* Write a string on serial monitor or reset to resend default value.
*
*
* You must uncommend the correct constructor.
*
* by Renzo Mischianti <https://mischianti.org>
*
* https://mischianti.org
*
* E220 ----- WeMos D1 mini ----- esp32 ----- Arduino Nano 33 IoT ----- Arduino MKR ----- ArduinoUNO
* M0 ----- D7 (or 3.3v) ----- 19 (or 3.3v) ----- 2 (or 3.3v) ----- 2 (or 3.3v) ----- 7 Volt div (or 3.3v)
* M1 ----- D6 (or 3.3v) ----- 21 (or 3.3v) ----- 4 (or 3.3v) ----- 4 (or 3.3v) ----- 6 Volt div (or 3.3v)
* TX ----- D3 (PullUP) ----- TX2 (PullUP) ----- TX1 (PullUP) ----- 14 (PullUP) ----- 4 (PullUP)
* RX ----- D4 (PullUP) ----- RX2 (PullUP) ----- RX1 (PullUP) ----- 13 (PullUP) ----- 5 Volt div (PullUP)
* AUX ----- D5 (PullUP) ----- 18 (PullUP) ----- 0 (PullUP) ----- 0 (PullUP) ----- 3 (PullUP)
* VCC ----- 3.3v/5v ----- 3.3v/5v ----- 3.3v/5v ----- 3.3v/5v ----- 3.3v/5v
* GND ----- GND ----- GND ----- GND ----- GND ----- GND
*
*/
// With FIXED SENDER configuration
#define DESTINATION_ADDL 3
// With FIXED RECEIVER configuration
//#define DESTINATION_ADDL 2
#include "Arduino.h"
#include "LoRa_E220.h"
// ---------- esp8266 pins --------------
//LoRa_E220 e220ttl(RX, TX, AUX, M0, M1); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
//LoRa_E220 e220ttl(D3, D4, D5, D7, D6); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX AUX M0 M1
//LoRa_E220 e220ttl(D2, D3); // Config without connect AUX and M0 M1
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(D2, D3); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
//LoRa_E220 e220ttl(&mySerial, D5, D7, D6); // AUX M0 M1
// -------------------------------------
// ---------- Arduino pins --------------
//LoRa_E220 e220ttl(4, 5, 3, 7, 6); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX AUX M0 M1
//LoRa_E220 e220ttl(4, 5); // Config without connect AUX and M0 M1
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(4, 5); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
//LoRa_E220 e220ttl(&mySerial, 3, 7, 6); // AUX M0 M1
// -------------------------------------
// ------------- Arduino MKR WiFi 1010 -------------
// LoRa_E220 e220ttl(&Serial1, 2, 4, 6); // RX AUX M0 M1
// -------------------------------------------------
// ------------- Arduino MKR WiFi 1010 -------------
// LoRa_E220 e220ttl(&Serial1, 0, 2, 4); // RX AUX M0 M1
// -------------------------------------------------
// ---------- esp32 pins --------------
LoRa_E220 e220ttl(&Serial2, 15, 21, 19); // RX AUX M0 M1
//LoRa_E220 e220ttl(&Serial2, 22, 4, 18, 21, 19, UART_BPS_RATE_9600); // esp32 RX <-- e220 TX, esp32 TX --> e220 RX AUX M0 M1
// -------------------------------------
void printParameters(struct Configuration configuration);
void setup() {
Serial.begin(9600);
delay(500);
// Startup all pins and UART
e220ttl.begin();
ResponseStructContainer c;
c = e220ttl.getConfiguration();
// It's important get configuration pointer before all other operation
Configuration configuration = *(Configuration*) c.data;
Serial.println(c.status.getResponseDescription());
Serial.println(c.status.code);
printParameters(configuration);
c.close();
Serial.println("Hi, I'm going to send message!");
// Send message
ResponseStatus rs = e220ttl.sendFixedMessage(0, DESTINATION_ADDL, 23, "Hello, world?");
// Check If there is some problem of succesfully send
Serial.println(rs.getResponseDescription());
}
void loop() {
// If something available
if (e220ttl.available()>1) {
// read the String message
ResponseContainer rc = e220ttl.receiveMessage();
// Is something goes wrong print error
if (rc.status.code!=1){
Serial.println(rc.status.getResponseDescription());
}else{
// Print the data received
Serial.println(rc.status.getResponseDescription());
Serial.println(rc.data);
}
}
if (Serial.available()) {
String input = Serial.readString();
ResponseStatus rs = e220ttl.sendFixedMessage(0, DESTINATION_ADDL, 23, input);
// Check If there is some problem of succesfully send
Serial.println(rs.getResponseDescription());
}
}
void printParameters(struct Configuration configuration) {
Serial.println("----------------------------------------");
Serial.print(F("HEAD : ")); Serial.print(configuration.COMMAND, HEX);Serial.print(" ");Serial.print(configuration.STARTING_ADDRESS, HEX);Serial.print(" ");Serial.println(configuration.LENGHT, HEX);
Serial.println(F(" "));
Serial.print(F("AddH : ")); Serial.println(configuration.ADDH, HEX);
Serial.print(F("AddL : ")); Serial.println(configuration.ADDL, HEX);
Serial.println(F(" "));
Serial.print(F("Chan : ")); Serial.print(configuration.CHAN, DEC); Serial.print(" -> "); Serial.println(configuration.getChannelDescription());
Serial.println(F(" "));
Serial.print(F("SpeedParityBit : ")); Serial.print(configuration.SPED.uartParity, BIN);Serial.print(" -> "); Serial.println(configuration.SPED.getUARTParityDescription());
Serial.print(F("SpeedUARTDatte : ")); Serial.print(configuration.SPED.uartBaudRate, BIN);Serial.print(" -> "); Serial.println(configuration.SPED.getUARTBaudRateDescription());
Serial.print(F("SpeedAirDataRate : ")); Serial.print(configuration.SPED.airDataRate, BIN);Serial.print(" -> "); Serial.println(configuration.SPED.getAirDataRateDescription());
Serial.println(F(" "));
Serial.print(F("OptionSubPacketSett: ")); Serial.print(configuration.OPTION.subPacketSetting, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getSubPacketSetting());
Serial.print(F("OptionTranPower : ")); Serial.print(configuration.OPTION.transmissionPower, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getTransmissionPowerDescription());
Serial.print(F("OptionRSSIAmbientNo: ")); Serial.print(configuration.OPTION.RSSIAmbientNoise, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getRSSIAmbientNoiseEnable());
Serial.println(F(" "));
Serial.print(F("TransModeWORPeriod : ")); Serial.print(configuration.TRANSMISSION_MODE.WORPeriod, BIN);Serial.print(" -> "); Serial.println(configuration.TRANSMISSION_MODE.getWORPeriodByParamsDescription());
Serial.print(F("TransModeEnableLBT : ")); Serial.print(configuration.TRANSMISSION_MODE.enableLBT, BIN);Serial.print(" -> "); Serial.println(configuration.TRANSMISSION_MODE.getLBTEnableByteDescription());
Serial.print(F("TransModeEnableRSSI: ")); Serial.print(configuration.TRANSMISSION_MODE.enableRSSI, BIN);Serial.print(" -> "); Serial.println(configuration.TRANSMISSION_MODE.getRSSIEnableByteDescription());
Serial.print(F("TransModeFixedTrans: ")); Serial.print(configuration.TRANSMISSION_MODE.fixedTransmission, BIN);Serial.print(" -> "); Serial.println(configuration.TRANSMISSION_MODE.getFixedTransmissionDescription());
Serial.println("----------------------------------------");
}
Trasmissione fissa con RSSI:
Per gestire RSSI, deve essere abilitato tramite configurazione, quindi la configurazione per il mittente diventa così:
ResponseStructContainer c;
c = e220ttl.getConfiguration();
Configuration configuration = *(Configuration*) c.data;
configuration.ADDL = 0x02;
configuration.ADDH = 0x00;
configuration.CHAN = 23;
configuration.SPED.uartBaudRate = UART_BPS_9600;
configuration.SPED.airDataRate = AIR_DATA_RATE_010_24;
configuration.SPED.uartParity = MODE_00_8N1;
configuration.OPTION.subPacketSetting = SPS_200_00;
configuration.OPTION.RSSIAmbientNoise = RSSI_AMBIENT_NOISE_DISABLED;
configuration.OPTION.transmissionPower = POWER_22;
configuration.TRANSMISSION_MODE.enableRSSI = RSSI_ENABLED;
configuration.TRANSMISSION_MODE.fixedTransmission = FT_FIXED_TRANSMISSION;
configuration.TRANSMISSION_MODE.enableLBT = LBT_DISABLED;
configuration.TRANSMISSION_MODE.WORPeriod = WOR_2000_011;
e220ttl.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
c.close();
e per il ricevitore:
ResponseStructContainer c;
c = e220ttl.getConfiguration();
Configuration configuration = *(Configuration*) c.data;
configuration.ADDL = 0x03;
configuration.ADDH = 0x00;
configuration.CHAN = 23;
configuration.SPED.uartBaudRate = UART_BPS_9600;
configuration.SPED.airDataRate = AIR_DATA_RATE_010_24;
configuration.SPED.uartParity = MODE_00_8N1;
configuration.OPTION.subPacketSetting = SPS_200_00;
configuration.OPTION.RSSIAmbientNoise = RSSI_AMBIENT_NOISE_DISABLED;
configuration.OPTION.transmissionPower = POWER_22;
configuration.TRANSMISSION_MODE.enableRSSI = RSSI_ENABLED;
configuration.TRANSMISSION_MODE.fixedTransmission = FT_FIXED_TRANSMISSION;
configuration.TRANSMISSION_MODE.enableLBT = LBT_DISABLED;
configuration.TRANSMISSION_MODE.WORPeriod = WOR_2000_011;
e220ttl.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
c.close();
Inoltre, in questo schizzo, presta attenzione a queste righe di codice:
// With FIXED SENDER configuration
// #define DESTINATION_ADDL 3
// With FIXED RECEIVER configuration
#define DESTINATION_ADDL 2
È necessario rimuovere il commento dalla corretta DESTINATION_ADDL per il mittente e il destinatario.
Ed ecco lo sketch con RSSI:
/*
* EBYTE LoRa E220
* Send a string message to a fixed point ADDH ADDL CHAN
*
* You must configure 2 device: one as SENDER (with FIXED SENDER config) and uncomment the relative
* define with the correct DESTINATION_ADDL, and one as RECEIVER (with FIXED RECEIVER config)
* and uncomment the relative define with the correct DESTINATION_ADDL.
*
* Write a string on serial monitor or reset to resend default value.
*
* You must uncommend the correct constructor.
*
* by Renzo Mischianti <https://mischianti.org>
*
* https://mischianti.org
*
* E220 ----- WeMos D1 mini ----- esp32 ----- Arduino Nano 33 IoT ----- Arduino MKR ----- ArduinoUNO
* M0 ----- D7 (or 3.3v) ----- 19 (or 3.3v) ----- 2 (or 3.3v) ----- 2 (or 3.3v) ----- 7 Volt div (or 3.3v)
* M1 ----- D6 (or 3.3v) ----- 21 (or 3.3v) ----- 4 (or 3.3v) ----- 4 (or 3.3v) ----- 6 Volt div (or 3.3v)
* TX ----- D3 (PullUP) ----- TX2 (PullUP) ----- TX1 (PullUP) ----- 14 (PullUP) ----- 4 (PullUP)
* RX ----- D4 (PullUP) ----- RX2 (PullUP) ----- RX1 (PullUP) ----- 13 (PullUP) ----- 5 Volt div (PullUP)
* AUX ----- D5 (PullUP) ----- 18 (PullUP) ----- 0 (PullUP) ----- 0 (PullUP) ----- 3 (PullUP)
* VCC ----- 3.3v/5v ----- 3.3v/5v ----- 3.3v/5v ----- 3.3v/5v ----- 3.3v/5v
* GND ----- GND ----- GND ----- GND ----- GND ----- GND
*
*/
// With FIXED SENDER configuration
// #define DESTINATION_ADDL 3
// With FIXED RECEIVER configuration
#define DESTINATION_ADDL 2
#include "Arduino.h"
#include "LoRa_E220.h"
// ---------- esp8266 pins --------------
//LoRa_E220 e220ttl(RX, TX, AUX, M0, M1); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
//LoRa_E220 e220ttl(D3, D4, D5, D7, D6); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX AUX M0 M1
//LoRa_E220 e220ttl(D2, D3); // Config without connect AUX and M0 M1
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(D2, D3); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
//LoRa_E220 e220ttl(&mySerial, D5, D7, D6); // AUX M0 M1
// -------------------------------------
// ---------- Arduino pins --------------
//LoRa_E220 e220ttl(4, 5, 3, 7, 6); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX AUX M0 M1
//LoRa_E220 e220ttl(4, 5); // Config without connect AUX and M0 M1
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(4, 5); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
//LoRa_E220 e220ttl(&mySerial, 3, 7, 6); // AUX M0 M1
// -------------------------------------
// ------------- Arduino Nano 33 IoT -------------
// LoRa_E220 e220ttl(&Serial1, 2, 4, 6); // RX AUX M0 M1
// -------------------------------------------------
// ------------- Arduino MKR WiFi 1010 -------------
LoRa_E220 e220ttl(&Serial1, 0, 2, 4); // RX AUX M0 M1
// -------------------------------------------------
// ---------- esp32 pins --------------
// LoRa_E220 e220ttl(&Serial2, 15, 21, 19); // RX AUX M0 M1
//LoRa_E220 e220ttl(&Serial2, 22, 4, 18, 21, 19, UART_BPS_RATE_9600); // esp32 RX <-- e220 TX, esp32 TX --> e220 RX AUX M0 M1
// -------------------------------------
void printParameters(struct Configuration configuration);
void setup() {
Serial.begin(9600);
delay(500);
// Startup all pins and UART
e220ttl.begin();
ResponseStructContainer c;
c = e220ttl.getConfiguration();
// It's important get configuration pointer before all other operation
Configuration configuration = *(Configuration*) c.data;
Serial.println(c.status.getResponseDescription());
Serial.println(c.status.code);
printParameters(configuration);
c.close();
Serial.println("Hi, I'm going to send message!");
// Send message
ResponseStatus rs = e220ttl.sendFixedMessage(0, DESTINATION_ADDL, 23, "Hello, world?");
// Check If there is some problem of succesfully send
Serial.println(rs.getResponseDescription());
}
void loop() {
// If something available
if (e220ttl.available()>1) {
// read the String message
ResponseContainer rc = e220ttl.receiveMessageRSSI();
// Is something goes wrong print error
if (rc.status.code!=1){
Serial.println(rc.status.getResponseDescription());
}else{
// Print the data received
Serial.println(rc.status.getResponseDescription());
Serial.println(rc.data);
Serial.print("RSSI: "); Serial.println(rc.rssi, DEC);
}
}
if (Serial.available()) {
String input = Serial.readString();
ResponseStatus rs = e220ttl.sendFixedMessage(0, DESTINATION_ADDL, 23, input);
// Check If there is some problem of succesfully send
Serial.println(rs.getResponseDescription());
}
}
void printParameters(struct Configuration configuration) {
Serial.println("----------------------------------------");
Serial.print(F("HEAD : ")); Serial.print(configuration.COMMAND, HEX);Serial.print(" ");Serial.print(configuration.STARTING_ADDRESS, HEX);Serial.print(" ");Serial.println(configuration.LENGHT, HEX);
Serial.println(F(" "));
Serial.print(F("AddH : ")); Serial.println(configuration.ADDH, HEX);
Serial.print(F("AddL : ")); Serial.println(configuration.ADDL, HEX);
Serial.println(F(" "));
Serial.print(F("Chan : ")); Serial.print(configuration.CHAN, DEC); Serial.print(" -> "); Serial.println(configuration.getChannelDescription());
Serial.println(F(" "));
Serial.print(F("SpeedParityBit : ")); Serial.print(configuration.SPED.uartParity, BIN);Serial.print(" -> "); Serial.println(configuration.SPED.getUARTParityDescription());
Serial.print(F("SpeedUARTDatte : ")); Serial.print(configuration.SPED.uartBaudRate, BIN);Serial.print(" -> "); Serial.println(configuration.SPED.getUARTBaudRateDescription());
Serial.print(F("SpeedAirDataRate : ")); Serial.print(configuration.SPED.airDataRate, BIN);Serial.print(" -> "); Serial.println(configuration.SPED.getAirDataRateDescription());
Serial.println(F(" "));
Serial.print(F("OptionSubPacketSett: ")); Serial.print(configuration.OPTION.subPacketSetting, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getSubPacketSetting());
Serial.print(F("OptionTranPower : ")); Serial.print(configuration.OPTION.transmissionPower, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getTransmissionPowerDescription());
Serial.print(F("OptionRSSIAmbientNo: ")); Serial.print(configuration.OPTION.RSSIAmbientNoise, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getRSSIAmbientNoiseEnable());
Serial.println(F(" "));
Serial.print(F("TransModeWORPeriod : ")); Serial.print(configuration.TRANSMISSION_MODE.WORPeriod, BIN);Serial.print(" -> "); Serial.println(configuration.TRANSMISSION_MODE.getWORPeriodByParamsDescription());
Serial.print(F("TransModeEnableLBT : ")); Serial.print(configuration.TRANSMISSION_MODE.enableLBT, BIN);Serial.print(" -> "); Serial.println(configuration.TRANSMISSION_MODE.getLBTEnableByteDescription());
Serial.print(F("TransModeEnableRSSI: ")); Serial.print(configuration.TRANSMISSION_MODE.enableRSSI, BIN);Serial.print(" -> "); Serial.println(configuration.TRANSMISSION_MODE.getRSSIEnableByteDescription());
Serial.print(F("TransModeFixedTrans: ")); Serial.print(configuration.TRANSMISSION_MODE.fixedTransmission, BIN);Serial.print(" -> "); Serial.println(configuration.TRANSMISSION_MODE.getFixedTransmissionDescription());
Serial.println("----------------------------------------");
}
Trasmissione fissa: broadcast
Possiamo testare la comunicazione broadcast con l’esatta configurazione dell’indirizzo e del canale.
Per fare un test, puoi creare tre dispositivi con queste tre configurazioni:
Dispositivo 1:
ResponseStructContainer c;
c = e220ttl.getConfiguration();
Configuration configuration = *(Configuration*) c.data;
configuration.ADDL = 0x04;
configuration.ADDH = 0x00;
configuration.CHAN = 23;
configuration.SPED.uartBaudRate = UART_BPS_9600;
configuration.SPED.airDataRate = AIR_DATA_RATE_010_24;
configuration.SPED.uartParity = MODE_00_8N1;
configuration.OPTION.subPacketSetting = SPS_200_00;
configuration.OPTION.RSSIAmbientNoise = RSSI_AMBIENT_NOISE_DISABLED;
configuration.OPTION.transmissionPower = POWER_22;
configuration.TRANSMISSION_MODE.enableRSSI = RSSI_DISABLED;
configuration.TRANSMISSION_MODE.enableRepeater = REPEATER_DISABLED;
configuration.TRANSMISSION_MODE.enableLBT = LBT_DISABLED;
configuration.TRANSMISSION_MODE.WORPeriod = WOR_2000_011;
e220ttl.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
c.close();
Dispositivo 2:
ResponseStructContainer c;
c = e220ttl.getConfiguration();
Configuration configuration = *(Configuration*) c.data;
configuration.ADDL = 0x05;
configuration.ADDH = 0x00;
configuration.CHAN = 23;
configuration.SPED.uartBaudRate = UART_BPS_9600;
configuration.SPED.airDataRate = AIR_DATA_RATE_010_24;
configuration.SPED.uartParity = MODE_00_8N1;
configuration.OPTION.subPacketSetting = SPS_200_00;
configuration.OPTION.RSSIAmbientNoise = RSSI_AMBIENT_NOISE_DISABLED;
configuration.OPTION.transmissionPower = POWER_22;
configuration.TRANSMISSION_MODE.enableRSSI = RSSI_DISABLED;
configuration.TRANSMISSION_MODE.fixedTransmission = FT_FIXED_TRANSMISSION;
configuration.TRANSMISSION_MODE.enableLBT = LBT_DISABLED;
configuration.TRANSMISSION_MODE.WORPeriod = WOR_2000_011;
e220ttl.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
c.close();
Dispositivo 3:
ResponseStructContainer c;
c = e220ttl.getConfiguration();
Configuration configuration = *(Configuration*) c.data;
configuration.ADDL = 0x06;
configuration.ADDH = 0x00;
configuration.CHAN = 23;
configuration.SPED.uartBaudRate = UART_BPS_9600;
configuration.SPED.airDataRate = AIR_DATA_RATE_010_24;
configuration.SPED.uartParity = MODE_00_8N1;
configuration.OPTION.subPacketSetting = SPS_200_00;
configuration.OPTION.RSSIAmbientNoise = RSSI_AMBIENT_NOISE_DISABLED;
configuration.OPTION.transmissionPower = POWER_22;
configuration.TRANSMISSION_MODE.enableRSSI = RSSI_DISABLED;
configuration.TRANSMISSION_MODE.fixedTransmission = FT_FIXED_TRANSMISSION;
configuration.TRANSMISSION_MODE.enableLBT = LBT_DISABLED;
configuration.TRANSMISSION_MODE.WORPeriod = WOR_2000_011;
e220ttl.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
c.close();
Il metodo da usare sarà:
// Send message
ResponseStatus rs = e220ttl.sendBroadcastFixedMessage(23, "Hello, world?");
// Check If there is some problem of succesfully send
Serial.println(rs.getResponseDescription());
o
// Send message
ResponseStatus rs = e220ttl.sendFixedMessage(BROADCAST_ADDRESS, BROADCAST_ADDRESS, 4, "Send message to channel 4");
Serial.println(rs.getResponseDescription());
Il ricevitore, come descritto, ha lo stesso codice perché il dispositivo gestisce il preambolo con Indirizzo e Canale.
Ecco lo sketch del mittente:
/*
* EBYTE LoRa E220
*
* Send a string message to all devices of the Channel CHAN 23
*
* Write a string on serial monitor or reset to send the string to all device on channel 23.
*
* Send a fixed message, you must check that the transmitter and receiver have different
* ADDL or ADDH, check the configuration down
*
* For the test you can use
* - BROADCAST MESSAGE 1
* - BROADCAST MESSAGE 2
* - BROADCAST MESSAGE 3
*
* Pai attention e220 support RSSI, if you want use that functionality you must enable RSSI on configuration
* configuration.TRANSMISSION_MODE.enableRSSI = RSSI_ENABLED;
*
* and uncomment #define ENABLE_RSSI true in this sketch
*
* by Renzo Mischianti <https://mischianti.org>
*
* https://mischianti.org
*
* E220 ----- WeMos D1 mini ----- esp32 ----- Arduino Nano 33 IoT ----- Arduino MKR ----- ArduinoUNO
* M0 ----- D7 (or 3.3v) ----- 19 (or 3.3v) ----- 2 (or 3.3v) ----- 2 (or 3.3v) ----- 7 Volt div (or 3.3v)
* M1 ----- D6 (or 3.3v) ----- 21 (or 3.3v) ----- 4 (or 3.3v) ----- 4 (or 3.3v) ----- 6 Volt div (or 3.3v)
* TX ----- D3 (PullUP) ----- TX2 (PullUP) ----- TX1 (PullUP) ----- 14 (PullUP) ----- 4 (PullUP)
* RX ----- D4 (PullUP) ----- RX2 (PullUP) ----- RX1 (PullUP) ----- 13 (PullUP) ----- 5 Volt div (PullUP)
* AUX ----- D5 (PullUP) ----- 18 (PullUP) ----- 0 (PullUP) ----- 0 (PullUP) ----- 3 (PullUP)
* VCC ----- 3.3v/5v ----- 3.3v/5v ----- 3.3v/5v ----- 3.3v/5v ----- 3.3v/5v
* GND ----- GND ----- GND ----- GND ----- GND ----- GND
*
*/
// If you want use RSSI uncomment //#define ENABLE_RSSI true
// and use relative configuration with RSSI enabled
//#define ENABLE_RSSI true
#include "Arduino.h"
#include "LoRa_E220.h"
// ---------- esp8266 pins --------------
//LoRa_E220 e220ttl(RX, TX, AUX, M0, M1); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
//LoRa_E220 e220ttl(D3, D4, D5, D7, D6); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX AUX M0 M1
//LoRa_E220 e220ttl(D2, D3); // Config without connect AUX and M0 M1
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(D2, D3); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
//LoRa_E220 e220ttl(&mySerial, D5, D7, D6); // AUX M0 M1
// -------------------------------------
// ---------- Arduino pins --------------
//LoRa_E220 e220ttl(4, 5, 3, 7, 6); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX AUX M0 M1
//LoRa_E220 e220ttl(4, 5); // Config without connect AUX and M0 M1
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(4, 5); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
//LoRa_E220 e220ttl(&mySerial, 3, 7, 6); // AUX M0 M1
// -------------------------------------
// ------------- Arduino Nano 33 IoT -------------
// LoRa_E220 e220ttl(&Serial1, 2, 4, 6); // RX AUX M0 M1
// -------------------------------------------------
// ------------- Arduino MKR WiFi 1010 -------------
LoRa_E220 e220ttl(&Serial1, 0, 2, 4); // RX AUX M0 M1
// -------------------------------------------------
// ---------- esp32 pins --------------
// LoRa_E220 e220ttl(&Serial2, 15, 21, 19); // RX AUX M0 M1
//LoRa_E220 e220ttl(&Serial2, 22, 4, 18, 21, 19, UART_BPS_RATE_9600); // esp32 RX <-- e220 TX, esp32 TX --> e220 RX AUX M0 M1
// -------------------------------------
void setup() {
Serial.begin(9600);
delay(500);
// Startup all pins and UART
e220ttl.begin();
Serial.println("Hi, I'm going to send message!");
// Send message
ResponseStatus rs = e220ttl.sendBroadcastFixedMessage(23, "Hello, world?");
// Check If there is some problem of succesfully send
Serial.println(rs.getResponseDescription());
}
void loop() {
// If something available
if (e220ttl.available()>1) {
// read the String message
#ifdef ENABLE_RSSI
ResponseContainer rc = e220ttl.receiveMessageRSSI();
#else
ResponseContainer rc = e220ttl.receiveMessage();
#endif
// Is something goes wrong print error
if (rc.status.code!=1){
Serial.println(rc.status.getResponseDescription());
}else{
// Print the data received
Serial.println(rc.status.getResponseDescription());
Serial.println(rc.data);
#ifdef ENABLE_RSSI
Serial.print("RSSI: "); Serial.println(rc.rssi, DEC);
#endif
}
}
if (Serial.available()) {
String input = Serial.readString();
ResponseStatus rs = e220ttl.sendBroadcastFixedMessage(23, input);
// Check If there is some problem of succesfully send
Serial.println(rs.getResponseDescription());
}
}
Trasmissione fissa: monitoraggio
Come hai già visto nel primo schema, puoi ascoltare tutti i messaggi nel canale specificato e devi configurare il tuo indirizzo in questo modo, con un indirizzo uguale a 0xFFFF.
ResponseStructContainer c;
c = e220ttl.getConfiguration();
Configuration configuration = *(Configuration*) c.data;
configuration.ADDL = BROADCAST_ADDRESS;
configuration.ADDH = BROADCAST_ADDRESS;
configuration.CHAN = 23;
configuration.SPED.uartBaudRate = UART_BPS_9600;
configuration.SPED.airDataRate = AIR_DATA_RATE_010_24;
configuration.SPED.uartParity = MODE_00_8N1;
configuration.OPTION.subPacketSetting = SPS_200_00;
configuration.OPTION.RSSIAmbientNoise = RSSI_AMBIENT_NOISE_DISABLED;
configuration.OPTION.transmissionPower = POWER_22;
configuration.TRANSMISSION_MODE.enableRSSI = RSSI_DISABLED;
configuration.TRANSMISSION_MODE.fixedTransmission = FT_FIXED_TRANSMISSION;
configuration.TRANSMISSION_MODE.enableLBT = LBT_DISABLED;
configuration.TRANSMISSION_MODE.WORPeriod = WOR_2000_011;
e220ttl.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
c.close();
Per ricevere i messaggi:
/*
* EBYTE LoRa E220
*
* Receive messages on CHANNEL 23
* Uncomment #define ENABLE_RSSI true in this sketch
* if the sender send RSSI also
*
* by Renzo Mischianti <https://mischianti.org>
*
* https://mischianti.org
*
* E220 ----- WeMos D1 mini ----- esp32 ----- Arduino Nano 33 IoT ----- Arduino MKR ----- ArduinoUNO
* M0 ----- D7 (or 3.3v) ----- 19 (or 3.3v) ----- 2 (or 3.3v) ----- 2 (or 3.3v) ----- 7 Volt div (or 3.3v)
* M1 ----- D6 (or 3.3v) ----- 21 (or 3.3v) ----- 4 (or 3.3v) ----- 4 (or 3.3v) ----- 6 Volt div (or 3.3v)
* TX ----- D3 (PullUP) ----- TX2 (PullUP) ----- TX1 (PullUP) ----- 14 (PullUP) ----- 4 (PullUP)
* RX ----- D4 (PullUP) ----- RX2 (PullUP) ----- RX1 (PullUP) ----- 13 (PullUP) ----- 5 Volt div (PullUP)
* AUX ----- D5 (PullUP) ----- 18 (PullUP) ----- 0 (PullUP) ----- 0 (PullUP) ----- 3 (PullUP)
* VCC ----- 3.3v/5v ----- 3.3v/5v ----- 3.3v/5v ----- 3.3v/5v ----- 3.3v/5v
* GND ----- GND ----- GND ----- GND ----- GND ----- GND
*
*/
// If you want use RSSI uncomment
//#define ENABLE_RSSI true
#include "Arduino.h"
#include "LoRa_E220.h"
// ---------- esp8266 pins --------------
//LoRa_E220 e220ttl(RX, TX, AUX, M0, M1); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
LoRa_E220 e220ttl(D3, D4, D5, D7, D6); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX AUX M0 M1
//LoRa_E220 e220ttl(D2, D3); // Config without connect AUX and M0 M1
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(D2, D3); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
//LoRa_E220 e220ttl(&mySerial, D5, D7, D6); // AUX M0 M1
// -------------------------------------
// ---------- Arduino pins --------------
//LoRa_E220 e220ttl(4, 5, 3, 7, 6); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX AUX M0 M1
//LoRa_E220 e220ttl(4, 5); // Config without connect AUX and M0 M1
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(4, 5); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
//LoRa_E220 e220ttl(&mySerial, 3, 7, 6); // AUX M0 M1
// -------------------------------------
// ------------- Arduino Nano 33 IoT -------------
// LoRa_E220 e220ttl(&Serial1, 2, 4, 6); // RX AUX M0 M1
// -------------------------------------------------
// ------------- Arduino MKR WiFi 1010 -------------
// LoRa_E220 e220ttl(&Serial1, 0, 2, 4); // RX AUX M0 M1
// -------------------------------------------------
// ---------- esp32 pins --------------
// LoRa_E220 e220ttl(&Serial2, 15, 21, 19); // RX AUX M0 M1
//LoRa_E220 e220ttl(&Serial2, 22, 4, 18, 21, 19, UART_BPS_RATE_9600); // esp32 RX <-- e220 TX, esp32 TX --> e220 RX AUX M0 M1
// -------------------------------------
void setup() {
Serial.begin(9600);
delay(500);
// Startup all pins and UART
e220ttl.begin();
Serial.println("Start receiving!");
}
void loop() {
// If something available
if (e220ttl.available()>1) {
Serial.println("Message received!");
// read the String message
#ifdef ENABLE_RSSI
ResponseContainer rc = e220ttl.receiveMessageRSSI();
#else
ResponseContainer rc = e220ttl.receiveMessage();
#endif
// Is something goes wrong print error
if (rc.status.code!=1){
Serial.println(rc.status.getResponseDescription());
}else{
// Print the data received
Serial.println(rc.status.getResponseDescription());
Serial.println(rc.data);
#ifdef ENABLE_RSSI
Serial.print("RSSI: "); Serial.println(rc.rssi, DEC);
#endif
}
}
}
Grazie
- Ebyte LoRa E220 LLCC68 per Arduino, esp32 o esp8266: specifiche ed utilizzo base
- Ebyte LoRa E220 LLCC68 per Arduino, esp32 o esp8266: libreria
- Ebyte LoRa E220 LLCC68 per Arduino, esp32 o esp8266: configurazione
- Ebyte LoRa E220 LLCC68 per Arduino, esp32 o esp8266: trasmissione fissa, broadcast, monitor e RSSI
- Ebyte LoRa E220 LLCC68 per Arduino, esp32 o esp8266: power saving ed invio di dati strutturati
- Ebyte LoRa E220 LLCC68 per Arduino, esp32 o esp8266: WOR il microcontrollore e lo shield per Arduino
- Ebyte LoRa E220 LLCC68 per Arduino, esp32 o esp8266: WOR il microcontrollore e lo shield per il WeMos D1 mini
- Ebyte LoRa E220 LLCC68 per Arduino, esp32 o esp8266: WOR il microcontrollore e lo shield per l’esp32 dev v1
Shield e PCB
- Mischianti Arduino LoRa shield (Open source)
- Mischianti WeMos LoRa shield (Open source)
- Mischianti ESP32 DOIT DEV KIT v1 shield (Open source)