mirror of
https://github.com/timmbogner/Farm-Data-Relay-System
synced 2024-11-10 07:10:42 +00:00
Merge pull request #7 from SensorsIot/main
Debug and other enhancements
This commit is contained in:
commit
ff5bde2098
@ -5,6 +5,9 @@
|
||||
// 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 ROLE LORA_SENSOR
|
||||
|
||||
#include "fdrs_sensor.h"
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
#define DEEP_SLEEP
|
||||
//#define POWER_CTRL 14
|
||||
#define DEBUG
|
||||
#define CREDENTIALS
|
||||
#define CREDENTIALS
|
||||
#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE
|
||||
|
||||
//LoRa Configuration
|
||||
@ -22,13 +22,23 @@
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DIO0 26
|
||||
//433E6 for Asia
|
||||
//866E6 for Europe
|
||||
//915E6 for North America
|
||||
#define BAND 915E6 //May be overwritten if CREDENTIALS is set
|
||||
|
||||
|
||||
#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 {
|
||||
@ -97,7 +107,7 @@ void beginFDRS() {
|
||||
#ifdef DEBUG
|
||||
Serial.begin(115200);
|
||||
#endif
|
||||
DBG("FDRS Sensor ID " + String(READING_ID)+ " initializing...");
|
||||
DBG("FDRS Sensor ID " + String(READING_ID) + " initializing...");
|
||||
DBG(" Gateway: " + String (GTWY_MAC, HEX));
|
||||
#ifdef POWER_CTRL
|
||||
DBG("Powering up the sensor array!");
|
||||
@ -136,6 +146,7 @@ void beginFDRS() {
|
||||
#endif
|
||||
#ifdef USE_LORA
|
||||
DBG("Initializing LoRa!");
|
||||
DBG(BAND);
|
||||
#ifndef __AVR__
|
||||
SPI.begin(SCK, MISO, MOSI, SS);
|
||||
#endif
|
||||
@ -181,9 +192,9 @@ void loadFDRS(float d, uint8_t t) {
|
||||
data_count++;
|
||||
}
|
||||
void sleepFDRS(int sleep_time) {
|
||||
DBG("Sleepytime!");
|
||||
DBG("Sleepytime!");
|
||||
#ifdef DEEP_SLEEP
|
||||
DBG(" Deep sleeping.");
|
||||
DBG(" Deep sleeping.");
|
||||
#ifdef ESP32
|
||||
esp_sleep_enable_timer_wakeup(sleep_time * 1000000);
|
||||
esp_deep_sleep_start();
|
||||
@ -192,6 +203,6 @@ DBG(" Deep sleeping.");
|
||||
ESP.deepSleep(sleep_time * 1000000);
|
||||
#endif
|
||||
#endif
|
||||
DBG(" Delaying.");
|
||||
DBG(" Delaying.");
|
||||
delay(sleep_time * 1000);
|
||||
}
|
||||
|
@ -6,17 +6,31 @@
|
||||
// An example of how to send data using "fdrs_sensor.h".
|
||||
//
|
||||
|
||||
#define DEBUG
|
||||
|
||||
#define ESPNOW_SENSOR
|
||||
|
||||
#include "fdrs_sensor.h"
|
||||
|
||||
float data1 = 42.069;
|
||||
float data2 = 21.0345;
|
||||
float data1;
|
||||
float data2;
|
||||
|
||||
void setup() {
|
||||
beginFDRS();
|
||||
}
|
||||
void loop() {
|
||||
data1=readHum();
|
||||
loadFDRS(data1, HUMIDITY_T);
|
||||
data2=readTemp();
|
||||
loadFDRS(data2, TEMP_T);
|
||||
sendFDRS();
|
||||
sleepFDRS(10); //Sleep time in seconds
|
||||
}
|
||||
|
||||
float readTemp(){
|
||||
return 42.069;
|
||||
}
|
||||
|
||||
float readHum(){
|
||||
return 21.0345;
|
||||
}
|
||||
|
@ -11,8 +11,7 @@
|
||||
//#define USE_LORA
|
||||
#define DEEP_SLEEP
|
||||
//#define POWER_CTRL 14
|
||||
#define DEBUG
|
||||
//#define CREDENTIALS
|
||||
#define DEBUG
|
||||
#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE
|
||||
|
||||
//LoRa Configuration
|
||||
@ -22,13 +21,22 @@
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DIO0 26
|
||||
//433E6 for Asia
|
||||
//866E6 for Europe
|
||||
//915E6 for North America
|
||||
#define BAND 915E6 //May be overwritten if CREDENTIALS is set
|
||||
|
||||
#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 {
|
||||
@ -74,13 +82,10 @@ typedef struct __attribute__((packed)) DataReading {
|
||||
#include <LoRa.h>
|
||||
#endif
|
||||
|
||||
#define DBG(a)
|
||||
#ifdef ESP8266
|
||||
#define UART_IF Serial
|
||||
#else
|
||||
#ifdef DEBUG
|
||||
#define DBG(a) (Serial.println(a))
|
||||
#endif
|
||||
#else
|
||||
#define DBG(a)
|
||||
#endif
|
||||
|
||||
const uint16_t espnow_size = 250 / sizeof(DataReading);
|
||||
|
@ -4,6 +4,11 @@
|
||||
//
|
||||
// Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
//
|
||||
|
||||
#define DEBUG
|
||||
|
||||
#define ROLE ESPNOW_GATEWAY
|
||||
|
||||
#include "fdrs_config.h"
|
||||
#include "DataReading.h"
|
||||
#ifdef ESP8266
|
||||
|
@ -36,10 +36,6 @@
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DIO0 26
|
||||
//433E6 for Asia
|
||||
//866E6 for Europe
|
||||
//915E6 for North America
|
||||
#define BAND 915E6
|
||||
|
||||
//#define USE_LED
|
||||
#define LED_PIN 32
|
||||
|
@ -19,16 +19,13 @@
|
||||
|
||||
#define CREDENTIALS
|
||||
|
||||
//ESP32 Only -- Define UART pins and interface.
|
||||
#if defined (ESP32)
|
||||
#define RXD2 14
|
||||
#define TXD2 15
|
||||
#define UART_IF Serial1
|
||||
#define DEBUG
|
||||
|
||||
//WiFi Configuration -- Needed only if this device is using MQTT
|
||||
#define WIFI_NET "Your SSID"
|
||||
#define WIFI_PASS "Password"
|
||||
#define MQTT_ADDR "192.168.0.8"
|
||||
#define UART_IF Serial2
|
||||
#else
|
||||
#define UART_IF Serial
|
||||
#endif
|
||||
|
||||
////LoRa Configuration -- Needed only if using LoRa
|
||||
#define SCK 5
|
||||
@ -37,11 +34,20 @@
|
||||
#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
|
||||
|
||||
#ifdef CREDENTIALS
|
||||
#include <credentials.h>
|
||||
#endif
|
||||
|
@ -1,15 +1,13 @@
|
||||
#define DBG(a)
|
||||
#ifdef ESP8266
|
||||
#define UART_IF Serial
|
||||
#else
|
||||
#ifdef DEBUG
|
||||
#define DBG(a) (Serial.println(a))
|
||||
#else
|
||||
#define DBG(a)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
const uint8_t espnow_size = 250 / sizeof(DataReading);
|
||||
const uint8_t lora_size = 256 / sizeof(DataReading);
|
||||
const uint8_t mac_prefix[] = {MAC_PREFIX};
|
||||
esp_now_peer_info_t peerInfo;
|
||||
// esp_now_peer_info_t peerInfo;
|
||||
|
||||
uint8_t broadcast_mac[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||
uint8_t selfAddress[] = {MAC_PREFIX, UNIT_MAC};
|
||||
@ -496,5 +494,4 @@ void begin_espnow() {
|
||||
|
||||
#endif
|
||||
DBG(" ESP-NOW Initialized.");
|
||||
DBG(WIFI_NET);
|
||||
}
|
||||
|
@ -4,6 +4,9 @@
|
||||
//
|
||||
// Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
//
|
||||
#define DEBUG
|
||||
|
||||
#define ROLE UART_GATEWAY
|
||||
#include "fdrs_config.h"
|
||||
#include "DataReading.h"
|
||||
#ifdef ESP8266
|
||||
@ -51,6 +54,7 @@ void setup() {
|
||||
client.setServer(mqtt_server, 1883);
|
||||
if (!client.connected()) {
|
||||
DBG("Connecting mqtt...");
|
||||
DBG(mqtt_server);
|
||||
reconnect();
|
||||
}
|
||||
client.setCallback(mqtt_callback);
|
||||
@ -59,6 +63,7 @@ void setup() {
|
||||
#endif
|
||||
#ifdef USE_LORA
|
||||
DBG("Initializing LoRa!");
|
||||
DBG(BAND);
|
||||
SPI.begin(SCK, MISO, MOSI, SS);
|
||||
LoRa.setPins(SS, RST, DIO0);
|
||||
if (!LoRa.begin(BAND)) {
|
||||
|
@ -25,10 +25,6 @@
|
||||
//#define RXD2 21
|
||||
//#define TXD2 22
|
||||
|
||||
#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
|
||||
@ -36,14 +32,9 @@
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DIO0 26
|
||||
//433E6 for Asia
|
||||
//866E6 for Europe
|
||||
//915E6 for North America
|
||||
#define BAND 915E6
|
||||
|
||||
//#define USE_LED
|
||||
#define LED_PIN 32
|
||||
#define NUM_LEDS 4
|
||||
|
||||
#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE
|
||||
#define UART_IF Serial1
|
||||
|
@ -19,11 +19,13 @@
|
||||
|
||||
#define CREDENTIALS
|
||||
|
||||
//ESP32 Only -- Define UART pins and interface
|
||||
#if defined (ESP32)
|
||||
#define RXD2 14
|
||||
#define TXD2 15
|
||||
#define UART_IF Serial1
|
||||
#define DEBUG
|
||||
#define UART_IF Serial2
|
||||
#else
|
||||
#define UART_IF Serial
|
||||
#endif
|
||||
|
||||
//LoRa Configuration -- Needed only if this device is using LoRa
|
||||
#define SCK 5
|
||||
@ -32,16 +34,23 @@
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DIO0 26
|
||||
//433E6 for Asia
|
||||
//866E6 for Europe
|
||||
//915E6 for North America
|
||||
#define BAND 915E6
|
||||
|
||||
//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"
|
||||
|
||||
#ifdef CREDENTIALS
|
||||
#include <credentials.h>
|
||||
//433E6 for Asia
|
||||
//866E6 for Europe
|
||||
//915E6 for North America
|
||||
#define BAND 915E6
|
||||
#endif
|
||||
|
@ -1,10 +1,7 @@
|
||||
#define DBG(a)
|
||||
#ifdef ESP8266
|
||||
#define UART_IF Serial
|
||||
#else
|
||||
#ifdef DEBUG
|
||||
#define DBG(a) (Serial.println(a))
|
||||
#endif
|
||||
#else
|
||||
#define DBG(a)
|
||||
#endif
|
||||
const uint8_t espnow_size = 250 / sizeof(DataReading);
|
||||
const uint8_t lora_size = 256 / sizeof(DataReading);
|
||||
|
@ -4,8 +4,14 @@
|
||||
//
|
||||
// Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
//
|
||||
|
||||
#define DEBUG
|
||||
|
||||
#define ROLE MQTT_GATEWAY
|
||||
|
||||
#include "fdrs_config.h"
|
||||
#include "DataReading.h"
|
||||
|
||||
#ifdef ESP8266
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
@ -29,12 +35,11 @@
|
||||
|
||||
void setup() {
|
||||
#if defined(ESP8266)
|
||||
UART_IF.begin(115200);
|
||||
Serial.begin(115200);
|
||||
#elif defined(ESP32)
|
||||
Serial.begin(115200);
|
||||
UART_IF.begin(115200, SERIAL_8N1, RXD2, TXD2);
|
||||
#endif
|
||||
DBG("Initializing FDRS Gateway");
|
||||
DBG("Address:" + String (UNIT_MAC, HEX));
|
||||
#ifdef USE_LED
|
||||
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
|
||||
@ -48,11 +53,13 @@ void setup() {
|
||||
DBG("Connecting to Wifi...");
|
||||
delay(500);
|
||||
}
|
||||
DBG("WiFi Connected");
|
||||
client.setServer(mqtt_server, 1883);
|
||||
if (!client.connected()) {
|
||||
DBG("Connecting mqtt...");
|
||||
reconnect();
|
||||
}
|
||||
DBG("MQTT Connected");
|
||||
client.setCallback(mqtt_callback);
|
||||
#else
|
||||
begin_espnow();
|
||||
@ -68,6 +75,8 @@ void setup() {
|
||||
#endif
|
||||
// UART_IF.println(sizeof(DataReading));
|
||||
|
||||
client.publish("esp/fdrs/status", "FDRS initialized");
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
@ -22,13 +22,6 @@
|
||||
#define LORA1_ACT
|
||||
#define LORA2_ACT
|
||||
|
||||
//#define RXD2 21
|
||||
//#define TXD2 22
|
||||
|
||||
#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
|
||||
@ -46,4 +39,3 @@
|
||||
#define NUM_LEDS 4
|
||||
|
||||
#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE
|
||||
#define UART_IF Serial1
|
||||
|
@ -19,16 +19,13 @@
|
||||
|
||||
#define CREDENTIALS
|
||||
|
||||
//ESP32 Only -- Define UART pins and interface.
|
||||
#if defined (ESP32)
|
||||
#define RXD2 14
|
||||
#define TXD2 15
|
||||
#define UART_IF Serial1
|
||||
#define DEBUG
|
||||
|
||||
//WiFi Configuration -- Needed only if this device is using MQTT
|
||||
#define WIFI_NET "Your SSID"
|
||||
#define WIFI_PASS "Password"
|
||||
#define MQTT_ADDR "192.168.0.8"
|
||||
#else
|
||||
#define UART_IF Serial
|
||||
#endif
|
||||
|
||||
////LoRa Configuration -- Needed only if using LoRa
|
||||
#define SCK 5
|
||||
@ -37,11 +34,21 @@
|
||||
#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
|
||||
|
||||
#ifdef CREDENTIALS
|
||||
#include <credentials.h>
|
||||
#endif
|
||||
|
@ -1,15 +1,12 @@
|
||||
#define DBG(a)
|
||||
#ifdef ESP8266
|
||||
#define UART_IF Serial
|
||||
#else
|
||||
#ifdef DEBUG
|
||||
#define DBG(a) (Serial.println(a))
|
||||
#endif
|
||||
#else
|
||||
#define DBG(a)
|
||||
#endif
|
||||
const uint8_t espnow_size = 250 / sizeof(DataReading);
|
||||
const uint8_t lora_size = 256 / sizeof(DataReading);
|
||||
const uint8_t mac_prefix[] = {MAC_PREFIX};
|
||||
esp_now_peer_info_t peerInfo;
|
||||
// esp_now_peer_info_t peerInfo;
|
||||
|
||||
uint8_t broadcast_mac[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||
uint8_t selfAddress[] = {MAC_PREFIX, UNIT_MAC};
|
||||
@ -102,6 +99,7 @@ void getSerial() {
|
||||
}
|
||||
void mqtt_callback(char* topic, byte * message, unsigned int length) {
|
||||
String incomingString;
|
||||
DBG(topic);
|
||||
for (int i = 0; i < length; i++) {
|
||||
incomingString += (char)message[i];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user