mirror of
https://github.com/timmbogner/Farm-Data-Relay-System
synced 2024-11-10 07:10:42 +00:00
Add files via upload
added LoRa support!
This commit is contained in:
parent
2d9c0672dc
commit
a5a75c6821
@ -1,3 +1,4 @@
|
||||
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// GATEWAY 2.000
|
||||
@ -19,11 +20,20 @@
|
||||
#include "DataReading.h"
|
||||
#include <PubSubClient.h>
|
||||
#include "fdrs_functions.h"
|
||||
#include <LoRa.h>
|
||||
|
||||
#ifdef USE_WIFI
|
||||
const char* ssid = WIFI_NET;
|
||||
const char* password = WIFI_PASS;
|
||||
const char* mqtt_server = MQTT_ADDR;
|
||||
|
||||
#endif
|
||||
#ifdef USE_LORA
|
||||
void sendLoRa() {
|
||||
LoRa.beginPacket();
|
||||
LoRa.write((uint8_t*)&theData, ln);
|
||||
LoRa.endPacket();
|
||||
}
|
||||
#endif
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
begin_espnow();
|
||||
@ -36,15 +46,29 @@ void setup() {
|
||||
client.setServer(mqtt_server, 1883);
|
||||
client.setCallback(mqtt_callback);
|
||||
#endif
|
||||
#ifdef USE_LORA
|
||||
SPI.begin(SCK, MISO, MOSI, SS);
|
||||
LoRa.setPins(SS, RST, DIO0);
|
||||
if (!LoRa.begin(BAND)) {
|
||||
while (1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop() {
|
||||
while (Serial.available()) {
|
||||
getSerial();
|
||||
}
|
||||
if (newData != 0) {
|
||||
|
||||
|
||||
#ifdef USE_LORA
|
||||
int packetSize = LoRa.parsePacket();
|
||||
if (packetSize)
|
||||
{
|
||||
LoRa.readBytes((uint8_t *)&theData, packetSize);
|
||||
ln = packetSize;
|
||||
newData = 6;
|
||||
}
|
||||
#endif
|
||||
if (newData) {
|
||||
switch (newData) {
|
||||
case 1: //ESP-NOW #1
|
||||
ESPNOW1_ACT
|
||||
@ -61,11 +85,12 @@ void loop() {
|
||||
case 5: //MQTT
|
||||
MQTT_ACT
|
||||
break;
|
||||
case 6: //LoRa
|
||||
LORA_ACT
|
||||
break;
|
||||
}
|
||||
newData = 0;
|
||||
}
|
||||
|
||||
|
||||
#ifdef USE_WIFI
|
||||
if (!client.connected()) {
|
||||
reconnect();
|
||||
|
@ -4,23 +4,35 @@
|
||||
// This is still in progress. Stay tuned!
|
||||
|
||||
//#define USE_WIFI //You cannot use ESP-NOW while WiFi is in use
|
||||
#define WIFI_NET "Your SSID"
|
||||
#define WIFI_PASS "Password"
|
||||
#define MQTT_ADDR "192.168.0.8"
|
||||
//#define WIFI_NET "Your SSID"
|
||||
//#define WIFI_PASS "Password"
|
||||
//#define MQTT_ADDR "192.168.0.8"
|
||||
|
||||
#define USE_LORA
|
||||
#define SCK 5
|
||||
#define MISO 19
|
||||
#define MOSI 27
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DIO0 26
|
||||
//433E6 for Asia
|
||||
//866E6 for Europe
|
||||
//915E6 for North America
|
||||
#define BAND 915E6
|
||||
|
||||
#define USE_LORA //Coming soon
|
||||
|
||||
#define UNIT_MAC 0x00// THIS UNIT
|
||||
#define PREV_MAC 0x01// ESPNOW1 Address
|
||||
#define NEXT_MAC 0x02// ESPNOW2 Address
|
||||
|
||||
//Actions -- Define what happens when a message arrives.
|
||||
//Actions -- Define what happens when a packet arrives at each interface:
|
||||
|
||||
#define ESPNOW1_ACT sendESPNOW(2); sendSerial();
|
||||
#define ESPNOW2_ACT sendESPNOW(1); sendSerial();
|
||||
#define ESPNOWG_ACT sendSerial();
|
||||
#define SERIAL_ACT sendESPNOW(0);
|
||||
#define MQTT_ACT sendSerial();
|
||||
#define ESPNOW1_ACT //sendESPNOW(2); sendSerial();
|
||||
#define ESPNOW2_ACT //sendESPNOW(1); sendSerial();
|
||||
#define ESPNOWG_ACT //sendSerial(); sendLoRa();
|
||||
#define SERIAL_ACT //sendESPNOW(0); sendLoRa();
|
||||
#define MQTT_ACT //sendSerial();
|
||||
#define LORA_ACT sendSerial();
|
||||
|
||||
//#define ESPNOW1_ACTION
|
||||
//#define ESPNOW2_ACTION
|
||||
|
Loading…
Reference in New Issue
Block a user