tubbleschruting

pull/12/head
Timm Bogner 2 years ago
parent fcb6f45c49
commit 39d9f1ba6a

@ -5,10 +5,8 @@
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA. // Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
// An example of how to send data using "fdrs_sensor.h". // An example of how to send data using "fdrs_sensor.h".
// //
#define DEBUG
#define CREDENTIALS
#include <FDRSdefaults.h>
#include "fdrs_sensor.h" #include "fdrs_sensor.h"
float data1; float data1;
@ -27,7 +25,8 @@ void loop() {
} }
float readTemp() { float readTemp() {
return 42.069; // return 42.069;
return 42.5;
} }
float readHum() { float readHum() {

@ -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_setup.h" #include "sensor_config.h"
#if defined(ESP8266) #if defined(ESP8266)
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <espnow.h> #include <espnow.h>
@ -13,11 +13,47 @@
#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;
@ -28,7 +64,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];
@ -78,22 +114,22 @@ void beginFDRS() {
#ifdef USE_LORA #ifdef USE_LORA
DBG("Initializing LoRa!"); DBG("Initializing LoRa!");
DBG(BAND); DBG(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(BAND)) { if (!LoRa.begin(FDRS_BAND)) {
while (1); while (1);
} }
LoRa.setSpreadingFactor(SF); LoRa.setSpreadingFactor(FDRS_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();

@ -0,0 +1,27 @@
// FARM DATA RELAY SYSTEM
//
// Sensor Configuration
//
#include <fdrs_globals.h> //Uncomment if you install the globals file
#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
//LoRa Configuration
#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 SF 7

@ -1,16 +0,0 @@
#define READING_ID 1 //Unique ID for this sensor
#define GTWY_MAC 0x04 //Address of the nearest gateway
//#define USE_ESPNOW
#define USE_LORA
#define DEEP_SLEEP
//#define POWER_CTRL 14
//LoRa Configuration
#define SCK 5
#define MISO 19
#define MOSI 27
#define SS 18
#define RST 14
#define DIO0 26

@ -5,11 +5,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.
// //
#define DEBUG
#define CREDENTIALS
#include "fdrs_config.h" #include "fdrs_config.h"
#ifdef ESP8266 #ifdef ESP8266
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <espnow.h> #include <espnow.h>
@ -75,8 +71,9 @@ void setup() {
#endif #endif
//DBG(sizeof(DataReading)); //DBG(sizeof(DataReading));
#ifdef USE_WIFI
client.publish(TOPIC_STATUS, "FDRS initialized"); client.publish(TOPIC_STATUS, "FDRS initialized");
#endif
} }
void loop() { void loop() {

@ -10,23 +10,17 @@
//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 #define ESPNOWG_ACT sendSerial();
#define SERIAL_ACT sendMQTT(); #define SERIAL_ACT //sendMQTT();
#define MQTT_ACT #define MQTT_ACT
#define LORAG_ACT #define LORAG_ACT sendSerial();
#define USE_LORA //#define USE_LORA
#define USE_WIFI //Used only for MQTT gateway //#define USE_WIFI //Used only for MQTT gateway
#define WIFI_SSID "Your SSID" #define WIFI_SSID "Your SSID"
#define WIFI_PASS "Your Password" #define WIFI_PASS "Your Password"
#define MQTT_ADDR "192.168.0.8" #define MQTT_ADDR "192.168.0.8"
// Peer Actions
#define ESPNOW1_ACT
#define ESPNOW2_ACT
#define LORA1_ACT
#define LORA2_ACT
// Peer addresses // Peer addresses
#define ESPNOW1_PEER 0x04 // ESPNOW1 Address #define ESPNOW1_PEER 0x04 // ESPNOW1 Address
@ -34,23 +28,11 @@
#define LORA1_PEER 0x04 // LoRa1 Address #define LORA1_PEER 0x04 // LoRa1 Address
#define LORA2_PEER 0x05 // LoRa2 Address #define LORA2_PEER 0x05 // LoRa2 Address
// Buffer Delays - in milliseconds // Peer Actions
//#define ESPNOW1_DELAY 0 #define ESPNOW1_ACT
//#define ESPNOW2_DELAY 0 #define ESPNOW2_ACT
//#define ESPNOWG_DELAY 0 #define LORA1_ACT
//#define SERIAL_DELAY 0 #define LORA2_ACT
//#define MQTT_DELAY 0
//#define LORAG_DELAY 1000
//#define LORA1_DELAY 1000
//#define LORA2_DELAY 1000
//#define USE_LORA
#define SCK 5
#define MISO 19
#define MOSI 27
#define SS 18
#define RST 14
#define DIO0 26
//Pins for UART data interface (ESP32 only) //Pins for UART data interface (ESP32 only)
#define RXD2 14 #define RXD2 14
@ -69,6 +51,15 @@
#define BAND 915E6 #define BAND 915E6
#define SF 7 #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 USE_LED //Not yet fully implemented
#define LED_PIN 32 #define LED_PIN 32
#define NUM_LEDS 4 #define NUM_LEDS 4
@ -77,5 +68,3 @@
#define TOPIC_DATA "FDRS/DATA" #define TOPIC_DATA "FDRS/DATA"
#define TOPIC_STATUS "FDRS/STATUS" #define TOPIC_STATUS "FDRS/STATUS"
#define TOPIC_COMMAND "FDRS/COMMAND" #define TOPIC_COMMAND "FDRS/COMMAND"
#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE // Should only be changed if implementing multiple FDRS systems.

@ -3,11 +3,13 @@
#else #else
#define DBG(a) #define DBG(a)
#endif #endif
#if defined (ESP32) #if defined (ESP32)
#define UART_IF Serial1 #define UART_IF Serial1
#else #else
#define UART_IF Serial #define UART_IF Serial
#endif #endif
#ifdef GLOBALS #ifdef GLOBALS
#define FDRS_WIFI_SSID GLOBAL_SSID #define FDRS_WIFI_SSID GLOBAL_SSID
#define FDRS_WIFI_PASS GLOBAL_PASS #define FDRS_WIFI_PASS GLOBAL_PASS
@ -22,6 +24,8 @@
#define FDRS_SF SF #define FDRS_SF SF
#endif #endif
#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;

Loading…
Cancel
Save