Commit c65028ac authored by Giacomo Lavermicocca's avatar Giacomo Lavermicocca

backup of tries

parent 1fca15ec
/*
Uses interrup method check the new incoming messages, and print via serial
in 115200 baud rate.
The default interrupt pin in SX1276/8(DIO0) connected to ESP32's GPIO26
by Aaron.Lee from HelTec AutoMation, ChengDu, China
成都惠利特自动化科技有限公司
www.heltec.cn
this project also realess in GitHub:
https://github.com/Heltec-Aaron-Lee/WiFi_Kit_series
*/
#include <SPI.h>
#include <LoRa.h>
// Pin definetion of WIFI LoRa 32
// HelTec AutoMation 2017 support@heltec.cn
#define SCK 5 // GPIO5 -- SX127x's SCK
#define MISO 19 // GPIO19 -- SX127x's MISO
#define MOSI 27 // GPIO27 -- SX127x's MOSI
#define SS 18 // GPIO18 -- SX127x's CS
#define RST 14 // GPIO14 -- SX127x's RESET
#define DI0 26 // GPIO26 -- SX127x's IRQ(Interrupt Request)
#define BAND 868E6 //you can set band here directly,e.g. 868E6,915E6
#define PABOOST true
#define RELE_1 0
#define RELE_2 22 //2
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println("LoRa Receiver Callback");
SPI.begin(SCK,MISO,MOSI,SS);
LoRa.setPins(SS,RST,DI0);
if (!LoRa.begin(BAND,PABOOST)) {
Serial.println("Starting LoRa failed!");
while (1);
}
pinMode(RELE_1,OUTPUT);
pinMode(RELE_2,OUTPUT);
// register the receive callback
LoRa.onReceive(onReceive);
// put the radio into receive mode
LoRa.receive();
}
void loop() {
// do nothing
// wait for a second
}
void onReceive(int packetSize)
{
// received a packet
Serial.print("Received packet '");
// read packet
String str;
for (int i = 0; i < packetSize; i++)
{
char p = (char)LoRa.read();
Serial.print(p);
str += p;
}
if(str == "hello 1")
{
digitalWrite(RELE_1, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(RELE_2, HIGH); // turn the LED on (HIGH is the voltage level)
} else {
digitalWrite(RELE_1, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(RELE_2, LOW); // turn the LED on (HIGH is the voltage level)
}
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.print(str);
Serial.print(" ");
Serial.println(LoRa.packetRssi());
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment