mirror of
https://github.com/timmbogner/Farm-Data-Relay-System
synced 2024-11-10 07:10:42 +00:00
Changed to my_
added hyphen in the my_xxx defines
This commit is contained in:
parent
a1188238cf
commit
a0de0339a1
@ -1,208 +0,0 @@
|
|||||||
// FARM DATA RELAY SYSTEM
|
|
||||||
//
|
|
||||||
// "fdrs_sensor.h"
|
|
||||||
//
|
|
||||||
// Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
|
||||||
//
|
|
||||||
#define READING_ID 1 //Unique ID for this sensor
|
|
||||||
#define GTWY_MAC 0x00 //Address of the nearest gateway
|
|
||||||
|
|
||||||
//#define USE_ESPNOW
|
|
||||||
#define USE_LORA
|
|
||||||
#define DEEP_SLEEP
|
|
||||||
//#define POWER_CTRL 14
|
|
||||||
#define DEBUG
|
|
||||||
#define CREDENTIALS
|
|
||||||
#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE
|
|
||||||
|
|
||||||
//LoRa Configuration
|
|
||||||
#define SCK 5
|
|
||||||
#define MISO 19
|
|
||||||
#define MOSI 27
|
|
||||||
#define SS 18
|
|
||||||
#define RST 14
|
|
||||||
#define DIO0 26
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef CREDENTIALS
|
|
||||||
#include <credentials.h>
|
|
||||||
#define WIFI_NET mySSID
|
|
||||||
#define WIFI_PASS myPASSWORD
|
|
||||||
#define MQTT_ADDR MQTT_BROKER
|
|
||||||
#define BAND myBAND
|
|
||||||
#else
|
|
||||||
#define WIFI_NET "Your SSID"
|
|
||||||
#define WIFI_PASS "Password"
|
|
||||||
#define MQTT_ADDR "192.168.0.8"
|
|
||||||
|
|
||||||
//433E6 for Asia
|
|
||||||
//866E6 for Europe
|
|
||||||
//915E6 for North America
|
|
||||||
#define BAND 915E6
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct __attribute__((packed)) DataReading {
|
|
||||||
float d;
|
|
||||||
uint16_t id;
|
|
||||||
uint8_t t;
|
|
||||||
|
|
||||||
} DataReading;
|
|
||||||
|
|
||||||
#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
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(ESP8266)
|
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include <espnow.h>
|
|
||||||
#elif defined(ESP32)
|
|
||||||
#include <esp_now.h>
|
|
||||||
#include <WiFi.h>
|
|
||||||
#include <esp_wifi.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_LORA
|
|
||||||
#include <LoRa.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define DBG(a)
|
|
||||||
#ifdef ESP8266
|
|
||||||
#define UART_IF Serial
|
|
||||||
#else
|
|
||||||
#ifdef DEBUG
|
|
||||||
#define DBG(a) (Serial.println(a))
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const uint16_t espnow_size = 250 / sizeof(DataReading);
|
|
||||||
uint8_t gatewayAddress[] = {MAC_PREFIX, GTWY_MAC};
|
|
||||||
uint8_t gtwyAddress[] = {gatewayAddress[3], gatewayAddress[4], GTWY_MAC};
|
|
||||||
uint8_t LoRaAddress[] = {0x42, 0x00};
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t wait_time = 0;
|
|
||||||
DataReading fdrsData[espnow_size];
|
|
||||||
uint8_t data_count = 0;
|
|
||||||
|
|
||||||
void beginFDRS() {
|
|
||||||
#ifdef DEBUG
|
|
||||||
Serial.begin(115200);
|
|
||||||
#endif
|
|
||||||
DBG("FDRS Sensor ID " + String(READING_ID) + " initializing...");
|
|
||||||
DBG(" Gateway: " + String (GTWY_MAC, HEX));
|
|
||||||
#ifdef POWER_CTRL
|
|
||||||
DBG("Powering up the sensor array!");
|
|
||||||
pinMode(POWER_CTRL, OUTPUT);
|
|
||||||
digitalWrite(POWER_CTRL, 1);
|
|
||||||
#endif
|
|
||||||
// Init ESP-NOW for either ESP8266 or ESP32 and set MAC address
|
|
||||||
#ifdef USE_ESPNOW
|
|
||||||
DBG("Initializing ESP-NOW!");
|
|
||||||
WiFi.mode(WIFI_STA);
|
|
||||||
WiFi.disconnect();
|
|
||||||
#if defined(ESP8266)
|
|
||||||
if (esp_now_init() != 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
|
||||||
// Register peers
|
|
||||||
esp_now_add_peer(gatewayAddress, ESP_NOW_ROLE_COMBO, 0, NULL, 0);
|
|
||||||
#elif defined(ESP32)
|
|
||||||
if (esp_now_init() != ESP_OK) {
|
|
||||||
DBG("Error initializing ESP-NOW");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
esp_now_peer_info_t peerInfo;
|
|
||||||
peerInfo.ifidx = WIFI_IF_STA;
|
|
||||||
peerInfo.channel = 0;
|
|
||||||
peerInfo.encrypt = false;
|
|
||||||
// Register first peer
|
|
||||||
memcpy(peerInfo.peer_addr, gatewayAddress, 6);
|
|
||||||
if (esp_now_add_peer(&peerInfo) != ESP_OK) {
|
|
||||||
DBG("Failed to add peer");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
DBG(" ESP-NOW Initialized.");
|
|
||||||
#endif
|
|
||||||
#ifdef USE_LORA
|
|
||||||
DBG("Initializing LoRa!");
|
|
||||||
DBG(BAND);
|
|
||||||
#ifndef __AVR__
|
|
||||||
SPI.begin(SCK, MISO, MOSI, SS);
|
|
||||||
#endif
|
|
||||||
LoRa.setPins(SS, RST, DIO0);
|
|
||||||
if (!LoRa.begin(BAND)) {
|
|
||||||
while (1);
|
|
||||||
}
|
|
||||||
DBG(" LoRa Initialized.");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
void transmitLoRa(uint8_t* mac, DataReading * packet, uint8_t len) {
|
|
||||||
#ifdef USE_LORA
|
|
||||||
uint8_t pkt[5 + (len * sizeof(DataReading))];
|
|
||||||
memcpy(&pkt, mac, 3);
|
|
||||||
memcpy(&pkt[3], &LoRaAddress, 2);
|
|
||||||
memcpy(&pkt[5], packet, len * sizeof(DataReading));
|
|
||||||
LoRa.beginPacket();
|
|
||||||
LoRa.write((uint8_t*)&pkt, sizeof(pkt));
|
|
||||||
LoRa.endPacket();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
void sendFDRS() {
|
|
||||||
DBG("Sending FDRS Packet!");
|
|
||||||
#ifdef USE_ESPNOW
|
|
||||||
esp_now_send(gatewayAddress, (uint8_t *) &fdrsData, data_count * sizeof(DataReading));
|
|
||||||
delay(5);
|
|
||||||
DBG(" ESP-NOW sent.");
|
|
||||||
#endif
|
|
||||||
#ifdef USE_LORA
|
|
||||||
transmitLoRa(gtwyAddress, fdrsData, data_count);
|
|
||||||
DBG(" LoRa sent.");
|
|
||||||
#endif
|
|
||||||
data_count = 0;
|
|
||||||
}
|
|
||||||
void loadFDRS(float d, uint8_t t) {
|
|
||||||
DBG("Data loaded. Type: " + String(t));
|
|
||||||
if (data_count > espnow_size) sendFDRS();
|
|
||||||
DataReading dr;
|
|
||||||
dr.id = READING_ID;
|
|
||||||
dr.t = t;
|
|
||||||
dr.d = d;
|
|
||||||
fdrsData[data_count] = dr;
|
|
||||||
data_count++;
|
|
||||||
}
|
|
||||||
void sleepFDRS(int sleep_time) {
|
|
||||||
DBG("Sleepytime!");
|
|
||||||
#ifdef DEEP_SLEEP
|
|
||||||
DBG(" Deep sleeping.");
|
|
||||||
#ifdef ESP32
|
|
||||||
esp_sleep_enable_timer_wakeup(sleep_time * 1000000);
|
|
||||||
esp_deep_sleep_start();
|
|
||||||
#endif
|
|
||||||
#ifdef ESP8266
|
|
||||||
ESP.deepSleep(sleep_time * 1000000);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
DBG(" Delaying.");
|
|
||||||
delay(sleep_time * 1000);
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
// FARM DATA RELAY SYSTEM
|
|
||||||
//
|
|
||||||
// GATEWAY 2.000 Configuration
|
|
||||||
|
|
||||||
#include "defaults.h"
|
|
||||||
|
|
||||||
#define UNIT_MAC 0x00 // The address of this gateway
|
|
||||||
|
|
||||||
//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).
|
|
||||||
|
|
||||||
#define ESPNOWG_ACT sendSerial();
|
|
||||||
#define SERIAL_ACT
|
|
||||||
#define MQTT_ACT
|
|
||||||
#define LORAG_ACT sendSerial();
|
|
||||||
|
|
||||||
#define USE_LORA
|
|
||||||
//#define USE_WIFI //Used only for MQTT gateway
|
|
||||||
|
|
||||||
#define CREDENTIALS
|
|
||||||
|
|
||||||
#if defined (ESP32)
|
|
||||||
#define RXD2 14
|
|
||||||
#define TXD2 15
|
|
||||||
#define UART_IF Serial2
|
|
||||||
#else
|
|
||||||
#define UART_IF Serial
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//LoRa Configuration -- Needed only if this device is using LoRa
|
|
||||||
#define SCK 5
|
|
||||||
#define MISO 19
|
|
||||||
#define MOSI 27
|
|
||||||
#define SS 18
|
|
||||||
#define RST 14
|
|
||||||
#define DIO0 26
|
|
||||||
|
|
||||||
//WiFi Configuration -- Needed only if is using MQTT
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef CREDENTIALS
|
|
||||||
#include <credentials.h>
|
|
||||||
#define WIFI_NET mySSID
|
|
||||||
#define WIFI_PASS myPASSWORD
|
|
||||||
#define MQTT_ADDR MQTT_BROKER
|
|
||||||
#define BAND myBAND
|
|
||||||
#else
|
|
||||||
#define WIFI_NET "Your SSID"
|
|
||||||
#define WIFI_PASS "Password"
|
|
||||||
#define MQTT_ADDR "192.168.0.8"
|
|
||||||
|
|
||||||
//433E6 for Asia
|
|
||||||
//866E6 for Europe
|
|
||||||
//915E6 for North America
|
|
||||||
#define BAND 915E6
|
|
||||||
#endif
|
|
@ -6,6 +6,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#define DEBUG
|
#define DEBUG
|
||||||
|
#define CREDENTIALS
|
||||||
|
|
||||||
#define ROLE MQTT_GATEWAY
|
#define ROLE MQTT_GATEWAY
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
Please copy the "FDRS_common_files" directory to your Arduino library directory
|
Please copy the "FDRS_common_files" directory to your Arduino library directory
|
||||||
add a file "FDRScredentials.h" to this directory with this content:
|
add a file "FDRScredentials.h" to this directory with this content:
|
||||||
|
|
||||||
#define mySSID ""
|
#define my_SSID ""
|
||||||
#define myPASSWORD ""
|
#define my_PASSWORD ""
|
||||||
#define myMQTT_BROKER "192.168.0.203"
|
#define my_MQTT_BROKER "192.168.0.203"
|
||||||
|
|
||||||
#define myBAND 433.2E6
|
#define my_BAND 433.2E6
|
||||||
#define mySF 7
|
#define my_SF 7
|
||||||
|
|
||||||
Fill in your stuff and save it
|
Fill in your stuff and save it
|
@ -44,11 +44,11 @@
|
|||||||
|
|
||||||
#ifdef CREDENTIALS
|
#ifdef CREDENTIALS
|
||||||
#include <FDRScredentials.h>
|
#include <FDRScredentials.h>
|
||||||
#define WIFI_NET mySSID // ssid of your accesspoint
|
#define WIFI_NET my_SSID // ssid of your accesspoint
|
||||||
#define WIFI_PASS myPASSWORD // password of access point
|
#define WIFI_PASS my_PASSWORD // password of access point
|
||||||
#define MQTT_ADDR myMQTT_BROKER
|
#define MQTT_ADDR my_MQTT_BROKER
|
||||||
#define BAND myBAND
|
#define BAND my_BAND
|
||||||
#define SF mySF
|
#define SF my_SF
|
||||||
#else
|
#else
|
||||||
#define WIFI_NET "Your SSID"
|
#define WIFI_NET "Your SSID"
|
||||||
#define WIFI_PASS "Password"
|
#define WIFI_PASS "Password"
|
||||||
|
Loading…
Reference in New Issue
Block a user