2021-12-06 04:19:39 +00:00
|
|
|
// FARM DATA RELAY SYSTEM
|
|
|
|
//
|
|
|
|
// GATEWAY 2.000
|
2021-12-06 17:36:18 +00:00
|
|
|
// This is still in progress. Stay tuned!
|
2021-12-06 04:19:39 +00:00
|
|
|
//
|
|
|
|
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
2021-12-06 17:36:18 +00:00
|
|
|
//
|
2021-12-06 04:19:39 +00:00
|
|
|
|
|
|
|
#if defined(ESP8266)
|
|
|
|
#include <ESP8266WiFi.h>
|
|
|
|
#include <espnow.h>
|
|
|
|
#elif defined(ESP32)
|
|
|
|
#include <esp_now.h>
|
|
|
|
#include <WiFi.h>
|
|
|
|
#include <esp_wifi.h>
|
|
|
|
#endif
|
|
|
|
#include "fdrs_config.h"
|
|
|
|
#include <ArduinoJson.h>
|
|
|
|
#include "DataReading.h"
|
|
|
|
#include <PubSubClient.h>
|
|
|
|
#include "fdrs_functions.h"
|
|
|
|
|
2021-12-06 17:36:18 +00:00
|
|
|
const char* ssid = WIFI_NET;
|
|
|
|
const char* password = WIFI_PASS;
|
|
|
|
const char* mqtt_server = MQTT_ADDR;
|
2021-12-06 04:19:39 +00:00
|
|
|
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(115200);
|
|
|
|
begin_espnow();
|
|
|
|
#ifdef USE_WIFI
|
|
|
|
delay(10);
|
|
|
|
WiFi.begin(ssid, password);
|
|
|
|
while (WiFi.status() != WL_CONNECTED) {
|
|
|
|
delay(500);
|
|
|
|
}
|
|
|
|
client.setServer(mqtt_server, 1883);
|
|
|
|
client.setCallback(mqtt_callback);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
while (Serial.available()) {
|
|
|
|
getSerial();
|
|
|
|
}
|
|
|
|
if (newData != 0) {
|
|
|
|
|
|
|
|
|
|
|
|
switch (newData) {
|
|
|
|
case 1: //ESP-NOW #1
|
2021-12-06 17:36:18 +00:00
|
|
|
ESPNOW1_ACT
|
2021-12-06 04:19:39 +00:00
|
|
|
break;
|
|
|
|
case 2: //ESP-NOW #2
|
2021-12-06 17:36:18 +00:00
|
|
|
ESPNOW2_ACT
|
2021-12-06 04:19:39 +00:00
|
|
|
break;
|
|
|
|
case 3: //ESP-NOW General
|
2021-12-06 17:36:18 +00:00
|
|
|
ESPNOWG_ACT
|
2021-12-06 04:19:39 +00:00
|
|
|
break;
|
|
|
|
case 4: //Serial
|
2021-12-06 17:36:18 +00:00
|
|
|
SERIAL_ACT
|
2021-12-06 04:19:39 +00:00
|
|
|
break;
|
|
|
|
case 5: //MQTT
|
2021-12-06 17:36:18 +00:00
|
|
|
MQTT_ACT
|
2021-12-06 04:19:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
newData = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef USE_WIFI
|
|
|
|
if (!client.connected()) {
|
|
|
|
reconnect();
|
|
|
|
}
|
|
|
|
client.loop();
|
|
|
|
#endif
|
|
|
|
}
|