mirror of
https://github.com/timmbogner/Farm-Data-Relay-System
synced 2024-11-10 07:10:42 +00:00
Updated gateway .ino
This commit is contained in:
parent
05bc51ae6c
commit
a8e94156dd
@ -30,7 +30,8 @@
|
|||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <SD.h>
|
#include <SD.h>
|
||||||
#endif
|
#endif
|
||||||
#include "fdrs_functions.h"
|
//#include <fdrs_functions.h> //Use global functions file
|
||||||
|
#include "fdrs_functions.h" //Use local functions file
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#ifdef USE_WIFI
|
#ifdef USE_WIFI
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
|
#include <WiFiUdp.h>
|
||||||
|
#include <NTPClient.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_LORA
|
#ifdef USE_LORA
|
||||||
#include <LoRa.h>
|
#include <LoRa.h>
|
||||||
@ -24,7 +26,12 @@
|
|||||||
#ifdef USE_LED
|
#ifdef USE_LED
|
||||||
#include <FastLED.h>
|
#include <FastLED.h>
|
||||||
#endif
|
#endif
|
||||||
#include <fdrs_functions.h>
|
#ifdef USE_SD_LOG
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <SD.h>
|
||||||
|
#endif
|
||||||
|
#include <fdrs_functions.h> //Use global functions file
|
||||||
|
//#include "fdrs_functions.h" //Use local functions file
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
@ -51,25 +58,17 @@ void setup() {
|
|||||||
DBG("WiFi Connected");
|
DBG("WiFi Connected");
|
||||||
client.setServer(mqtt_server, mqtt_port);
|
client.setServer(mqtt_server, mqtt_port);
|
||||||
if (!client.connected()) {
|
if (!client.connected()) {
|
||||||
DBG("Connecting MQTT...");
|
reconnect(5);
|
||||||
reconnect();
|
|
||||||
}
|
}
|
||||||
DBG("MQTT Connected");
|
|
||||||
client.setCallback(mqtt_callback);
|
client.setCallback(mqtt_callback);
|
||||||
#else
|
#else
|
||||||
begin_espnow();
|
begin_espnow();
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_LORA
|
#ifdef USE_LORA
|
||||||
DBG("Initializing LoRa!");
|
begin_lora();
|
||||||
#ifdef ESP32
|
|
||||||
SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
|
|
||||||
#endif
|
#endif
|
||||||
LoRa.setPins(LORA_SS, LORA_RST, LORA_DIO0);
|
#ifdef USE_SD_LOG
|
||||||
if (!LoRa.begin(FDRS_BAND)) {
|
begin_SD();
|
||||||
while (1);
|
|
||||||
}
|
|
||||||
LoRa.setSpreadingFactor(FDRS_SF);
|
|
||||||
DBG(" LoRa initialized.");
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//DBG(sizeof(DataReading));
|
//DBG(sizeof(DataReading));
|
||||||
@ -132,12 +131,20 @@ void loop() {
|
|||||||
getSerial();
|
getSerial();
|
||||||
}
|
}
|
||||||
getLoRa();
|
getLoRa();
|
||||||
#ifdef USE_WIFI
|
#ifdef USE_WIFI
|
||||||
if (!client.connected()) {
|
if (!client.connected()) {
|
||||||
DBG("Connecting MQTT...");
|
reconnect(1, true);
|
||||||
reconnect();
|
|
||||||
}
|
}
|
||||||
client.loop();
|
client.loop(); // for recieving incoming messages and maintaining connection
|
||||||
|
|
||||||
|
timeClient.update(); //update internal clock if possible
|
||||||
|
#endif
|
||||||
|
#ifdef USE_SD_LOG
|
||||||
|
unsigned long current_millis = millis();
|
||||||
|
if(current_millis-last_millis >= 1000){
|
||||||
|
seconds_since_reset+=(current_millis-last_millis)/1000;
|
||||||
|
last_millis=current_millis;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if (newData) {
|
if (newData) {
|
||||||
switch (newData) {
|
switch (newData) {
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#ifdef USE_WIFI
|
#ifdef USE_WIFI
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
|
#include <WiFiUdp.h>
|
||||||
|
#include <NTPClient.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_LORA
|
#ifdef USE_LORA
|
||||||
#include <LoRa.h>
|
#include <LoRa.h>
|
||||||
@ -24,7 +26,12 @@
|
|||||||
#ifdef USE_LED
|
#ifdef USE_LED
|
||||||
#include <FastLED.h>
|
#include <FastLED.h>
|
||||||
#endif
|
#endif
|
||||||
#include <fdrs_functions.h>
|
#ifdef USE_SD_LOG
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <SD.h>
|
||||||
|
#endif
|
||||||
|
#include <fdrs_functions.h> //Use global functions file
|
||||||
|
//#include "fdrs_functions.h" //Use local functions file
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
@ -51,25 +58,17 @@ void setup() {
|
|||||||
DBG("WiFi Connected");
|
DBG("WiFi Connected");
|
||||||
client.setServer(mqtt_server, mqtt_port);
|
client.setServer(mqtt_server, mqtt_port);
|
||||||
if (!client.connected()) {
|
if (!client.connected()) {
|
||||||
DBG("Connecting MQTT...");
|
reconnect(5);
|
||||||
reconnect();
|
|
||||||
}
|
}
|
||||||
DBG("MQTT Connected");
|
|
||||||
client.setCallback(mqtt_callback);
|
client.setCallback(mqtt_callback);
|
||||||
#else
|
#else
|
||||||
begin_espnow();
|
begin_espnow();
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_LORA
|
#ifdef USE_LORA
|
||||||
DBG("Initializing LoRa!");
|
begin_lora();
|
||||||
#ifdef ESP32
|
|
||||||
SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
|
|
||||||
#endif
|
#endif
|
||||||
LoRa.setPins(LORA_SS, LORA_RST, LORA_DIO0);
|
#ifdef USE_SD_LOG
|
||||||
if (!LoRa.begin(FDRS_BAND)) {
|
begin_SD();
|
||||||
while (1);
|
|
||||||
}
|
|
||||||
LoRa.setSpreadingFactor(FDRS_SF);
|
|
||||||
DBG(" LoRa initialized.");
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//DBG(sizeof(DataReading));
|
//DBG(sizeof(DataReading));
|
||||||
@ -132,12 +131,20 @@ void loop() {
|
|||||||
getSerial();
|
getSerial();
|
||||||
}
|
}
|
||||||
getLoRa();
|
getLoRa();
|
||||||
#ifdef USE_WIFI
|
#ifdef USE_WIFI
|
||||||
if (!client.connected()) {
|
if (!client.connected()) {
|
||||||
DBG("Connecting MQTT...");
|
reconnect(1, true);
|
||||||
reconnect();
|
|
||||||
}
|
}
|
||||||
client.loop();
|
client.loop(); // for recieving incoming messages and maintaining connection
|
||||||
|
|
||||||
|
timeClient.update(); //update internal clock if possible
|
||||||
|
#endif
|
||||||
|
#ifdef USE_SD_LOG
|
||||||
|
unsigned long current_millis = millis();
|
||||||
|
if(current_millis-last_millis >= 1000){
|
||||||
|
seconds_since_reset+=(current_millis-last_millis)/1000;
|
||||||
|
last_millis=current_millis;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if (newData) {
|
if (newData) {
|
||||||
switch (newData) {
|
switch (newData) {
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#ifdef USE_WIFI
|
#ifdef USE_WIFI
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
|
#include <WiFiUdp.h>
|
||||||
|
#include <NTPClient.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_LORA
|
#ifdef USE_LORA
|
||||||
#include <LoRa.h>
|
#include <LoRa.h>
|
||||||
@ -24,7 +26,12 @@
|
|||||||
#ifdef USE_LED
|
#ifdef USE_LED
|
||||||
#include <FastLED.h>
|
#include <FastLED.h>
|
||||||
#endif
|
#endif
|
||||||
#include <fdrs_functions.h>
|
#ifdef USE_SD_LOG
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <SD.h>
|
||||||
|
#endif
|
||||||
|
#include <fdrs_functions.h> //Use global functions file
|
||||||
|
//#include "fdrs_functions.h" //Use local functions file
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
@ -51,25 +58,17 @@ void setup() {
|
|||||||
DBG("WiFi Connected");
|
DBG("WiFi Connected");
|
||||||
client.setServer(mqtt_server, mqtt_port);
|
client.setServer(mqtt_server, mqtt_port);
|
||||||
if (!client.connected()) {
|
if (!client.connected()) {
|
||||||
DBG("Connecting MQTT...");
|
reconnect(5);
|
||||||
reconnect();
|
|
||||||
}
|
}
|
||||||
DBG("MQTT Connected");
|
|
||||||
client.setCallback(mqtt_callback);
|
client.setCallback(mqtt_callback);
|
||||||
#else
|
#else
|
||||||
begin_espnow();
|
begin_espnow();
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_LORA
|
#ifdef USE_LORA
|
||||||
DBG("Initializing LoRa!");
|
begin_lora();
|
||||||
#ifdef ESP32
|
|
||||||
SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
|
|
||||||
#endif
|
#endif
|
||||||
LoRa.setPins(LORA_SS, LORA_RST, LORA_DIO0);
|
#ifdef USE_SD_LOG
|
||||||
if (!LoRa.begin(FDRS_BAND)) {
|
begin_SD();
|
||||||
while (1);
|
|
||||||
}
|
|
||||||
LoRa.setSpreadingFactor(FDRS_SF);
|
|
||||||
DBG(" LoRa initialized.");
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//DBG(sizeof(DataReading));
|
//DBG(sizeof(DataReading));
|
||||||
@ -132,12 +131,20 @@ void loop() {
|
|||||||
getSerial();
|
getSerial();
|
||||||
}
|
}
|
||||||
getLoRa();
|
getLoRa();
|
||||||
#ifdef USE_WIFI
|
#ifdef USE_WIFI
|
||||||
if (!client.connected()) {
|
if (!client.connected()) {
|
||||||
DBG("Connecting MQTT...");
|
reconnect(1, true);
|
||||||
reconnect();
|
|
||||||
}
|
}
|
||||||
client.loop();
|
client.loop(); // for recieving incoming messages and maintaining connection
|
||||||
|
|
||||||
|
timeClient.update(); //update internal clock if possible
|
||||||
|
#endif
|
||||||
|
#ifdef USE_SD_LOG
|
||||||
|
unsigned long current_millis = millis();
|
||||||
|
if(current_millis-last_millis >= 1000){
|
||||||
|
seconds_since_reset+=(current_millis-last_millis)/1000;
|
||||||
|
last_millis=current_millis;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if (newData) {
|
if (newData) {
|
||||||
switch (newData) {
|
switch (newData) {
|
||||||
|
Loading…
Reference in New Issue
Block a user