tubbleschruting

This commit is contained in:
Timm Bogner 2022-05-25 19:11:38 -05:00
parent fcb6f45c49
commit 39d9f1ba6a
7 changed files with 101 additions and 65 deletions

View File

@ -5,10 +5,8 @@
// 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".
//
#define DEBUG
#define CREDENTIALS
#include <FDRSdefaults.h>
#include "fdrs_sensor.h"
float data1;
@ -27,7 +25,8 @@ void loop() {
}
float readTemp() {
return 42.069;
// return 42.069;
return 42.5;
}
float readHum() {

View File

@ -4,7 +4,7 @@
//
// 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)
#include <ESP8266WiFi.h>
#include <espnow.h>
@ -13,11 +13,47 @@
#include <WiFi.h>
#include <esp_wifi.h>
#endif
#ifdef USE_LORA
#include <LoRa.h>
#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 {
float d;
uint16_t id;
@ -28,7 +64,7 @@ typedef struct __attribute__((packed)) DataReading {
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];
@ -78,15 +114,15 @@ void beginFDRS() {
#ifdef USE_LORA
DBG("Initializing LoRa!");
DBG(BAND);
DBG(SF);
DBG(SF);
#ifndef __AVR__
SPI.begin(SCK, MISO, MOSI, SS);
#endif
LoRa.setPins(SS, RST, DIO0);
if (!LoRa.begin(BAND)) {
if (!LoRa.begin(FDRS_BAND)) {
while (1);
}
LoRa.setSpreadingFactor(SF);
LoRa.setSpreadingFactor(FDRS_SF);
DBG(" LoRa Initialized.");
#endif
}

View File

@ -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

View File

@ -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

View File

@ -5,11 +5,7 @@
// Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
//
#define DEBUG
#define CREDENTIALS
#include "fdrs_config.h"
#ifdef ESP8266
#include <ESP8266WiFi.h>
#include <espnow.h>
@ -75,8 +71,9 @@ void setup() {
#endif
//DBG(sizeof(DataReading));
#ifdef USE_WIFI
client.publish(TOPIC_STATUS, "FDRS initialized");
#endif
}
void loop() {

View File

@ -10,23 +10,17 @@
//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
#define SERIAL_ACT sendMQTT();
#define ESPNOWG_ACT sendSerial();
#define SERIAL_ACT //sendMQTT();
#define MQTT_ACT
#define LORAG_ACT
#define LORAG_ACT sendSerial();
#define USE_LORA
#define USE_WIFI //Used only for MQTT gateway
//#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 Actions
#define ESPNOW1_ACT
#define ESPNOW2_ACT
#define LORA1_ACT
#define LORA2_ACT
#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
@ -34,23 +28,11 @@
#define LORA1_PEER 0x04 // LoRa1 Address
#define LORA2_PEER 0x05 // LoRa2 Address
// 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_LORA
#define SCK 5
#define MISO 19
#define MOSI 27
#define SS 18
#define RST 14
#define DIO0 26
// Peer Actions
#define ESPNOW1_ACT
#define ESPNOW2_ACT
#define LORA1_ACT
#define LORA2_ACT
//Pins for UART data interface (ESP32 only)
#define RXD2 14
@ -69,6 +51,15 @@
#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
@ -77,5 +68,3 @@
#define TOPIC_DATA "FDRS/DATA"
#define TOPIC_STATUS "FDRS/STATUS"
#define TOPIC_COMMAND "FDRS/COMMAND"
#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE // Should only be changed if implementing multiple FDRS systems.

View File

@ -3,11 +3,13 @@
#else
#define DBG(a)
#endif
#if defined (ESP32)
#define UART_IF Serial1
#else
#define UART_IF Serial
#endif
#ifdef GLOBALS
#define FDRS_WIFI_SSID GLOBAL_SSID
#define FDRS_WIFI_PASS GLOBAL_PASS
@ -22,6 +24,8 @@
#define FDRS_SF SF
#endif
#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE // Should only be changed if implementing multiple FDRS systems.
typedef struct __attribute__((packed)) DataReading {
float d;
uint16_t id;