mirror of
https://github.com/timmbogner/Farm-Data-Relay-System
synced 2024-11-10 07:10:42 +00:00
On the way back to a working example
This commit is contained in:
parent
69180f5f22
commit
fc117c1f42
@ -4,7 +4,7 @@
|
|||||||
//
|
//
|
||||||
// Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
// Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||||
//
|
//
|
||||||
#include "sensor_config.h"
|
#include "sensor_setup.h"
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <espnow.h>
|
#include <espnow.h>
|
||||||
@ -13,47 +13,11 @@
|
|||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <esp_wifi.h>
|
#include <esp_wifi.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_LORA
|
#ifdef USE_LORA
|
||||||
#include <LoRa.h>
|
#include <LoRa.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef GLOBALS
|
|
||||||
#define FDRS_BAND GLOBAL_BAND
|
|
||||||
#define FDRS_SF GLOBAL_SF
|
|
||||||
#else
|
|
||||||
#define FDRS_BAND BAND
|
|
||||||
#define FDRS_SF SF
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
#define DBG(a) (Serial.println(a))
|
|
||||||
#else
|
|
||||||
#define DBG(a)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define STATUS_T 0 // Status
|
|
||||||
#define TEMP_T 1 // Temperature
|
|
||||||
#define TEMP2_T 2 // Temperature #2
|
|
||||||
#define HUMIDITY_T 3 // Relative Humidity
|
|
||||||
#define PRESSURE_T 4 // Atmospheric Pressure
|
|
||||||
#define LIGHT_T 5 // Light (lux)
|
|
||||||
#define SOIL_T 6 // Soil Moisture
|
|
||||||
#define SOIL2_T 7 // Soil Moisture #2
|
|
||||||
#define SOILR_T 8 // Soil Resistance
|
|
||||||
#define SOILR2_T 9 // Soil Resistance #2
|
|
||||||
#define OXYGEN_T 10 // Oxygen
|
|
||||||
#define CO2_T 11 // Carbon Dioxide
|
|
||||||
#define WINDSPD_T 12 // Wind Speed
|
|
||||||
#define WINDHDG_T 13 // Wind Direction
|
|
||||||
#define RAINFALL_T 14 // Rainfall
|
|
||||||
#define MOTION_T 15 // Motion
|
|
||||||
#define VOLTAGE_T 16 // Voltage
|
|
||||||
#define VOLTAGE2_T 17 // Voltage #2
|
|
||||||
#define CURRENT_T 18 // Current
|
|
||||||
#define CURRENT2_T 19 // Current #2
|
|
||||||
#define IT_T 20 // Iterations
|
|
||||||
#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE // Should only be changed if implementing multiple FDRS systems.
|
|
||||||
|
|
||||||
typedef struct __attribute__((packed)) DataReading {
|
typedef struct __attribute__((packed)) DataReading {
|
||||||
float d;
|
float d;
|
||||||
uint16_t id;
|
uint16_t id;
|
||||||
@ -64,7 +28,7 @@ typedef struct __attribute__((packed)) DataReading {
|
|||||||
const uint16_t espnow_size = 250 / sizeof(DataReading);
|
const uint16_t espnow_size = 250 / sizeof(DataReading);
|
||||||
uint8_t gatewayAddress[] = {MAC_PREFIX, GTWY_MAC};
|
uint8_t gatewayAddress[] = {MAC_PREFIX, GTWY_MAC};
|
||||||
uint8_t gtwyAddress[] = {gatewayAddress[3], gatewayAddress[4], GTWY_MAC};
|
uint8_t gtwyAddress[] = {gatewayAddress[3], gatewayAddress[4], GTWY_MAC};
|
||||||
uint8_t LoRaAddress[] = {0x42, 0x00};
|
|
||||||
|
|
||||||
uint32_t wait_time = 0;
|
uint32_t wait_time = 0;
|
||||||
DataReading fdrsData[espnow_size];
|
DataReading fdrsData[espnow_size];
|
||||||
@ -113,23 +77,23 @@ void beginFDRS() {
|
|||||||
#endif
|
#endif
|
||||||
#ifdef USE_LORA
|
#ifdef USE_LORA
|
||||||
DBG("Initializing LoRa!");
|
DBG("Initializing LoRa!");
|
||||||
DBG(BAND);
|
DBG(GLOBAL_BAND);
|
||||||
DBG(SF);
|
DBG(SF);
|
||||||
#ifndef __AVR__
|
#ifndef __AVR__
|
||||||
SPI.begin(SCK, MISO, MOSI, SS);
|
SPI.begin(SCK, MISO, MOSI, SS);
|
||||||
#endif
|
#endif
|
||||||
LoRa.setPins(SS, RST, DIO0);
|
LoRa.setPins(SS, RST, DIO0);
|
||||||
if (!LoRa.begin(FDRS_BAND)) {
|
if (!LoRa.begin(BAND)) {
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
LoRa.setSpreadingFactor(FDRS_SF);
|
LoRa.setSpreadingFactor(SF);
|
||||||
DBG(" LoRa Initialized.");
|
DBG(" LoRa Initialized.");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
void transmitLoRa(uint8_t* mac, DataReading * packet, uint8_t len) {
|
void transmitLoRa(uint8_t* mac, DataReading * packet, uint8_t len) {
|
||||||
#ifdef USE_LORA
|
#ifdef USE_LORA
|
||||||
uint8_t pkt[5 + (len * sizeof(DataReading))];
|
uint8_t pkt[5 + (len * sizeof(DataReading))];
|
||||||
memcpy(&pkt, mac, 3); //
|
memcpy(&pkt, mac, 3); //
|
||||||
memcpy(&pkt[3], &LoRaAddress, 2);
|
memcpy(&pkt[3], &LoRaAddress, 2);
|
||||||
memcpy(&pkt[5], packet, len * sizeof(DataReading));
|
memcpy(&pkt[5], packet, len * sizeof(DataReading));
|
||||||
LoRa.beginPacket();
|
LoRa.beginPacket();
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#define DEBUG
|
#define DEBUG
|
||||||
#define CREDENTIALS
|
#define CREDENTIALS
|
||||||
|
|
||||||
#include <FDRSdefaults.h>
|
#include <fdrs_globals.h>
|
||||||
#include "fdrs_sensor.h"
|
#include "fdrs_sensor.h"
|
||||||
|
|
||||||
float data1;
|
float data1;
|
||||||
|
@ -19,6 +19,12 @@
|
|||||||
#include <LoRa.h>
|
#include <LoRa.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
#define DBG(a) (Serial.println(a))
|
||||||
|
#else
|
||||||
|
#define DBG(a)
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct __attribute__((packed)) DataReading {
|
typedef struct __attribute__((packed)) DataReading {
|
||||||
float d;
|
float d;
|
||||||
uint16_t id;
|
uint16_t id;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#define DEBUG
|
#define DEBUG
|
||||||
#define CREDENTIALS
|
#define CREDENTIALS
|
||||||
|
|
||||||
#include <fdrs_defaults.h>
|
#include <fdrs_globals.h>
|
||||||
#include "fdrs_config.h"
|
#include "fdrs_config.h"
|
||||||
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
@ -73,7 +73,6 @@ void setup() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//DBG(sizeof(DataReading));
|
//DBG(sizeof(DataReading));
|
||||||
client.publish(TOPIC_STATUS, "FDRS initialized");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,3 +39,13 @@
|
|||||||
#define SS 18
|
#define SS 18
|
||||||
#define RST 14
|
#define RST 14
|
||||||
#define DIO0 26
|
#define DIO0 26
|
||||||
|
|
||||||
|
// Buffer Delays - in milliseconds
|
||||||
|
#define ESPNOW1_DELAY 0
|
||||||
|
#define ESPNOW2_DELAY 0
|
||||||
|
#define ESPNOWG_DELAY 0
|
||||||
|
#define SERIAL_DELAY 0
|
||||||
|
#define MQTT_DELAY 0
|
||||||
|
#define LORAG_DELAY 1000
|
||||||
|
#define LORA1_DELAY 1000
|
||||||
|
#define LORA2_DELAY 1000
|
||||||
|
@ -4,6 +4,20 @@
|
|||||||
#define DBG(a)
|
#define DBG(a)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined (ESP32)
|
||||||
|
#define UART_IF Serial1
|
||||||
|
#else
|
||||||
|
#define UART_IF Serial
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GLOBALS
|
||||||
|
#define FDRS_BAND GLOBAL_BAND
|
||||||
|
#define FDRS_SF GLOBAL_SF
|
||||||
|
#else
|
||||||
|
#define FDRS_BAND BAND
|
||||||
|
#define FDRS_SF SF
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct __attribute__((packed)) DataReading {
|
typedef struct __attribute__((packed)) DataReading {
|
||||||
float d;
|
float d;
|
||||||
uint16_t id;
|
uint16_t id;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#define DEBUG
|
#define DEBUG
|
||||||
#define CREDENTIALS
|
#define CREDENTIALS
|
||||||
|
|
||||||
#include <fdrs_defaults.h>
|
#include <fdrs_globals.h>
|
||||||
#include "fdrs_config.h"
|
#include "fdrs_config.h"
|
||||||
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
@ -66,14 +66,13 @@ void setup() {
|
|||||||
DBG("Initializing LoRa!");
|
DBG("Initializing LoRa!");
|
||||||
SPI.begin(SCK, MISO, MOSI, SS);
|
SPI.begin(SCK, MISO, MOSI, SS);
|
||||||
LoRa.setPins(SS, RST, DIO0);
|
LoRa.setPins(SS, RST, DIO0);
|
||||||
if (!LoRa.begin(BAND)) {
|
if (!LoRa.begin(GLOBAL_BAND)) {
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
DBG(" LoRa initialized.");
|
DBG(" LoRa initialized.");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//DBG(sizeof(DataReading));
|
//DBG(sizeof(DataReading));
|
||||||
client.publish(TOPIC_STATUS, "FDRS initialized");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,41 +2,69 @@
|
|||||||
//
|
//
|
||||||
// GATEWAY 2.000 Configuration
|
// GATEWAY 2.000 Configuration
|
||||||
|
|
||||||
#define UNIT_MAC 0x04 // The address of this gateway
|
#include <fdrs_globals.h> //Uncomment if you install the globals file
|
||||||
#define ESPNOW1_PEER 0xFD // ESPNOW1 Address
|
#define DEBUG
|
||||||
#define ESPNOW2_PEER 0xFE // ESPNOW2 Address
|
|
||||||
#define LORA1_PEER 0xFD // LoRa1 Address
|
#define UNIT_MAC 0x04 // The address of this gateway
|
||||||
#define LORA2_PEER 0xFE // LoRa2 Address
|
|
||||||
|
|
||||||
//Actions -- Define what happens when a packet arrives at each interface:
|
//Actions -- Define what happens when a packet arrives at each interface:
|
||||||
//Current function options are: sendESPNOW(MAC), sendSerial(), sendMQTT(), bufferESPNOW(interface), bufferSerial(), and bufferLoRa(interface).
|
//Current function options are: sendESPNOW(MAC), sendSerial(), sendMQTT(), bufferESPNOW(interface), bufferSerial(), and bufferLoRa(interface).
|
||||||
|
|
||||||
#define ESPNOWG_ACT sendSerial();
|
#define ESPNOWG_ACT sendSerial();
|
||||||
#define SERIAL_ACT
|
#define SERIAL_ACT //sendMQTT();
|
||||||
#define MQTT_ACT
|
#define MQTT_ACT
|
||||||
#define LORAG_ACT sendSerial();
|
#define LORAG_ACT sendSerial();
|
||||||
|
|
||||||
|
#define USE_LORA
|
||||||
|
//#define USE_WIFI //Used only for MQTT gateway
|
||||||
|
|
||||||
|
//#define WIFI_SSID "Your SSID"
|
||||||
|
//#define WIFI_PASS "Your Password"
|
||||||
|
//#define MQTT_ADDR "192.168.0.8"
|
||||||
|
|
||||||
|
// Peer addresses
|
||||||
|
#define ESPNOW1_PEER 0x04 // ESPNOW1 Address
|
||||||
|
#define ESPNOW2_PEER 0x05 // ESPNOW2 Address
|
||||||
|
#define LORA1_PEER 0x04 // LoRa1 Address
|
||||||
|
#define LORA2_PEER 0x05 // LoRa2 Address
|
||||||
|
|
||||||
|
// Peer Actions
|
||||||
#define ESPNOW1_ACT
|
#define ESPNOW1_ACT
|
||||||
#define ESPNOW2_ACT
|
#define ESPNOW2_ACT
|
||||||
#define LORA1_ACT
|
#define LORA1_ACT
|
||||||
#define LORA2_ACT
|
#define LORA2_ACT
|
||||||
|
|
||||||
#define USE_LORA
|
//Pins for UART data interface (ESP32 only)
|
||||||
//#define USE_WIFI //Used only for MQTT gateway
|
|
||||||
|
|
||||||
#define CREDENTIALS
|
|
||||||
|
|
||||||
#if defined (ESP32)
|
|
||||||
#define RXD2 14
|
#define RXD2 14
|
||||||
#define TXD2 15
|
#define TXD2 15
|
||||||
#define UART_IF Serial2
|
|
||||||
#else
|
|
||||||
#define UART_IF Serial
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//LoRa Configuration -- Needed only if this device is using LoRa
|
//LoRa Configuration -- Needed only if using LoRa
|
||||||
#define SCK 5
|
#define SCK 5
|
||||||
#define MISO 19
|
#define MISO 19
|
||||||
#define MOSI 27
|
#define MOSI 27
|
||||||
#define SS 18
|
#define SS 18
|
||||||
#define RST 14
|
#define RST 14
|
||||||
#define DIO0 26
|
#define DIO0 26
|
||||||
|
//433E6 for Asia
|
||||||
|
//866E6 for Europe
|
||||||
|
//915E6 for North America
|
||||||
|
//#define BAND 915E6
|
||||||
|
//#define SF 7
|
||||||
|
|
||||||
|
// Buffer Delays - in milliseconds
|
||||||
|
#define ESPNOW1_DELAY 0
|
||||||
|
#define ESPNOW2_DELAY 0
|
||||||
|
#define ESPNOWG_DELAY 0
|
||||||
|
#define SERIAL_DELAY 0
|
||||||
|
#define MQTT_DELAY 0
|
||||||
|
#define LORAG_DELAY 1000
|
||||||
|
#define LORA1_DELAY 1000
|
||||||
|
#define LORA2_DELAY 1000
|
||||||
|
//#define USE_LED //Not yet fully implemented
|
||||||
|
#define LED_PIN 32
|
||||||
|
#define NUM_LEDS 4
|
||||||
|
|
||||||
|
// MQTT Topics
|
||||||
|
#define TOPIC_DATA "FDRS/DATA"
|
||||||
|
#define TOPIC_STATUS "FDRS/STATUS"
|
||||||
|
#define TOPIC_COMMAND "FDRS/COMMAND"
|
||||||
|
@ -140,9 +140,10 @@ void getLoRa() {
|
|||||||
uint8_t packet[packetSize];
|
uint8_t packet[packetSize];
|
||||||
uint8_t incLORAMAC[2];
|
uint8_t incLORAMAC[2];
|
||||||
LoRa.readBytes((uint8_t *)&packet, packetSize);
|
LoRa.readBytes((uint8_t *)&packet, packetSize);
|
||||||
for (int i = 0; i < packetSize; i++) {
|
/*for (int i = 0; i < packetSize; i++) {
|
||||||
Serial.println(packet[i], HEX);
|
Serial.println(packet[i], HEX);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
if (memcmp(&packet, &selfAddress[3], 3) == 0) { //Check if addressed to this device
|
if (memcmp(&packet, &selfAddress[3], 3) == 0) { //Check if addressed to this device
|
||||||
DBG("Packet for me");
|
DBG("Packet for me");
|
||||||
memcpy(&incLORAMAC, &packet[3], 2); //Split off address portion of packet
|
memcpy(&incLORAMAC, &packet[3], 2); //Split off address portion of packet
|
||||||
|
Loading…
Reference in New Issue
Block a user