├── extras ├── Basic_Setup.png ├── basic-MQTT.png ├── basic-UART.png ├── Advanced_Setup.png ├── Basic_LoRa_Setup.png └── Advanced_Setup_LoRa.png ├── src ├── ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays │ ├── component.mk │ ├── CMakeLists.txt │ ├── resources │ │ ├── FontTool.png │ │ ├── DemoFrame1.jpg │ │ ├── DemoFrame2.jpg │ │ ├── DemoFrame3.jpg │ │ ├── DemoFrame4.jpg │ │ ├── xbmPreview.png │ │ ├── SPI_version.jpg │ │ └── glyphEditor.png │ ├── examples │ │ ├── SSD1306ClockDemo │ │ │ └── images.h │ │ ├── SSD1306SimpleDemo │ │ │ └── images.h │ │ ├── SSD1306TwoScreenDemo │ │ │ ├── images.h │ │ │ └── SSD1306TwoScreenDemo.ino │ │ ├── SSD1306UiDemo │ │ │ └── images.h │ │ ├── SSD1306ScrollVerticalDemo │ │ │ └── SSD1306ScrollVerticalDemo.ino │ │ └── SSD1306OTADemo │ │ │ └── SSD1306OTADemo.ino │ ├── README_GEOMETRY_64_48.md │ ├── library.properties │ ├── platformio.ini │ ├── UPGRADE-4.0.md │ ├── library.json │ ├── license │ ├── src │ │ ├── SH1106.h │ │ ├── SSD1306.h │ │ ├── SH1106Brzo.h │ │ ├── SH1106Spi.h │ │ ├── SSD1306I2C.h │ │ ├── SSD1306Spi.h │ │ └── SSD1306Brzo.h │ ├── keywords.txt │ ├── CONTRIBUTING.md │ └── UPGRADE-3.0.md ├── fdrs_debug.h ├── fdrs_gateway_scheduler.h ├── fdrs_gateway_ota.h ├── fdrs_globals.h ├── fdrs_datatypes.h ├── fdrs_oled.h ├── fdrs_gateway_mqtt.h └── fdrs_node_espnow.h ├── examples ├── 0_MQTT_Gateway │ ├── 0_MQTT_Gateway.ino │ └── fdrs_gateway_config.h ├── 1_UART_Gateway │ ├── 1_UART_Gateway.ino │ └── fdrs_gateway_config.h ├── 3_LoRa_Repeater │ ├── 3_LoRa_Repeater.ino │ └── fdrs_gateway_config.h ├── 2_ESPNOW_Repeater │ ├── 2_ESPNOW_Repeater.ino │ └── fdrs_gateway_config.h ├── ESPNOW_Stress_Test │ ├── ESPNOW_Stress_Test.ino │ └── fdrs_node_config.h ├── Controller_examples │ ├── Single_Channel_Relay │ │ └── Single_Channel_Relay.ino │ ├── LilyGo_TWatch2020 │ │ ├── fdrs_node_config.h │ │ └── LilyGo_TWatch2020.ino │ ├── ControllerTime │ │ └── fdrs_node_config.h │ ├── FastLED │ │ ├── fdrs_node_config.h │ │ └── FastLED.ino │ ├── Irrigation │ │ ├── fdrs_node_config.h │ │ └── Irrigation.ino │ └── TFT_eSPI_fdrs │ │ ├── fdrs_node_config.h │ │ └── TFT_eSPI_fdrs.ino ├── LoRa_Controller │ ├── LoRa_Controller.ino │ └── fdrs_node_config.h ├── ESPNOW_Controller │ ├── ESPNOW_Controller.ino │ └── fdrs_node_config.h ├── Gateway_Examples │ ├── 1_MQTT_Gateway_Ethernet │ │ ├── 1_MQTT_Gateway_Ethernet.ino │ │ └── fdrs_gateway_config.h │ └── Repeater_Voltage │ │ ├── Repeater_Voltage.ino │ │ └── fdrs_gateway_config.h ├── Sensor_Examples │ ├── CapacitiveSoil │ │ ├── CapacitiveSoil.ino │ │ └── fdrs_node_config.h │ ├── DS18B20_fdrs │ │ ├── DS18B20_fdrs.ino │ │ └── fdrs_node_config.h │ ├── SHT20_fdrs │ │ ├── SHT20_fdrs.ino │ │ └── fdrs_node_config.h │ ├── BME280_fdrs │ │ ├── BME280_fdrs.ino │ │ └── fdrs_node_config.h │ ├── BMP280_fdrs │ │ ├── BMP280_fdrs.ino │ │ └── fdrs_node_config.h │ ├── MLX90614_fdrs │ │ ├── MLX90614_fdrs.ino │ │ └── fdrs_node_config.h │ ├── AHT20_fdrs │ │ ├── AHT20_fdrs.ino │ │ └── fdrs_node_config.h │ ├── TippingBucket │ │ ├── TippingBucket.ino │ │ └── fdrs_node_config.h │ ├── MESB_fdrs │ │ ├── MESB_fdrs.ino │ │ └── fdrs_node_config.h │ ├── DHT22_fdrs │ │ ├── DHT22_fdrs.ino │ │ └── fdrs_node_config.h │ ├── README.md │ ├── FrequencyCounter │ │ ├── FrequencyCounter.ino │ │ └── fdrs_node_config.h │ ├── KisssysGypsum │ │ ├── fdrs_node_config.h │ │ └── KisssysGypsum.ino │ ├── LilyGo_HiGrow_32 │ │ ├── fdrs_node_config.h │ │ └── LilyGo_HiGrow_32.ino │ ├── GenericGPS_fdrs │ │ └── fdrs_node_config.h │ └── TSL2561 │ │ ├── fdrs_node_config.h │ │ └── TSL2561.ino ├── LoRa_Sensor │ ├── LoRa_Sensor.ino │ └── fdrs_node_config.h ├── ESPNOW_Sensor │ ├── ESPNOW_Sensor.ino │ └── fdrs_node_config.h └── LoRa_Stress_Test │ ├── fdrs_node_config.h │ └── LoRa_Stress_Test.ino ├── library.properties ├── LICENSE └── keywords.txt /extras/Basic_Setup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timmbogner/Farm-Data-Relay-System/HEAD/extras/Basic_Setup.png -------------------------------------------------------------------------------- /extras/basic-MQTT.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timmbogner/Farm-Data-Relay-System/HEAD/extras/basic-MQTT.png -------------------------------------------------------------------------------- /extras/basic-UART.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timmbogner/Farm-Data-Relay-System/HEAD/extras/basic-UART.png -------------------------------------------------------------------------------- /extras/Advanced_Setup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timmbogner/Farm-Data-Relay-System/HEAD/extras/Advanced_Setup.png -------------------------------------------------------------------------------- /extras/Basic_LoRa_Setup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timmbogner/Farm-Data-Relay-System/HEAD/extras/Basic_LoRa_Setup.png -------------------------------------------------------------------------------- /extras/Advanced_Setup_LoRa.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timmbogner/Farm-Data-Relay-System/HEAD/extras/Advanced_Setup_LoRa.png -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := src 2 | COMPONENT_SRCDIRS := src 3 | CXXFLAGS += -Wno-ignored-qualifiers 4 | -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_ADD_INCLUDEDIRS src) 2 | set(COMPONENT_PRIV_REQUIRES arduino-esp32) 3 | set(COMPONENT_SRCDIRS src) 4 | register_component() 5 | -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/resources/FontTool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timmbogner/Farm-Data-Relay-System/HEAD/src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/resources/FontTool.png -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/resources/DemoFrame1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timmbogner/Farm-Data-Relay-System/HEAD/src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/resources/DemoFrame1.jpg -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/resources/DemoFrame2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timmbogner/Farm-Data-Relay-System/HEAD/src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/resources/DemoFrame2.jpg -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/resources/DemoFrame3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timmbogner/Farm-Data-Relay-System/HEAD/src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/resources/DemoFrame3.jpg -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/resources/DemoFrame4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timmbogner/Farm-Data-Relay-System/HEAD/src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/resources/DemoFrame4.jpg -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/resources/xbmPreview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timmbogner/Farm-Data-Relay-System/HEAD/src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/resources/xbmPreview.png -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/resources/SPI_version.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timmbogner/Farm-Data-Relay-System/HEAD/src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/resources/SPI_version.jpg -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/resources/glyphEditor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timmbogner/Farm-Data-Relay-System/HEAD/src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/resources/glyphEditor.png -------------------------------------------------------------------------------- /examples/0_MQTT_Gateway/0_MQTT_Gateway.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // GATEWAY 2.000 4 | // 5 | // Developed by Timm Bogner (timmbogner@gmail.com) in Urbana, Illinois, USA. 6 | // 7 | 8 | #include "fdrs_gateway_config.h" 9 | #include 10 | 11 | void setup() { 12 | beginFDRS(); 13 | } 14 | 15 | void loop() { 16 | loopFDRS(); 17 | } 18 | -------------------------------------------------------------------------------- /examples/1_UART_Gateway/1_UART_Gateway.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // GATEWAY 2.000 4 | // 5 | // Developed by Timm Bogner (timmbogner@gmail.com) in Urbana, Illinois, USA. 6 | // 7 | 8 | #include "fdrs_gateway_config.h" 9 | #include 10 | 11 | void setup() { 12 | beginFDRS(); 13 | } 14 | 15 | void loop() { 16 | loopFDRS(); 17 | } 18 | -------------------------------------------------------------------------------- /examples/3_LoRa_Repeater/3_LoRa_Repeater.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // GATEWAY 2.000 4 | // 5 | // Developed by Timm Bogner (timmbogner@gmail.com) in Urbana, Illinois, USA. 6 | // 7 | 8 | #include "fdrs_gateway_config.h" 9 | #include 10 | 11 | void setup() { 12 | beginFDRS(); 13 | } 14 | 15 | void loop() { 16 | loopFDRS(); 17 | } 18 | -------------------------------------------------------------------------------- /examples/2_ESPNOW_Repeater/2_ESPNOW_Repeater.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // GATEWAY 2.000 4 | // 5 | // Developed by Timm Bogner (timmbogner@gmail.com) in Urbana, Illinois, USA. 6 | // 7 | 8 | #include "fdrs_gateway_config.h" 9 | #include 10 | 11 | void setup() { 12 | beginFDRS(); 13 | } 14 | 15 | void loop() { 16 | loopFDRS(); 17 | } 18 | -------------------------------------------------------------------------------- /examples/ESPNOW_Stress_Test/ESPNOW_Stress_Test.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // ESP-NOW Stress Tester or "Spammer" 4 | // 5 | // Sends ESP-NOW packets at approximately 60Hz. 6 | // 7 | 8 | #include "fdrs_node_config.h" 9 | #include 10 | 11 | void setup() { 12 | beginFDRS(); 13 | } 14 | void loop() { 15 | for (uint8_t i=0; i < 255; i++) { 16 | loadFDRS(float(i), IT_T); 17 | sendFDRS(); 18 | delay(15); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/examples/SSD1306ClockDemo/images.h: -------------------------------------------------------------------------------- 1 | const uint8_t activeSymbol[] PROGMEM = { 2 | B00000000, 3 | B00000000, 4 | B00011000, 5 | B00100100, 6 | B01000010, 7 | B01000010, 8 | B00100100, 9 | B00011000 10 | }; 11 | 12 | const uint8_t inactiveSymbol[] PROGMEM = { 13 | B00000000, 14 | B00000000, 15 | B00000000, 16 | B00000000, 17 | B00011000, 18 | B00011000, 19 | B00000000, 20 | B00000000 21 | }; 22 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Farm-Data-Relay-System 2 | version=2.0.1 3 | author=Timm Bogner 4 | maintainer=Timm Bogner 5 | sentence=Farm-Data-Relay-System - a infrastructure and cloud-less network 6 | paragraph=FDRS is a highly configurable cloud-agnostic network utilizing LoRa and ESPNow. Easily define nodes as sensors or routers and easily configure the way different protocols are forwarded. 7 | category=Communication 8 | url=https://github.com/timmbogner/Farm-Data-Relay-System 9 | architectures=* 10 | depends=ArduinoJson 11 | -------------------------------------------------------------------------------- /examples/Controller_examples/Single_Channel_Relay/Single_Channel_Relay.ino: -------------------------------------------------------------------------------- 1 | #define READING_ID 31 2 | #define GTWY_MAC 0x01 3 | #define USE_ESPNOW 4 | #define COIL_PIN 5 5 | 6 | #include 7 | 8 | bool status = 0; 9 | 10 | void fdrs_recv_cb(DataReading theData) { 11 | status = (bool)theData.d; 12 | } 13 | void setup() { 14 | beginFDRS(); 15 | if (addFDRS(1000, fdrs_recv_cb)) 16 | subscribeFDRS(READING_ID); 17 | pinMode(COIL_PIN, OUTPUT); 18 | } 19 | void loop() { 20 | loopFDRS(); 21 | if (status) digitalWrite(COIL_PIN, HIGH); 22 | else digitalWrite(COIL_PIN, LOW); 23 | } -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/README_GEOMETRY_64_48.md: -------------------------------------------------------------------------------- 1 | # GEOMETRY_64_48 2 | 3 | The 64x48 geometry setting are working with the `Wire.h` and `brzo_i2c` libraries. 4 | 5 | I've tested it successfully with a WEMOS D1 mini Lite and a WEMOS OLED shield 6 | 7 | Initialization code: 8 | 9 | - Wire 10 | ``` 11 | #include 12 | #include 13 | SSD1306Wire display(0x3c, D2, D1, GEOMETRY_64_48 ); // WEMOS OLED shield 14 | ``` 15 | 16 | - BRZO i2c 17 | ``` 18 | #include 19 | SSD1306Brzo display(0x3c, D2, D1, GEOMETRY_64_48 ); // WEMOS OLED Shield 20 | ``` 21 | -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/library.properties: -------------------------------------------------------------------------------- 1 | name=ESP8266 and ESP32 OLED driver for SSD1306 displays 2 | version=4.3.0 3 | author=ThingPulse, Fabrice Weinberg 4 | maintainer=ThingPulse 5 | sentence=I2C display driver for SSD1306 OLED displays connected to ESP8266, ESP32, Mbed-OS 6 | paragraph=The following geometries are currently supported: 128x64, 128x32, 64x48. The init sequence was inspired by Adafruit's library for the same display. 7 | category=Display 8 | url=https://github.com/ThingPulse/esp8266-oled-ssd1306 9 | architectures=esp8266,esp32 10 | license=MIT 11 | -------------------------------------------------------------------------------- /examples/LoRa_Controller/LoRa_Controller.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // ESP-NOW Sensor Example 4 | // 5 | // Developed by Timm Bogner (timmbogner@gmail.com) in Urbana, Illinois, USA. 6 | // An example of how to send data via ESP-NOW using FDRS. 7 | // 8 | 9 | #include "fdrs_node_config.h" 10 | #include 11 | 12 | void fdrs_recv_cb(DataReading theData) 13 | { 14 | DBG("ID: " + String(theData.id)); 15 | DBG("Type: " + String(theData.t)); 16 | DBG("Data: " + String(theData.d)); 17 | } 18 | 19 | void setup() 20 | { 21 | beginFDRS(); 22 | pingFDRS(1000); 23 | addFDRS(fdrs_recv_cb); 24 | subscribeFDRS(READING_ID); 25 | } 26 | void loop() 27 | { 28 | loopFDRS(); 29 | } 30 | -------------------------------------------------------------------------------- /examples/ESPNOW_Controller/ESPNOW_Controller.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // ESP-NOW Sensor Example 4 | // 5 | // Developed by Timm Bogner (timmbogner@gmail.com) in Urbana, Illinois, USA. 6 | // An example of how to send data via ESP-NOW using FDRS. 7 | // 8 | 9 | #include "fdrs_node_config.h" 10 | #include 11 | 12 | void fdrs_recv_cb(DataReading theData) 13 | { 14 | DBG("ID: " + String(theData.id)); 15 | DBG("Type: " + String(theData.t)); 16 | DBG("Data: " + String(theData.d)); 17 | } 18 | 19 | void setup() 20 | { 21 | beginFDRS(); 22 | pingFDRS(1000); 23 | addFDRS(fdrs_recv_cb); 24 | subscribeFDRS(READING_ID); 25 | } 26 | void loop() 27 | { 28 | loopFDRS(); 29 | } 30 | -------------------------------------------------------------------------------- /examples/Gateway_Examples/1_MQTT_Gateway_Ethernet/1_MQTT_Gateway_Ethernet.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // ETHERNET GATEWAY 4 | // 5 | // Developed by Timm Bogner (timmbogner@gmail.com) in Urbana, Illinois, USA. 6 | 7 | // Configuration for the ThingPulse ESPGateway: https://thingpulse.com/product/espgateway-ethernet-esp32-wifi-ble-gateway-with-rj45-ethernet-connector/ 8 | #define ETH_CLK_MODE ETH_CLOCK_GPIO16_OUT 9 | #define ETH_POWER_PIN 5 10 | 11 | #include "fdrs_gateway_config.h" 12 | #include 13 | 14 | void setup() { 15 | pinMode(ETH_POWER_PIN, OUTPUT); 16 | digitalWrite(ETH_POWER_PIN, HIGH); 17 | beginFDRS(); 18 | } 19 | 20 | void loop() { 21 | loopFDRS(); 22 | } 23 | -------------------------------------------------------------------------------- /examples/Sensor_Examples/CapacitiveSoil/CapacitiveSoil.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // CAPACITIVE SOIL MOISTURE SENSOR MODULE 4 | // 5 | // Developed by Timm Bogner (timmbogner@gmail.com) in Urbana, Illinois, USA. 6 | // Connect the sensor to an analog pin of your MCU. 7 | // 8 | 9 | #define SOIL_PIN 36 // Ignored on ESP8266 10 | 11 | #include "fdrs_node_config.h" 12 | #include 13 | void setup() { 14 | beginFDRS(); 15 | delay(50); //let the sensor warm up 16 | } 17 | void loop() { 18 | #ifdef ESP8266 19 | uint16_t s = analogRead(0); 20 | #else 21 | uint16_t s = analogRead(SOIL_PIN); 22 | #endif 23 | loadFDRS(s, SOIL_T); 24 | sendFDRS(); 25 | sleepFDRS(60 * 5); 26 | } 27 | -------------------------------------------------------------------------------- /examples/Sensor_Examples/DS18B20_fdrs/DS18B20_fdrs.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // DS18B20 SENSOR MODULE 4 | // 5 | 6 | #define ONE_WIRE_BUS 13 //Pin that the DS18B20 is connected to 7 | 8 | #include "fdrs_node_config.h" 9 | #include 10 | #include 11 | #include 12 | 13 | OneWire oneWire(ONE_WIRE_BUS); 14 | DallasTemperature sensors(&oneWire); 15 | 16 | void setup() { 17 | beginFDRS(); 18 | sensors.begin(); 19 | } 20 | 21 | void loop() { 22 | sensors.requestTemperatures(); // Send the command to get temperatures 23 | float tempC = sensors.getTempCByIndex(0); 24 | loadFDRS(tempC, TEMP_T); 25 | sendFDRS(); 26 | sleepFDRS(60); 27 | } 28 | -------------------------------------------------------------------------------- /examples/Sensor_Examples/SHT20_fdrs/SHT20_fdrs.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // SENSIRION SHT20 SENSOR MODULE 4 | // 5 | // Developed by Timm Bogner (timmbogner@gmail.com) in Urbana, Illinois, USA. 6 | // If you are using the sensor for air monitoring, change SOIL_T to HUMIDITY_T. 7 | // 8 | #include "DFRobot_SHT20.h" 9 | #include "fdrs_node_config.h" 10 | #include 11 | 12 | DFRobot_SHT20 sht20(&Wire, SHT20_I2C_ADDR); 13 | 14 | 15 | void setup() { 16 | beginFDRS(); 17 | sht20.initSHT20(); 18 | } 19 | void loop() { 20 | loadFDRS(sht20.readHumidity(), SOIL_T); 21 | loadFDRS(sht20.readTemperature(), TEMP_T); 22 | sendFDRS(); 23 | sleepFDRS(300); //Sleep time in seconds 24 | } 25 | -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; http://docs.platformio.org/page/projectconf.html 10 | 11 | [env:d1_mini] 12 | platform = espressif8266 13 | board = d1_mini 14 | framework = arduino 15 | upload_speed = 921600 16 | board_build.f_cpu = 160000000L 17 | upload_port = /dev/cu.SLAB_USBtoUART 18 | monitor_port = /dev/cu.SLAB_USBtoUART 19 | lib_deps = 20 | -------------------------------------------------------------------------------- /examples/LoRa_Sensor/LoRa_Sensor.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // LoRa Sensor Example 4 | // 5 | // Developed by Timm Bogner (timmbogner@gmail.com) in Urbana, Illinois, USA. 6 | // An example of how to send data via LoRa using FDRS. 7 | // 8 | 9 | #include "fdrs_node_config.h" 10 | #include 11 | 12 | float data1; 13 | float data2; 14 | 15 | void setup() { 16 | beginFDRS(); 17 | } 18 | void loop() { 19 | data1 = readHum(); 20 | loadFDRS(data1, HUMIDITY_T); 21 | data2 = readTemp(); 22 | loadFDRS(data2, TEMP_T); 23 | sendFDRS(); 24 | sleepFDRS(10); //Sleep time in seconds 25 | } 26 | 27 | float readTemp() { 28 | return 21.0; 29 | } 30 | 31 | float readHum() { 32 | return random(0,100); 33 | } 34 | -------------------------------------------------------------------------------- /examples/Sensor_Examples/BME280_fdrs/BME280_fdrs.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // BME280 SENSOR MODULE 4 | // 5 | // Developed by Timm Bogner (timmbogner@gmail.com) in Urbana, Illinois, USA. 6 | 7 | #include "fdrs_node_config.h" 8 | #include 9 | #include 10 | 11 | Adafruit_BME280 bme; 12 | 13 | void setup() { 14 | //Serial.begin(115200); 15 | beginFDRS(); 16 | while (!bme.begin(0x76)) { 17 | //Serial.println("BME not initializing!"); 18 | delay(10); 19 | } 20 | } 21 | 22 | void loop() { 23 | loadFDRS(bme.readTemperature(), TEMP_T); 24 | loadFDRS(bme.readHumidity(), HUMIDITY_T); 25 | loadFDRS(bme.readPressure() / 100.0F, PRESSURE_T); 26 | sendFDRS(); 27 | sleepFDRS(60); //Sleep time in seconds 28 | } 29 | -------------------------------------------------------------------------------- /examples/Sensor_Examples/BMP280_fdrs/BMP280_fdrs.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // BMP280 SENSOR MODULE 4 | // 5 | // Developed by Timm Bogner (timmbogner@gmail.com) in Urbana, Illinois, USA. 6 | // Connect sensor SDA and SCL pins to those of the ESP. 7 | 8 | #include "fdrs_node_config.h" 9 | #include 10 | #include 11 | 12 | Adafruit_BMP280 bmp; 13 | 14 | void setup() { 15 | //Serial.begin(115200); 16 | beginFDRS(); 17 | while (!bmp.begin(0x76)) { 18 | //Serial.println("BMP not initializing!"); 19 | delay(10); 20 | } 21 | } 22 | 23 | void loop() { 24 | loadFDRS(bmp.readTemperature(), TEMP_T); 25 | loadFDRS(bmp.readPressure() / 100.0F, PRESSURE_T); 26 | sendFDRS(); 27 | sleepFDRS(60); //Sleep time in seconds 28 | } 29 | -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/UPGRADE-4.0.md: -------------------------------------------------------------------------------- 1 | # Upgrade from 3.x to 4.0 2 | 3 | There are changes that breaks compatibility with older versions. 4 | 5 | 1. You'll have to change data type for all your binary resources such as images and fonts from 6 | 7 | ```c 8 | const char MySymbol[] PROGMEM = { 9 | ``` 10 | 11 | to 12 | 13 | ```c 14 | const uint8_t MySymbol[] PROGMEM = { 15 | ``` 16 | 17 | 1. Arguments of `setContrast` from `char` to `uint8_t` 18 | 19 | ```c++ 20 | void OLEDDisplay::setContrast(char contrast, char precharge, char comdetect); 21 | ``` 22 | 23 | to 24 | 25 | ```c++ 26 | void OLEDDisplay::setContrast(uint8_t contrast, uint8_t precharge, uint8_t comdetect); 27 | ``` 28 | -------------------------------------------------------------------------------- /examples/Sensor_Examples/MLX90614_fdrs/MLX90614_fdrs.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // MLX90614 INFRARED TEMPERATURE SENSOR MODULE 4 | // 5 | // Developed by Timm Bogner (timmbogner@gmail.com) in Urbana, Illinois, USA. 6 | 7 | #include "fdrs_node_config.h" 8 | #include 9 | #include 10 | 11 | Adafruit_MLX90614 mlx = Adafruit_MLX90614(); 12 | 13 | void setup() { 14 | beginFDRS(); 15 | delay(250); 16 | DBG("Adafruit MLX90614 test"); 17 | if (!mlx.begin()) { 18 | DBG("Error connecting to MLX sensor. Check wiring."); 19 | while (1); 20 | }; 21 | } 22 | 23 | void loop() { 24 | loadFDRS(mlx.readAmbientTempC(), TEMP_T); 25 | loadFDRS(mlx.readObjectTempC(), TEMP2_T); 26 | sendFDRS(); 27 | sleepFDRS(60); //Sleep time in seconds 28 | } 29 | -------------------------------------------------------------------------------- /examples/Gateway_Examples/Repeater_Voltage/Repeater_Voltage.ino: -------------------------------------------------------------------------------- 1 | #define GTWY_READING_ID 42 2 | #define INTERVAL_SECONDS 60 3 | #define ADC_PIN 34 4 | 5 | #include "fdrs_gateway_config.h" 6 | #include 7 | int vref = 1100; 8 | 9 | float getVoltage() { 10 | uint16_t v = analogRead(ADC_PIN); 11 | float battery_voltage = ((float)v / 4095.0) * 2.0 * 3.3 * (vref / 1000.0); 12 | String voltage = "Voltage :" + String(battery_voltage) + "V"; 13 | DBG(voltage); 14 | return battery_voltage; 15 | } 16 | void sendReading() { 17 | float v = getVoltage(); 18 | loadFDRS(v, VOLTAGE_T, GTWY_READING_ID); 19 | sendFDRS(); 20 | } 21 | 22 | void setup() { 23 | beginFDRS(); 24 | sendReading(); 25 | scheduleFDRS(sendReading, INTERVAL_SECONDS * 1000); 26 | sendReading(); 27 | } 28 | 29 | void loop() { 30 | loopFDRS(); 31 | } -------------------------------------------------------------------------------- /examples/Sensor_Examples/AHT20_fdrs/AHT20_fdrs.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // AHT20 SENSOR MODULE 4 | // 5 | // Developed by Timm Bogner (timmbogner@gmail.com) in Urbana, Illinois, USA. 6 | 7 | #include "fdrs_node_config.h" 8 | #include 9 | #include 10 | 11 | Adafruit_AHTX0 aht; 12 | 13 | void setup() { 14 | Serial.begin(115200); 15 | beginFDRS(); 16 | if (! aht.begin()) { 17 | Serial.println("Could not find AHT? Check wiring"); 18 | while (1) delay(10); 19 | } 20 | } 21 | 22 | void loop() { 23 | sensors_event_t humidity, temp; 24 | aht.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data 25 | loadFDRS(temp.temperature, TEMP_T); 26 | loadFDRS(humidity.relative_humidity, HUMIDITY_T); 27 | sendFDRS(); 28 | sleepFDRS(60); //Sleep time in seconds 29 | } 30 | -------------------------------------------------------------------------------- /examples/ESPNOW_Sensor/ESPNOW_Sensor.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // ESP-NOW Sensor Example 4 | // 5 | // Developed by Timm Bogner (timmbogner@gmail.com) in Urbana, Illinois, USA. 6 | // An example of how to send data via ESP-NOW using FDRS. 7 | // 8 | 9 | #include "fdrs_node_config.h" 10 | #include 11 | 12 | float data1; 13 | float data2; 14 | 15 | void setup() { 16 | beginFDRS(); 17 | } 18 | void loop() { 19 | data1 = readHum(); 20 | loadFDRS(data1, HUMIDITY_T); 21 | data2 = readTemp(); 22 | loadFDRS(data2, TEMP_T); 23 | // DBG(sendFDRS()); 24 | if(sendFDRS()){ 25 | DBG("Big Success!"); 26 | } else { 27 | DBG("Nope, not so much."); 28 | } 29 | sleepFDRS(10); //Sleep time in seconds 30 | } 31 | 32 | float readTemp() { 33 | return 22.069; 34 | } 35 | 36 | float readHum() { 37 | return random(0, 100); 38 | } 39 | -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ESP8266 and ESP32 OLED driver for SSD1306 displays", 3 | "version": "4.3.0", 4 | "keywords": "ssd1306, oled, display, i2c", 5 | "description": "I2C display driver for SSD1306 OLED displays connected to ESP8266, ESP32, Mbed-OS", 6 | "license": "MIT", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/ThingPulse/esp8266-oled-ssd1306" 11 | }, 12 | "authors": 13 | [ 14 | { 15 | "name": "Daniel Eichhorn, ThingPulse", 16 | "email": "squix78@gmail.com", 17 | "url": "https://thingpulse.com" 18 | }, 19 | { 20 | "name": "Fabrice Weinberg", 21 | "email": "fabrice@weinberg.me" 22 | } 23 | ], 24 | "frameworks": "arduino", 25 | "platforms": [ 26 | "espressif8266", 27 | "espressif32", 28 | "nordicnrf52" 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /examples/Sensor_Examples/TippingBucket/TippingBucket.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // TIPPING BUCKET RAINFALL SENSOR MODULE 4 | // 5 | // Developed by Timm Bogner (timmbogner@gmail.com) in Urbana, Illinois, USA. 6 | 7 | #define REED_PIN 2 8 | 9 | #include "fdrs_node_config.h" 10 | #include 11 | 12 | unsigned int theCount = 0; 13 | unsigned long lastTrigger = 0; 14 | boolean clicked = false; 15 | 16 | ICACHE_RAM_ATTR void detectsMovement() { 17 | clicked = true; 18 | lastTrigger = millis(); 19 | } 20 | 21 | void setup() { 22 | beginFDRS(); 23 | pinMode(REED_PIN, INPUT_PULLUP); 24 | attachInterrupt(digitalPinToInterrupt(REED_PIN), detectsMovement, FALLING); 25 | } 26 | 27 | void loop() { 28 | if (clicked && millis() - lastTrigger > 100) { 29 | theCount++; 30 | Serial.print("DINK."); 31 | Serial.println(theCount); 32 | clicked = false; 33 | loadFDRS(theCount, RAINFALL_T); 34 | sendFDRS(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/fdrs_debug.h: -------------------------------------------------------------------------------- 1 | #ifndef DBG_LEVEL 2 | #define DBG_LEVEL GLOBAL_DBG_LEVEL 3 | #endif 4 | 5 | #ifdef FDRS_DEBUG 6 | #ifdef USE_OLED 7 | #define DBG(a) Serial.print(" "); Serial.println(a); debug_OLED(String(a)); 8 | #else 9 | #define DBG(a) Serial.print(" "); Serial.println(a); 10 | #endif // USE_OLED 11 | #if (DBG_LEVEL == 0) 12 | #define DBG1(a); 13 | #define DBG2(a); 14 | #endif 15 | #if (DBG_LEVEL == 1) 16 | #define DBG1(a) Serial.print("[1] "); Serial.println(a); 17 | #define DBG2(a) 18 | #endif 19 | #if (DBG_LEVEL >= 2) 20 | #define DBG1(a) Serial.print("[1] "); Serial.println(a); 21 | #define DBG2(a) Serial.print("[2] "); Serial.println(a); 22 | #endif 23 | #else 24 | #ifdef USE_OLED 25 | #define DBG(a) debug_OLED(String(a)); 26 | #else 27 | #define DBG(a) 28 | #endif // USE_OLED 29 | #define DBG1(a) 30 | #define DBG2(a) 31 | #endif // FDRS_DEBUG -------------------------------------------------------------------------------- /src/fdrs_gateway_scheduler.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | typedef struct ScheduleItem 4 | { 5 | uint32_t interval; 6 | uint32_t start; 7 | void (*functionName)(); 8 | bool active; 9 | } ScheduleItem; 10 | 11 | ScheduleItem theSchedule[16]; 12 | 13 | bool scheduleFDRS(void (*added_func)(), uint32_t added_interval) 14 | { 15 | ScheduleItem arg = {.interval = added_interval, .start = millis(), .functionName = added_func, .active = true}; 16 | for (int i = 0; i < 16; i++) 17 | { 18 | if (!theSchedule[i].active) 19 | { 20 | theSchedule[i] = arg; 21 | return true; 22 | } 23 | } 24 | DBG("Schedule is full!"); 25 | return false; 26 | } 27 | void handle_schedule() 28 | { 29 | for (int i = 0; i < 16; i++) 30 | { 31 | if (theSchedule[i].active && (millis() - theSchedule[i].start > theSchedule[i].interval)) 32 | { 33 | theSchedule[i].start = millis(); 34 | theSchedule[i].functionName(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 timmbogner 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 by Daniel Eichhorn 4 | Copyright (c) 2016 by Fabrice Weinberg 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | See more at http://blog.squix.ch 25 | -------------------------------------------------------------------------------- /examples/Sensor_Examples/MESB_fdrs/MESB_fdrs.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Multifunction ESP8266 Sensor Board by Phil Grant 4 | // 5 | // https://github.com/gadjet/Multifunction-ESP8266-Sensor-board 6 | // 7 | 8 | #include "fdrs_node_config.h" 9 | #include 10 | #include 11 | 12 | Adafruit_AHT10 aht; 13 | 14 | const int reedSwitch = 13; 15 | 16 | void setup() { 17 | aht.begin(); 18 | 19 | // Init Serial Monitor 20 | //Serial.begin(115200); 21 | // initialize the reed switch pin as an input: 22 | pinMode(reedSwitch, INPUT); 23 | // initialize the wakeup pin as an input: 24 | pinMode(16, WAKEUP_PULLUP); 25 | beginFDRS(); 26 | } 27 | 28 | 29 | void loop() { 30 | sensors_event_t humidity, temp; 31 | aht.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data 32 | // Read the state of the reed switch and send open or closed 33 | if (digitalRead(reedSwitch) == HIGH) { 34 | loadFDRS(1.0, MOTION_T); 35 | } 36 | else { 37 | loadFDRS(0.0, MOTION_T); 38 | } 39 | loadFDRS((analogRead(A0) * 4.2 * 10 / 1023), VOLTAGE_T); 40 | loadFDRS(humidity.relative_humidity, HUMIDITY_T); 41 | loadFDRS(temp.temperature, TEMP_T); 42 | // Send message via FDRS 43 | sendFDRS(); 44 | sleepFDRS(15); //15 Min's sleep 45 | } 46 | -------------------------------------------------------------------------------- /examples/Controller_examples/LilyGo_TWatch2020/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | #include 6 | 7 | #define READING_ID 1 //Unique ID for this sensor 8 | #define GTWY_MAC 0x01 //Address of the nearest gateway 9 | 10 | #define USE_ESPNOW 11 | //#define USE_LORA 12 | #define DEEP_SLEEP 13 | //#define POWER_CTRL 14 14 | #define FDRS_DEBUG 15 | 16 | // LoRa Configuration 17 | #define RADIOLIB_MODULE SX1276 18 | #define LORA_SS 18 19 | #define LORA_RST 14 20 | #define LORA_DIO 26 21 | #define LORA_BUSY 33 22 | //#define USE_SX126X 23 | 24 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 25 | #define LORA_ACK // Request LoRa acknowledgment. 26 | 27 | //#define USE_LR // Use ESP-NOW LR mode (ESP32 only) 28 | 29 | // NTP Time settings for controllers and sensors 30 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 31 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 32 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 33 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /examples/Sensor_Examples/DHT22_fdrs/DHT22_fdrs.ino: -------------------------------------------------------------------------------- 1 | // Example testing sketch for various DHT humidity/temperature sensors 2 | // Written by ladyada, public domain 3 | 4 | // Modified by Timm Bogner for Farm Data Relay System -- Untested because I don't have a DHT sensor onhand. 5 | 6 | #include "fdrs_node_config.h" 7 | #include 8 | #include "DHT.h" 9 | 10 | #define DHTPIN 2 // Digital pin connected to the DHT sensor 11 | 12 | // Uncomment whatever type you're using! 13 | //#define DHTTYPE DHT11 // DHT 11 14 | #define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 15 | //#define DHTTYPE DHT21 // DHT 21 (AM2301) 16 | 17 | DHT dht(DHTPIN, DHTTYPE); 18 | 19 | void setup() { 20 | beginFDRS(); 21 | DBG("DHTxx Sketch!"); 22 | dht.begin(); 23 | } 24 | 25 | void loop() { 26 | // Wait a few seconds between measurements. 27 | // Reading temperature or humidity takes about 250 milliseconds! 28 | // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) 29 | float h = dht.readHumidity(); 30 | // Read temperature as Celsius (the default) 31 | float t = dht.readTemperature(); 32 | 33 | // Check if any reads failed and exit early (to try again). 34 | if (isnan(h) || isnan(t)) { 35 | DBG("Failed to read from DHT sensor!"); 36 | return; 37 | } 38 | loadFDRS(h, HUMIDITY_T); 39 | loadFDRS(t, TEMP_T); 40 | sendFDRS(); 41 | sleepFDRS(10); //Sleep time in seconds 42 | } 43 | -------------------------------------------------------------------------------- /examples/Controller_examples/ControllerTime/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | #include 6 | 7 | #define READING_ID 1 //Unique ID for this sensor 8 | #define GTWY_MAC 0x01 //Address of the nearest gateway 9 | 10 | #define USE_ESPNOW 11 | //#define USE_LORA 12 | #define DEEP_SLEEP 13 | //#define POWER_CTRL 14 14 | #define FDRS_DEBUG 15 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 16 | 17 | // LoRa Configuration 18 | #define RADIOLIB_MODULE SX1276 19 | #define LORA_SS 18 20 | #define LORA_RST 14 21 | #define LORA_DIO 26 22 | #define LORA_BUSY 33 23 | //#define USE_SX126X 24 | 25 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 26 | #define LORA_ACK // Request LoRa acknowledgment. 27 | 28 | //#define USE_LR // Use ESP-NOW LR mode (ESP32 only) 29 | 30 | // NTP Time settings for controllers and sensors 31 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 32 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 33 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 34 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug 35 | -------------------------------------------------------------------------------- /examples/Sensor_Examples/README.md: -------------------------------------------------------------------------------- 1 | # FDRS Sensors 2 | Out of date- Needs improvement. 3 | | Sensor Name | Maker/Datasheet | Library | 4 | | --- | --- | --- | 5 | | AHT20 | [ASAIR](http://www.aosong.com/userfiles/files/media/Data%20Sheet%20AHT20.pdf) | [Adafruit](https://github.com/adafruit/Adafruit_AHTX0) | 6 | | BME280 | [Bosch](https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bme280-ds002.pdf) | [Adafruit](https://github.com/adafruit/Adafruit_BME280_Library) | 7 | | BMP280 | [Bosch](https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp280-ds001.pdf) | [Adafruit](https://github.com/adafruit/Adafruit_BMP280_Library) | 8 | | DHT22 | [Aosong](https://www.sparkfun.com/datasheets/Sensors/Temperature/DHT22.pdf) |[adafruit](https://github.com/adafruit/DHT-sensor-library) | 9 | | DS18B20 | [Dallas](https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf) | [milesburton](https://github.com/adafruit/Adafruit_AHTX0) | 10 | | LilyGo HiGrow | [TTGO](http://www.lilygo.cn/prod_view.aspx?TypeId=50033&Id=1172) | 11 | | Multifunction ESP8266 Sensor Board | [Phil Grant](https://github.com/gadjet/Multifunction-ESP8266-Sensor-board) | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | I would like to use this spot as a showcase for open source PCB designs. If **you** have designed a sensor module that runs on either ESP8266 or ESP32, please contact me at timmbogner@gmail.com. I will make a custom sensor sketch, along with a link and description available here. 20 | -------------------------------------------------------------------------------- /examples/Sensor_Examples/FrequencyCounter/FrequencyCounter.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Gypsum-based Soil Moisture Sensor 4 | // 5 | // Uses a Ezsbc.com Dev board, a Kisssys moisture sensor board, and a DS3231 RTC. 6 | // Deep sleep current is less than 20µA. 7 | // https://www.printables.com/model/176752-gypson-water-sensor 8 | 9 | 10 | #include "fdrs_node_config.h" 11 | #include 12 | 13 | 14 | #define BUTTON_PIN_BITMASK 0x100000000 // 2^32 in hex the pin that is connected to SQW 15 | #define CLOCK_INTERRUPT_PIN 32 // yep same pin 16 | 17 | 18 | const int FreqIn1 = 5; 19 | volatile uint16_t Freq1 = 0; 20 | static uint16_t FreqOut1; 21 | 22 | ICACHE_RAM_ATTR void SensorInt1() { 23 | // If the pin is Rising, increment counter 24 | Freq1++; 25 | }; 26 | 27 | 28 | void readFrequency() { 29 | // for one second we count the pulses and get our moisture reading in pps 30 | attachInterrupt(FreqIn1, SensorInt1, RISING); 31 | delay(1000); // delay in ms is 1 seconds-- not the most accurate way to do this but more than accurate enough for our low frequency and 10 second read 32 | FreqOut1 = Freq1; // our frequency * 10 33 | detachInterrupt(FreqIn1); // only reading once so turn off the interrupt 34 | 35 | } 36 | void setup() { 37 | beginFDRS(); 38 | pinMode(FreqIn1, INPUT); 39 | Freq1 = 0; 40 | delay(50); 41 | readFrequency(); 42 | //DBG("Frequency = " + String(FreqOut1)); 43 | loadFDRS(FreqOut1, SOIL_T); 44 | sendFDRS(); 45 | sleepFDRS(1800); //Sleep time in seconds 46 | 47 | } 48 | 49 | void loop() { 50 | // nuttin honey 51 | } 52 | -------------------------------------------------------------------------------- /examples/LoRa_Stress_Test/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | #include 6 | 7 | #define READING_ID 5 //Unique ID for this sensor 8 | #define GTWY_MAC 0x01 //Address of the nearest gateway 9 | 10 | // #define USE_ESPNOW 11 | #define USE_LORA 12 | //#define DEEP_SLEEP 13 | //#define POWER_CTRL 14 14 | #define FDRS_DEBUG 15 | // 16 | // I2C - OLED or RTC 17 | #define I2C_SDA 5 18 | #define I2C_SCL 6 19 | 20 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 21 | // #define USE_OLED 22 | #define OLED_HEADER "FDRS" 23 | #define OLED_PAGE_SECS 30 24 | #define OLED_RST -1 25 | 26 | // LoRa Configuration 27 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 28 | #define LORA_SS 18 29 | #define LORA_RST 14 30 | #define LORA_DIO 26 31 | #define LORA_BUSY 33 32 | //#define USE_SX126X 33 | 34 | //#define CUSTOM_SPI 35 | #define LORA_SPI_SCK 5 36 | #define LORA_SPI_MISO 19 37 | #define LORA_SPI_MOSI 27 38 | 39 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 40 | #define LORA_ACK // Request LoRa acknowledgment. 41 | 42 | // NTP Time settings for controllers and sensors 43 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 44 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 45 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 46 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/src/SH1106.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 by ThingPulse, Daniel Eichhorn 5 | * Copyright (c) 2018 by Fabrice Weinberg 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | * 25 | * ThingPulse invests considerable time and money to develop these open source libraries. 26 | * Please support us by buying our products (and not the clones) from 27 | * https://thingpulse.com 28 | * 29 | */ 30 | 31 | #ifndef SH1106_h 32 | #define SH1106_h 33 | #include "SH1106Wire.h" 34 | 35 | // For make SH1106 an alias for SH1106Wire 36 | typedef SH1106Wire SH1106; 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/src/SSD1306.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 by ThingPulse, Daniel Eichhorn 5 | * Copyright (c) 2018 by Fabrice Weinberg 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | * 25 | * ThingPulse invests considerable time and money to develop these open source libraries. 26 | * Please support us by buying our products (and not the clones) from 27 | * https://thingpulse.com 28 | * 29 | */ 30 | 31 | #ifndef SSD1306_h 32 | #define SSD1306_h 33 | #include "SSD1306Wire.h" 34 | 35 | // For legacy support make SSD1306 an alias for SSD1306 36 | typedef SSD1306Wire SSD1306; 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /examples/Sensor_Examples/DS18B20_fdrs/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | 6 | #define READING_ID 1 //Unique ID for this sensor 7 | #define GTWY_MAC 0x01 //Address of the nearest gateway 8 | 9 | #define USE_ESPNOW 10 | //#define USE_LORA 11 | #define DEEP_SLEEP 12 | //#define POWER_CTRL 14 13 | #define FDRS_DEBUG 14 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 15 | 16 | // I2C - OLED or RTC 17 | #define I2C_SDA 5 18 | #define I2C_SCL 6 19 | 20 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 21 | // #define USE_OLED 22 | #define OLED_HEADER "FDRS" 23 | #define OLED_PAGE_SECS 30 24 | #define OLED_RST -1 25 | 26 | // LoRa Configuration 27 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 28 | #define LORA_SS 18 29 | #define LORA_RST 14 30 | #define LORA_DIO 26 31 | #define LORA_BUSY 33 32 | //#define USE_SX126X 33 | 34 | //#define CUSTOM_SPI 35 | #define LORA_SPI_SCK 5 36 | #define LORA_SPI_MISO 19 37 | #define LORA_SPI_MOSI 27 38 | 39 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 40 | #define LORA_ACK // Request LoRa acknowledgment. 41 | 42 | // NTP Time settings for controllers and sensors 43 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 44 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 45 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 46 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /examples/Sensor_Examples/AHT20_fdrs/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | 6 | #define READING_ID 1 //Unique ID for this sensor 7 | #define GTWY_MAC 0x01 //Address of the nearest gateway 8 | 9 | #define USE_ESPNOW 10 | //#define USE_LORA 11 | #define DEEP_SLEEP 12 | //#define POWER_CTRL 14 13 | 14 | #define FDRS_DEBUG 15 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 16 | 17 | // I2C - OLED or RTC 18 | #define I2C_SDA 5 19 | #define I2C_SCL 6 20 | 21 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 22 | // #define USE_OLED 23 | #define OLED_HEADER "FDRS" 24 | #define OLED_PAGE_SECS 30 25 | #define OLED_RST -1 26 | 27 | // LoRa Configuration 28 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 29 | #define LORA_SS 18 30 | #define LORA_RST 14 31 | #define LORA_DIO 26 32 | #define LORA_BUSY 33 33 | //#define USE_SX126X 34 | 35 | //#define CUSTOM_SPI 36 | #define LORA_SPI_SCK 5 37 | #define LORA_SPI_MISO 19 38 | #define LORA_SPI_MOSI 27 39 | 40 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 41 | #define LORA_ACK // Request LoRa acknowledgment. 42 | 43 | // NTP Time settings for controllers and sensors 44 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 45 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 46 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 47 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /examples/Sensor_Examples/BME280_fdrs/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | 6 | #define READING_ID 1 //Unique ID for this sensor 7 | #define GTWY_MAC 0x01 //Address of the nearest gateway 8 | 9 | #define USE_ESPNOW 10 | //#define USE_LORA 11 | #define DEEP_SLEEP 12 | //#define POWER_CTRL 14 13 | 14 | #define FDRS_DEBUG 15 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 16 | 17 | // I2C - OLED or RTC 18 | #define I2C_SDA 5 19 | #define I2C_SCL 6 20 | 21 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 22 | // #define USE_OLED 23 | #define OLED_HEADER "FDRS" 24 | #define OLED_PAGE_SECS 30 25 | #define OLED_RST -1 26 | 27 | // LoRa Configuration 28 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 29 | #define LORA_SS 18 30 | #define LORA_RST 14 31 | #define LORA_DIO 26 32 | #define LORA_BUSY 33 33 | //#define USE_SX126X 34 | 35 | //#define CUSTOM_SPI 36 | #define LORA_SPI_SCK 5 37 | #define LORA_SPI_MISO 19 38 | #define LORA_SPI_MOSI 27 39 | 40 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 41 | #define LORA_ACK // Request LoRa acknowledgment. 42 | 43 | // NTP Time settings for controllers and sensors 44 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 45 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 46 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 47 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /examples/Sensor_Examples/BMP280_fdrs/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | 6 | #define READING_ID 1 //Unique ID for this sensor 7 | #define GTWY_MAC 0x01 //Address of the nearest gateway 8 | 9 | #define USE_ESPNOW 10 | //#define USE_LORA 11 | #define DEEP_SLEEP 12 | //#define POWER_CTRL 14 13 | 14 | #define FDRS_DEBUG 15 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 16 | 17 | // I2C - OLED or RTC 18 | #define I2C_SDA 5 19 | #define I2C_SCL 6 20 | 21 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 22 | // #define USE_OLED 23 | #define OLED_HEADER "FDRS" 24 | #define OLED_PAGE_SECS 30 25 | #define OLED_RST -1 26 | 27 | // LoRa Configuration 28 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 29 | #define LORA_SS 18 30 | #define LORA_RST 14 31 | #define LORA_DIO 26 32 | #define LORA_BUSY 33 33 | //#define USE_SX126X 34 | 35 | //#define CUSTOM_SPI 36 | #define LORA_SPI_SCK 5 37 | #define LORA_SPI_MISO 19 38 | #define LORA_SPI_MOSI 27 39 | 40 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 41 | #define LORA_ACK // Request LoRa acknowledgment. 42 | 43 | // NTP Time settings for controllers and sensors 44 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 45 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 46 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 47 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /examples/Sensor_Examples/DHT22_fdrs/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | 6 | #define READING_ID 1 //Unique ID for this sensor 7 | #define GTWY_MAC 0x01 //Address of the nearest gateway 8 | 9 | #define USE_ESPNOW 10 | //#define USE_LORA 11 | #define DEEP_SLEEP 12 | //#define POWER_CTRL 14 13 | 14 | #define FDRS_DEBUG 15 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 16 | 17 | // I2C - OLED or RTC 18 | #define I2C_SDA 5 19 | #define I2C_SCL 6 20 | 21 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 22 | // #define USE_OLED 23 | #define OLED_HEADER "FDRS" 24 | #define OLED_PAGE_SECS 30 25 | #define OLED_RST -1 26 | 27 | // LoRa Configuration 28 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 29 | #define LORA_SS 18 30 | #define LORA_RST 14 31 | #define LORA_DIO 26 32 | #define LORA_BUSY 33 33 | //#define USE_SX126X 34 | 35 | //#define CUSTOM_SPI 36 | #define LORA_SPI_SCK 5 37 | #define LORA_SPI_MISO 19 38 | #define LORA_SPI_MOSI 27 39 | 40 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 41 | #define LORA_ACK // Request LoRa acknowledgment. 42 | 43 | // NTP Time settings for controllers and sensors 44 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 45 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 46 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 47 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /examples/Sensor_Examples/KisssysGypsum/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | 6 | #define READING_ID 1 //Unique ID for this sensor 7 | #define GTWY_MAC 0x01 //Address of the nearest gateway 8 | 9 | #define USE_ESPNOW 10 | //#define USE_LORA 11 | #define DEEP_SLEEP 12 | //#define POWER_CTRL 14 13 | 14 | #define FDRS_DEBUG 15 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 16 | 17 | // I2C - OLED or RTC 18 | #define I2C_SDA 5 19 | #define I2C_SCL 6 20 | 21 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 22 | // #define USE_OLED 23 | #define OLED_HEADER "FDRS" 24 | #define OLED_PAGE_SECS 30 25 | #define OLED_RST -1 26 | 27 | // LoRa Configuration 28 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 29 | #define LORA_SS 18 30 | #define LORA_RST 14 31 | #define LORA_DIO 26 32 | #define LORA_BUSY 33 33 | //#define USE_SX126X 34 | 35 | //#define CUSTOM_SPI 36 | #define LORA_SPI_SCK 5 37 | #define LORA_SPI_MISO 19 38 | #define LORA_SPI_MOSI 27 39 | 40 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 41 | #define LORA_ACK // Request LoRa acknowledgment. 42 | 43 | // NTP Time settings for controllers and sensors 44 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 45 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 46 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 47 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /examples/Sensor_Examples/LilyGo_HiGrow_32/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | 6 | #define READING_ID 1 //Unique ID for this sensor 7 | #define GTWY_MAC 0x01 //Address of the nearest gateway 8 | 9 | #define USE_ESPNOW 10 | //#define USE_LORA 11 | #define DEEP_SLEEP 12 | #define POWER_CTRL 4 13 | 14 | #define FDRS_DEBUG 15 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 16 | 17 | // I2C - OLED or RTC 18 | #define I2C_SDA 5 19 | #define I2C_SCL 6 20 | 21 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 22 | // #define USE_OLED 23 | #define OLED_HEADER "FDRS" 24 | #define OLED_PAGE_SECS 30 25 | #define OLED_RST -1 26 | 27 | // LoRa Configuration 28 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 29 | #define LORA_SS 18 30 | #define LORA_RST 14 31 | #define LORA_DIO 26 32 | #define LORA_BUSY 33 33 | //#define USE_SX126X 34 | 35 | //#define CUSTOM_SPI 36 | #define LORA_SPI_SCK 5 37 | #define LORA_SPI_MISO 19 38 | #define LORA_SPI_MOSI 27 39 | 40 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 41 | #define LORA_ACK // Request LoRa acknowledgment. 42 | 43 | // NTP Time settings for controllers and sensors 44 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 45 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 46 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 47 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /examples/Sensor_Examples/MESB_fdrs/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | 6 | #define READING_ID 1 //Unique ID for this sensor 7 | #define GTWY_MAC 0x01 //Address of the nearest gateway 8 | 9 | #define USE_ESPNOW 10 | //#define USE_LORA 11 | #define DEEP_SLEEP 12 | //#define POWER_CTRL 14 13 | 14 | #define FDRS_DEBUG 15 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 16 | 17 | // I2C - OLED or RTC 18 | #define I2C_SDA 5 19 | #define I2C_SCL 6 20 | 21 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 22 | // #define USE_OLED 23 | #define OLED_HEADER "FDRS" 24 | #define OLED_PAGE_SECS 30 25 | #define OLED_RST -1 26 | 27 | // LoRa Configuration 28 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 29 | #define LORA_SS 18 30 | #define LORA_RST 14 31 | #define LORA_DIO 26 32 | #define LORA_BUSY 33 33 | //#define USE_SX126X 34 | 35 | //#define CUSTOM_SPI 36 | #define LORA_SPI_SCK 5 37 | #define LORA_SPI_MISO 19 38 | #define LORA_SPI_MOSI 27 39 | 40 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 41 | #define LORA_ACK // Request LoRa acknowledgment. 42 | 43 | // NTP Time settings for controllers and sensors 44 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 45 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 46 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 47 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /examples/Sensor_Examples/MLX90614_fdrs/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | 6 | #define READING_ID 1 //Unique ID for this sensor 7 | #define GTWY_MAC 0x01 //Address of the nearest gateway 8 | 9 | #define USE_ESPNOW 10 | //#define USE_LORA 11 | #define DEEP_SLEEP 12 | #define POWER_CTRL 14 13 | 14 | #define FDRS_DEBUG 15 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 16 | 17 | // I2C - OLED or RTC 18 | #define I2C_SDA 5 19 | #define I2C_SCL 6 20 | 21 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 22 | // #define USE_OLED 23 | #define OLED_HEADER "FDRS" 24 | #define OLED_PAGE_SECS 30 25 | #define OLED_RST -1 26 | 27 | // LoRa Configuration 28 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 29 | #define LORA_SS 18 30 | #define LORA_RST 14 31 | #define LORA_DIO 26 32 | #define LORA_BUSY 33 33 | //#define USE_SX126X 34 | 35 | //#define CUSTOM_SPI 36 | #define LORA_SPI_SCK 5 37 | #define LORA_SPI_MISO 19 38 | #define LORA_SPI_MOSI 27 39 | 40 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 41 | #define LORA_ACK // Request LoRa acknowledgment. 42 | 43 | // NTP Time settings for controllers and sensors 44 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 45 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 46 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 47 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /examples/Sensor_Examples/TippingBucket/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | 6 | #define READING_ID 1 //Unique ID for this sensor 7 | #define GTWY_MAC 0x01 //Address of the nearest gateway 8 | 9 | #define USE_ESPNOW 10 | //#define USE_LORA 11 | #define DEEP_SLEEP 12 | //#define POWER_CTRL 14 13 | 14 | #define FDRS_DEBUG 15 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 16 | 17 | // I2C - OLED or RTC 18 | #define I2C_SDA 5 19 | #define I2C_SCL 6 20 | 21 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 22 | // #define USE_OLED 23 | #define OLED_HEADER "FDRS" 24 | #define OLED_PAGE_SECS 30 25 | #define OLED_RST -1 26 | 27 | // LoRa Configuration 28 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 29 | #define LORA_SS 18 30 | #define LORA_RST 14 31 | #define LORA_DIO 26 32 | #define LORA_BUSY 33 33 | //#define USE_SX126X 34 | 35 | //#define CUSTOM_SPI 36 | #define LORA_SPI_SCK 5 37 | #define LORA_SPI_MISO 19 38 | #define LORA_SPI_MOSI 27 39 | 40 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 41 | #define LORA_ACK // Request LoRa acknowledgment. 42 | 43 | // NTP Time settings for controllers and sensors 44 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 45 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 46 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 47 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /examples/Sensor_Examples/FrequencyCounter/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | 6 | #define READING_ID 23 //Unique ID for this sensor 7 | #define GTWY_MAC 0x01 //Address of the nearest gateway 8 | 9 | #define USE_ESPNOW 10 | //#define USE_LORA 11 | #define DEEP_SLEEP 12 | #define POWER_CTRL 22 13 | 14 | #define FDRS_DEBUG 15 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 16 | 17 | // I2C - OLED or RTC 18 | #define I2C_SDA 5 19 | #define I2C_SCL 6 20 | 21 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 22 | // #define USE_OLED 23 | #define OLED_HEADER "FDRS" 24 | #define OLED_PAGE_SECS 30 25 | #define OLED_RST -1 26 | 27 | // LoRa Configuration 28 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 29 | #define LORA_SS 18 30 | #define LORA_RST 14 31 | #define LORA_DIO 26 32 | #define LORA_BUSY 33 33 | //#define USE_SX126X 34 | 35 | //#define CUSTOM_SPI 36 | #define LORA_SPI_SCK 5 37 | #define LORA_SPI_MISO 19 38 | #define LORA_SPI_MOSI 27 39 | 40 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 41 | #define LORA_ACK // Request LoRa acknowledgment. 42 | 43 | // NTP Time settings for controllers and sensors 44 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 45 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 46 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 47 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /examples/Sensor_Examples/GenericGPS_fdrs/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | 6 | #define READING_ID 1 //Unique ID for this sensor 7 | #define GTWY_MAC 0x03 //Address of the nearest gateway 8 | 9 | //#define USE_ESPNOW 10 | #define USE_LORA 11 | //#define DEEP_SLEEP 12 | //#define POWER_CTRL 14 13 | 14 | #define FDRS_DEBUG 15 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 16 | 17 | // I2C - OLED or RTC 18 | #define I2C_SDA 5 19 | #define I2C_SCL 6 20 | 21 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 22 | // #define USE_OLED 23 | #define OLED_HEADER "FDRS" 24 | #define OLED_PAGE_SECS 30 25 | #define OLED_RST -1 26 | 27 | // LoRa Configuration 28 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 29 | #define LORA_SS 18 30 | #define LORA_RST 14 31 | #define LORA_DIO 26 32 | #define LORA_BUSY 33 33 | //#define USE_SX126X 34 | 35 | //#define CUSTOM_SPI 36 | #define LORA_SPI_SCK 5 37 | #define LORA_SPI_MISO 19 38 | #define LORA_SPI_MOSI 27 39 | 40 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 41 | #define LORA_ACK // Request LoRa acknowledgment. 42 | 43 | // NTP Time settings for controllers and sensors 44 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 45 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 46 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 47 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /examples/Sensor_Examples/TSL2561/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | 6 | #define READING_ID 1 //Unique ID for this sensor 7 | #define GTWY_MAC 0x01 //Address of the nearest gateway 8 | 9 | #define USE_ESPNOW 10 | //#define USE_LORA 11 | #define DEEP_SLEEP 12 | //#define POWER_CTRL 14 13 | 14 | #define FDRS_DEBUG 15 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 16 | 17 | 18 | // I2C - OLED or RTC 19 | #define I2C_SDA 5 20 | #define I2C_SCL 6 21 | 22 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 23 | // #define USE_OLED 24 | #define OLED_HEADER "FDRS" 25 | #define OLED_PAGE_SECS 30 26 | #define OLED_RST -1 27 | 28 | // LoRa Configuration 29 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 30 | #define LORA_SS 18 31 | #define LORA_RST 14 32 | #define LORA_DIO 26 33 | #define LORA_BUSY 33 34 | //#define USE_SX126X 35 | 36 | //#define CUSTOM_SPI 37 | #define LORA_SPI_SCK 5 38 | #define LORA_SPI_MISO 19 39 | #define LORA_SPI_MOSI 27 40 | 41 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 42 | #define LORA_ACK // Request LoRa acknowledgment. 43 | 44 | // NTP Time settings for controllers and sensors 45 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 46 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 47 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 48 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug 49 | -------------------------------------------------------------------------------- /examples/ESPNOW_Stress_Test/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | #include 6 | 7 | #define READING_ID 3 //Unique ID for this sensor 8 | #define GTWY_MAC 0x01 //Address of the nearest gateway 9 | 10 | #define USE_ESPNOW 11 | //#define USE_LORA 12 | //#define DEEP_SLEEP 13 | //#define POWER_CTRL 14 14 | 15 | //#define FDRS_DEBUG 16 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 17 | 18 | // I2C - OLED or RTC 19 | #define I2C_SDA 5 20 | #define I2C_SCL 6 21 | 22 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 23 | // #define USE_OLED 24 | #define OLED_HEADER "FDRS" 25 | #define OLED_PAGE_SECS 30 26 | #define OLED_RST -1 27 | 28 | // LoRa Configuration 29 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 30 | #define LORA_SS 18 31 | #define LORA_RST 14 32 | #define LORA_DIO 26 33 | #define LORA_BUSY 33 34 | //#define USE_SX126X 35 | 36 | //#define CUSTOM_SPI 37 | #define LORA_SPI_SCK 5 38 | #define LORA_SPI_MISO 19 39 | #define LORA_SPI_MOSI 27 40 | 41 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 42 | #define LORA_ACK // Request LoRa acknowledgment. 43 | 44 | // NTP Time settings for controllers and sensors 45 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 46 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 47 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 48 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /examples/Sensor_Examples/SHT20_fdrs/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | 6 | #define READING_ID 11 //Unique ID for this sensor 7 | #define GTWY_MAC 0x01 //Address of the nearest gateway 8 | 9 | #define USE_ESPNOW 10 | //#define USE_LORA 11 | #define DEEP_SLEEP 12 | //#define POWER_CTRL 14 13 | 14 | #define FDRS_DEBUG // Enable USB-Serial debugging 15 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 16 | 17 | // I2C - OLED or RTC 18 | #define I2C_SDA 5 19 | #define I2C_SCL 6 20 | 21 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 22 | // #define USE_OLED 23 | #define OLED_HEADER "FDRS" 24 | #define OLED_PAGE_SECS 30 25 | #define OLED_RST -1 26 | 27 | // LoRa Configuration 28 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 29 | #define LORA_SS 18 30 | #define LORA_RST 14 31 | #define LORA_DIO 26 32 | #define LORA_BUSY 33 33 | //#define USE_SX126X 34 | 35 | //#define CUSTOM_SPI 36 | #define LORA_SPI_SCK 5 37 | #define LORA_SPI_MISO 19 38 | #define LORA_SPI_MOSI 27 39 | 40 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 41 | #define LORA_ACK // Request LoRa acknowledgment. 42 | 43 | // NTP Time settings for controllers and sensors 44 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 45 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 46 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 47 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /examples/LoRa_Controller/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // Node Configuration 3 | 4 | #include 5 | 6 | #define READING_ID 1 //Unique ID for this sensor 7 | #define GTWY_MAC 0x01 //Address of the nearest gateway 8 | 9 | //#define USE_ESPNOW 10 | #define USE_LORA 11 | //#define DEEP_SLEEP 12 | //#define POWER_CTRL 14 13 | 14 | #define FDRS_DEBUG // Enable USB-Serial debugging 15 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 16 | 17 | // I2C - OLED or RTC 18 | #define I2C_SDA 5 19 | #define I2C_SCL 6 20 | 21 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 22 | // #define USE_OLED 23 | #define OLED_HEADER "FDRS" 24 | #define OLED_PAGE_SECS 30 25 | #define OLED_RST -1 26 | 27 | // LoRa Configuration 28 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 29 | #define LORA_SS 18 30 | #define LORA_RST 14 31 | #define LORA_DIO 26 32 | #define LORA_BUSY 33 33 | //#define USE_SX126X 34 | 35 | //#define CUSTOM_SPI 36 | #define LORA_SPI_SCK 5 37 | #define LORA_SPI_MISO 19 38 | #define LORA_SPI_MOSI 27 39 | 40 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 41 | #define LORA_ACK // Request LoRa acknowledgment. 42 | 43 | // NTP Time settings for controllers and sensors 44 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 45 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 46 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 47 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /examples/ESPNOW_Sensor/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | #include 6 | 7 | #define READING_ID 1 //Unique ID for this sensor 8 | #define GTWY_MAC 0x01 //Address of the nearest gateway 9 | 10 | #define USE_ESPNOW 11 | //#define USE_LORA 12 | #define DEEP_SLEEP 13 | //#define POWER_CTRL 14 14 | 15 | #define FDRS_DEBUG // Enable USB-Serial debugging 16 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 17 | 18 | // I2C - OLED or RTC 19 | #define I2C_SDA 5 20 | #define I2C_SCL 6 21 | 22 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 23 | // #define USE_OLED 24 | #define OLED_HEADER "FDRS" 25 | #define OLED_PAGE_SECS 30 26 | #define OLED_RST -1 27 | 28 | // LoRa Configuration 29 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 30 | #define LORA_SS 18 31 | #define LORA_RST 14 32 | #define LORA_DIO 26 33 | #define LORA_BUSY 33 34 | //#define USE_SX126X 35 | 36 | //#define CUSTOM_SPI 37 | #define LORA_SPI_SCK 5 38 | #define LORA_SPI_MISO 19 39 | #define LORA_SPI_MOSI 27 40 | 41 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 42 | #define LORA_ACK // Request LoRa acknowledgment. 43 | 44 | // NTP Time settings for controllers and sensors 45 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 46 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 47 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 48 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /examples/LoRa_Sensor/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | #include 6 | 7 | #define READING_ID 2 //Unique ID for this sensor 8 | #define GTWY_MAC 0x01 //Address of the nearest gateway 9 | 10 | //#define USE_ESPNOW 11 | #define USE_LORA 12 | #define DEEP_SLEEP 13 | //#define POWER_CTRL 14 14 | 15 | #define FDRS_DEBUG // Enable USB-Serial debugging 16 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 17 | 18 | /// I2C - OLED or RTC 19 | #define I2C_SDA 5 20 | #define I2C_SCL 6 21 | 22 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 23 | // #define USE_OLED 24 | #define OLED_HEADER "FDRS" 25 | #define OLED_PAGE_SECS 30 26 | #define OLED_RST -1 27 | 28 | // LoRa Configuration 29 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 30 | #define LORA_SS 18 31 | #define LORA_RST 14 32 | #define LORA_DIO 26 33 | #define LORA_BUSY 33 34 | //#define USE_SX126X 35 | 36 | //#define CUSTOM_SPI 37 | #define LORA_SPI_SCK 5 38 | #define LORA_SPI_MISO 19 39 | #define LORA_SPI_MOSI 27 40 | 41 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 42 | #define LORA_ACK // Request LoRa acknowledgment. 43 | 44 | // NTP Time settings for controllers and sensors 45 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 46 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 47 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 48 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /examples/ESPNOW_Controller/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | #include 6 | 7 | #define READING_ID 1 //Unique ID for this sensor 8 | #define GTWY_MAC 0x01 //Address of the nearest gateway 9 | 10 | #define USE_ESPNOW 11 | //#define USE_LORA 12 | //#define DEEP_SLEEP 13 | //#define POWER_CTRL 14 14 | 15 | #define FDRS_DEBUG // Enable USB-Serial debugging 16 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 17 | 18 | // I2C - OLED or RTC 19 | #define I2C_SDA 5 20 | #define I2C_SCL 6 21 | 22 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 23 | // #define USE_OLED 24 | #define OLED_HEADER "FDRS" 25 | #define OLED_PAGE_SECS 30 26 | #define OLED_RST -1 27 | 28 | // LoRa Configuration 29 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 30 | #define LORA_SS 18 31 | #define LORA_RST 14 32 | #define LORA_DIO 26 33 | #define LORA_BUSY 33 34 | //#define USE_SX126X 35 | 36 | //#define CUSTOM_SPI 37 | #define LORA_SPI_SCK 5 38 | #define LORA_SPI_MISO 19 39 | #define LORA_SPI_MOSI 27 40 | 41 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 42 | #define LORA_ACK // Request LoRa acknowledgment. 43 | 44 | // NTP Time settings for controllers and sensors 45 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 46 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 47 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 48 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /examples/Controller_examples/FastLED/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | #include 6 | 7 | #define READING_ID 103 //Unique ID for this sensor 8 | #define GTWY_MAC 0x01 //Address of the nearest gateway 9 | 10 | #define USE_ESPNOW 11 | //#define USE_LORA 12 | #define DEEP_SLEEP 13 | //#define POWER_CTRL 14 14 | 15 | #define FDRS_DEBUG // Enable USB-Serial debugging 16 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 17 | 18 | // I2C - OLED or RTC 19 | #define I2C_SDA 5 20 | #define I2C_SCL 6 21 | 22 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 23 | // #define USE_OLED 24 | #define OLED_HEADER "FDRS" 25 | #define OLED_PAGE_SECS 30 26 | #define OLED_RST -1 27 | 28 | // LoRa Configuration 29 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 30 | #define LORA_SS 18 31 | #define LORA_RST 14 32 | #define LORA_DIO 26 33 | #define LORA_BUSY 33 34 | //#define USE_SX126X 35 | 36 | //#define CUSTOM_SPI 37 | #define LORA_SPI_SCK 5 38 | #define LORA_SPI_MISO 19 39 | #define LORA_SPI_MOSI 27 40 | 41 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 42 | #define LORA_ACK // Request LoRa acknowledgment. 43 | 44 | // NTP Time settings for controllers and sensors 45 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 46 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 47 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 48 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /examples/Controller_examples/Irrigation/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | #include 6 | 7 | #define READING_ID 1 //Unique ID for this sensor 8 | #define GTWY_MAC 0x01 //Address of the nearest gateway 9 | 10 | #define USE_ESPNOW 11 | //#define USE_LORA 12 | //#define DEEP_SLEEP 13 | //#define POWER_CTRL 14 14 | 15 | #define FDRS_DEBUG // Enable USB-Serial debugging 16 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 17 | 18 | /// I2C - OLED or RTC 19 | #define I2C_SDA 5 20 | #define I2C_SCL 6 21 | 22 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 23 | // #define USE_OLED 24 | #define OLED_HEADER "FDRS" 25 | #define OLED_PAGE_SECS 30 26 | #define OLED_RST -1 27 | 28 | // LoRa Configuration 29 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 30 | #define LORA_SS 18 31 | #define LORA_RST 14 32 | #define LORA_DIO 26 33 | #define LORA_BUSY 33 34 | //#define USE_SX126X 35 | 36 | //#define CUSTOM_SPI 37 | #define LORA_SPI_SCK 5 38 | #define LORA_SPI_MISO 19 39 | #define LORA_SPI_MOSI 27 40 | 41 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 42 | #define LORA_ACK // Request LoRa acknowledgment. 43 | 44 | // NTP Time settings for controllers and sensors 45 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 46 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 47 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 48 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /examples/Controller_examples/TFT_eSPI_fdrs/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | #include 6 | 7 | #define READING_ID 1 //Unique ID for this sensor 8 | #define GTWY_MAC 0x01 //Address of the nearest gateway 9 | 10 | #define USE_ESPNOW 11 | //#define USE_LORA 12 | //#define DEEP_SLEEP 13 | //#define POWER_CTRL 14 14 | 15 | #define FDRS_DEBUG // Enable USB-Serial debugging 16 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 17 | 18 | // I2C - OLED or RTC 19 | #define I2C_SDA 5 20 | #define I2C_SCL 6 21 | 22 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 23 | // #define USE_OLED 24 | #define OLED_HEADER "FDRS" 25 | #define OLED_PAGE_SECS 30 26 | #define OLED_RST -1 27 | 28 | // LoRa Configuration 29 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 30 | #define LORA_SS 18 31 | #define LORA_RST 14 32 | #define LORA_DIO 26 33 | #define LORA_BUSY 33 34 | //#define USE_SX126X 35 | 36 | //#define CUSTOM_SPI 37 | #define LORA_SPI_SCK 5 38 | #define LORA_SPI_MISO 19 39 | #define LORA_SPI_MOSI 27 40 | 41 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 42 | #define LORA_ACK // Request LoRa acknowledgment. 43 | 44 | // NTP Time settings for controllers and sensors 45 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 46 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 47 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 48 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /examples/Sensor_Examples/CapacitiveSoil/fdrs_node_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Sensor Configuration 4 | 5 | 6 | #define READING_ID 21 //Unique ID for this sensor 7 | #define GTWY_MAC 0x01 //Address of the nearest gateway 8 | 9 | //#define USE_ESPNOW 10 | #define USE_LORA 11 | 12 | //#define USE_LR // Enables 802.11LR on ESP32 ESP-NOW devices 13 | 14 | //#define DEEP_SLEEP 15 | //#define POWER_CTRL 14 16 | 17 | #define FDRS_DEBUG // Enable USB-Serial debugging 18 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 19 | 20 | // I2C - OLED or RTC 21 | #define I2C_SDA 5 22 | #define I2C_SCL 6 23 | 24 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 25 | // #define USE_OLED 26 | #define OLED_HEADER "FDRS" 27 | #define OLED_PAGE_SECS 30 28 | #define OLED_RST -1 29 | 30 | // LoRa Configuration 31 | #define RADIOLIB_MODULE SX1276 //Tested on SX1276 32 | #define LORA_SS 18 33 | #define LORA_RST 14 34 | #define LORA_DIO 26 35 | #define LORA_BUSY 33 36 | //#define USE_SX126X 37 | 38 | //#define CUSTOM_SPI 39 | #define LORA_SPI_SCK 5 40 | #define LORA_SPI_MISO 19 41 | #define LORA_SPI_MOSI 27 42 | 43 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 44 | #define LORA_ACK // Request LoRa acknowledgment. 45 | 46 | // NTP Time settings for controllers and sensors 47 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 48 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 49 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 50 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/examples/SSD1306SimpleDemo/images.h: -------------------------------------------------------------------------------- 1 | #define WiFi_Logo_width 60 2 | #define WiFi_Logo_height 36 3 | const uint8_t WiFi_Logo_bits[] PROGMEM = { 4 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 5 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, 6 | 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF, 7 | 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 8 | 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 9 | 0xFF, 0x03, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 10 | 0x00, 0xFF, 0xFF, 0xFF, 0x07, 0xC0, 0x83, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 11 | 0x01, 0x00, 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x0C, 0x00, 12 | 0xC0, 0xFF, 0xFF, 0x7C, 0x00, 0x60, 0x0C, 0x00, 0xC0, 0x31, 0x46, 0x7C, 13 | 0xFC, 0x77, 0x08, 0x00, 0xE0, 0x23, 0xC6, 0x3C, 0xFC, 0x67, 0x18, 0x00, 14 | 0xE0, 0x23, 0xE4, 0x3F, 0x1C, 0x00, 0x18, 0x00, 0xE0, 0x23, 0x60, 0x3C, 15 | 0x1C, 0x70, 0x18, 0x00, 0xE0, 0x03, 0x60, 0x3C, 0x1C, 0x70, 0x18, 0x00, 16 | 0xE0, 0x07, 0x60, 0x3C, 0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C, 17 | 0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00, 18 | 0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00, 0xE0, 0x8F, 0x71, 0x3C, 19 | 0x1C, 0x70, 0x18, 0x00, 0xC0, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x08, 0x00, 20 | 0xC0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x0C, 0x00, 0x80, 0xFF, 0xFF, 0x1F, 21 | 0x00, 0x00, 0x06, 0x00, 0x80, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x07, 0x00, 22 | 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0xF8, 0xFF, 0xFF, 23 | 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 24 | 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF, 25 | 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00, 26 | 0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 27 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 28 | }; 29 | -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/examples/SSD1306TwoScreenDemo/images.h: -------------------------------------------------------------------------------- 1 | #define WiFi_Logo_width 60 2 | #define WiFi_Logo_height 36 3 | const uint8_t WiFi_Logo_bits[] PROGMEM = { 4 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 5 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, 6 | 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF, 7 | 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 8 | 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 9 | 0xFF, 0x03, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 10 | 0x00, 0xFF, 0xFF, 0xFF, 0x07, 0xC0, 0x83, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 11 | 0x01, 0x00, 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x0C, 0x00, 12 | 0xC0, 0xFF, 0xFF, 0x7C, 0x00, 0x60, 0x0C, 0x00, 0xC0, 0x31, 0x46, 0x7C, 13 | 0xFC, 0x77, 0x08, 0x00, 0xE0, 0x23, 0xC6, 0x3C, 0xFC, 0x67, 0x18, 0x00, 14 | 0xE0, 0x23, 0xE4, 0x3F, 0x1C, 0x00, 0x18, 0x00, 0xE0, 0x23, 0x60, 0x3C, 15 | 0x1C, 0x70, 0x18, 0x00, 0xE0, 0x03, 0x60, 0x3C, 0x1C, 0x70, 0x18, 0x00, 16 | 0xE0, 0x07, 0x60, 0x3C, 0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C, 17 | 0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00, 18 | 0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00, 0xE0, 0x8F, 0x71, 0x3C, 19 | 0x1C, 0x70, 0x18, 0x00, 0xC0, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x08, 0x00, 20 | 0xC0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x0C, 0x00, 0x80, 0xFF, 0xFF, 0x1F, 21 | 0x00, 0x00, 0x06, 0x00, 0x80, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x07, 0x00, 22 | 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0xF8, 0xFF, 0xFF, 23 | 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 24 | 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF, 25 | 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00, 26 | 0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 27 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 28 | }; 29 | -------------------------------------------------------------------------------- /src/fdrs_gateway_ota.h: -------------------------------------------------------------------------------- 1 | #if defined(ESP32) || defined(ESP8266) 2 | #include 3 | #endif // defined(ESP32) || defined (ESP8266) 4 | 5 | void begin_OTA() { 6 | #if defined(ESP32) || defined(ESP8266) 7 | // Port defaults to 3232 8 | // ArduinoOTA.setPort(3232); 9 | 10 | // Hostname defaults to esp3232-[MAC] 11 | // 12 | ArduinoOTA.setHostname("FDRSGW"); 13 | 14 | // No authentication by default 15 | // ArduinoOTA.setPassword("admin"); 16 | 17 | // Password can be set with it's md5 value as well 18 | // MD5(admin) = 21232f297a57a5a743894a0e4a801fc3 19 | // ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3"); 20 | ArduinoOTA.onStart([]() { 21 | String type; 22 | if (ArduinoOTA.getCommand() == U_FLASH) { 23 | type = "sketch"; 24 | } 25 | else { // U_SPIFFS 26 | type = "filesystem"; 27 | } 28 | 29 | // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end() 30 | //ESP_LOGI(TAG, "Start updating " + type); 31 | }); 32 | ArduinoOTA.onEnd([]() { 33 | DBG("\nEnd"); 34 | }); 35 | ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { 36 | #ifndef USE_OLED // Displaying on OLED slows down the download process 37 | DBG("Progress: " + String(progress / (total / 100)) + "%"); 38 | #endif 39 | }); 40 | ArduinoOTA.onError([](ota_error_t error) { 41 | DBG("Error[" + String(error) + "]"); 42 | if (error == OTA_AUTH_ERROR) { DBG("Auth Failed"); } 43 | else if (error == OTA_BEGIN_ERROR) { DBG("Begin Failed"); } 44 | else if (error == OTA_CONNECT_ERROR) { DBG("Connect Failed"); } 45 | else if (error == OTA_RECEIVE_ERROR) { DBG("Receive Failed"); } 46 | else if (error == OTA_END_ERROR) { DBG("End Failed"); } 47 | }); 48 | 49 | ArduinoOTA.begin(); 50 | #endif // defined(ESP32) || defined (ESP8266) 51 | 52 | } 53 | 54 | void handleOTA() { 55 | #if defined(ESP32) || defined(ESP8266) 56 | ArduinoOTA.handle(); 57 | #endif // defined(ESP32) || defined (ESP8266) 58 | } 59 | 60 | -------------------------------------------------------------------------------- /examples/Controller_examples/LilyGo_TWatch2020/LilyGo_TWatch2020.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // LilyGo T-Watch 2020 (v1) Example 4 | // This sketch retrieves the time from a nearby FDRS gateway using ESP-NOW. 5 | // 6 | // Developed by Timm Bogner (timmbogner@gmail.com) in Urbana, Illinois, USA 7 | // FDRS Timekeeping was developed and contributed by Jeff Lehman (aviateur17) 8 | // 9 | // Gratitude to Lewis He and LilyGo for building and supporting the T-Watch. 10 | // 11 | 12 | #define UPTIME 3 // Seconds to remain on before sleeping 13 | #define LILYGO_WATCH_2020_V1 14 | 15 | #include 16 | #include "fdrs_node_config.h" 17 | #include 18 | 19 | TTGOClass *ttgo; 20 | TFT_eSPI *tft; 21 | PCF8563_Class *rtc; 22 | AXP20X_Class *power; 23 | 24 | uint32_t interval = 0; 25 | 26 | void fdrs_recv_cb(DataReading theData) { 27 | } 28 | 29 | void setup() { 30 | ttgo = TTGOClass::getWatch(); 31 | ttgo->begin(); 32 | ttgo->openBL(); 33 | rtc = ttgo->rtc; 34 | tft = ttgo->tft; 35 | power = ttgo->power; 36 | 37 | tft->setTextColor(TFT_RED, TFT_BLACK); 38 | //Draw voltage in top right corner 39 | tft->drawString(String(power->getBattVoltage() / 1000.0), 180, 0, 4); 40 | 41 | beginFDRS(); 42 | uint32_t contact = pingFDRS(100); 43 | if (contact != UINT32_MAX) { 44 | // Draw ping response time (if any) in top left 45 | tft->drawString(String(contact), 0, 0, 4); 46 | addFDRS(fdrs_recv_cb); 47 | delay(100); 48 | rtc->syncToRtc(); 49 | } 50 | 51 | char strftime_buf[64]; 52 | time_t local = time(NULL) + (isDST ? dstOffset : stdOffset); 53 | localtime_r(&local, &timeinfo); 54 | strftime(strftime_buf, sizeof(strftime_buf), "%m-%d-%Y", &timeinfo); // generate MM-DD-YYYY local time character array 55 | tft->setTextColor(TFT_BLUE, TFT_BLACK); 56 | tft->drawString(strftime_buf, 50, 200, 4); 57 | tft->setTextColor(TFT_GREEN, TFT_BLACK); 58 | strftime(strftime_buf, sizeof(strftime_buf), "%I:%M:%S", &timeinfo); // generate HH:MM:SS local time character array 59 | tft->drawString(strftime_buf, 5, 75, 7); 60 | delay(UPTIME * 1000); 61 | 62 | power->clearIRQ(); 63 | ttgo->displaySleep(); 64 | ttgo->powerOff(); 65 | esp_sleep_enable_ext1_wakeup(GPIO_SEL_35, ESP_EXT1_WAKEUP_ALL_LOW); 66 | esp_deep_sleep_start(); 67 | } 68 | 69 | void loop() { 70 | } -------------------------------------------------------------------------------- /examples/Controller_examples/TFT_eSPI_fdrs/TFT_eSPI_fdrs.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // TFT_eSPI Example 4 | // 5 | // Listens for datareading IDs #101-104 and displays their data in the four corners of a TFT screen. 6 | // Developed by Timm Bogner (timmbogner@gmail.com) in Urbana, Illinois, USA. 7 | // 8 | // 9 | #include "fdrs_node_config.h" 10 | #include 11 | #include 12 | 13 | TFT_eSPI tft = TFT_eSPI(); 14 | 15 | #define CONTROL_A 101 //ID for datapoint A 16 | #define CONTROL_B 102 //ID for datapoint B 17 | #define CONTROL_C 103 //ID for datapoint C 18 | #define CONTROL_D 104 //ID for datapoint D 19 | 20 | float value_A = 0; 21 | float value_B = 0; 22 | float value_C = 0; 23 | float value_D = 0; 24 | 25 | bool newData = false; 26 | 27 | void fdrs_recv_cb(DataReading theData) { 28 | switch (theData.id) { 29 | case CONTROL_A: 30 | value_A = theData.d; 31 | newData = true; 32 | break; 33 | case CONTROL_B: 34 | value_B = theData.d; 35 | newData = true; 36 | break; 37 | case CONTROL_C: 38 | value_C = theData.d; 39 | newData = true; 40 | break; 41 | case CONTROL_D: 42 | value_D = theData.d; 43 | newData = true; 44 | break; 45 | } 46 | } 47 | void updateScreen() { 48 | tft.fillScreen(TFT_BLACK); 49 | tft.setTextDatum(TL_DATUM); 50 | tft.drawFloat(value_A, 3, 0, 0, 2); 51 | tft.setTextDatum(TR_DATUM); 52 | tft.drawFloat(value_B, 3, tft.width(), 0, 2); 53 | tft.setTextDatum(BL_DATUM); 54 | tft.drawFloat(value_C, 3, 0, tft.height(), 2); 55 | tft.setTextDatum(BR_DATUM); 56 | tft.drawFloat(value_D, 3, tft.width(), tft.height(), 2); 57 | 58 | } 59 | 60 | void setup() { 61 | tft.init(); 62 | tft.setRotation(1); 63 | tft.fillScreen(TFT_BLACK); 64 | tft.setTextColor(TFT_WHITE, TFT_BLACK); 65 | tft.setTextSize(2); 66 | updateScreen(); 67 | beginFDRS(); 68 | DBG("W:" +String(tft.width())); 69 | DBG("FARM DATA RELAY SYSTEM :: TFT_eSPI Example -- thanks Bodmer!"); 70 | if (addFDRS(1000, fdrs_recv_cb)) { 71 | subscribeFDRS(CONTROL_A); 72 | subscribeFDRS(CONTROL_B); 73 | subscribeFDRS(CONTROL_C); 74 | subscribeFDRS(CONTROL_D); 75 | } else { 76 | DBG("Not Connected"); 77 | } 78 | 79 | } 80 | 81 | void loop() 82 | { 83 | loopFDRS(); 84 | if (newData) { 85 | newData = false; 86 | updateScreen(); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/examples/SSD1306UiDemo/images.h: -------------------------------------------------------------------------------- 1 | #define WiFi_Logo_width 60 2 | #define WiFi_Logo_height 36 3 | const uint8_t WiFi_Logo_bits[] PROGMEM = { 4 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 5 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, 6 | 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF, 7 | 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 8 | 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 9 | 0xFF, 0x03, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 10 | 0x00, 0xFF, 0xFF, 0xFF, 0x07, 0xC0, 0x83, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 11 | 0x01, 0x00, 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x0C, 0x00, 12 | 0xC0, 0xFF, 0xFF, 0x7C, 0x00, 0x60, 0x0C, 0x00, 0xC0, 0x31, 0x46, 0x7C, 13 | 0xFC, 0x77, 0x08, 0x00, 0xE0, 0x23, 0xC6, 0x3C, 0xFC, 0x67, 0x18, 0x00, 14 | 0xE0, 0x23, 0xE4, 0x3F, 0x1C, 0x00, 0x18, 0x00, 0xE0, 0x23, 0x60, 0x3C, 15 | 0x1C, 0x70, 0x18, 0x00, 0xE0, 0x03, 0x60, 0x3C, 0x1C, 0x70, 0x18, 0x00, 16 | 0xE0, 0x07, 0x60, 0x3C, 0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C, 17 | 0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00, 18 | 0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00, 0xE0, 0x8F, 0x71, 0x3C, 19 | 0x1C, 0x70, 0x18, 0x00, 0xC0, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x08, 0x00, 20 | 0xC0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x0C, 0x00, 0x80, 0xFF, 0xFF, 0x1F, 21 | 0x00, 0x00, 0x06, 0x00, 0x80, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x07, 0x00, 22 | 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0xF8, 0xFF, 0xFF, 23 | 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 24 | 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF, 25 | 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00, 26 | 0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 27 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 28 | }; 29 | 30 | const uint8_t activeSymbol[] PROGMEM = { 31 | B00000000, 32 | B00000000, 33 | B00011000, 34 | B00100100, 35 | B01000010, 36 | B01000010, 37 | B00100100, 38 | B00011000 39 | }; 40 | 41 | const uint8_t inactiveSymbol[] PROGMEM = { 42 | B00000000, 43 | B00000000, 44 | B00000000, 45 | B00000000, 46 | B00011000, 47 | B00011000, 48 | B00000000, 49 | B00000000 50 | }; 51 | -------------------------------------------------------------------------------- /examples/Sensor_Examples/TSL2561/TSL2561.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "fdrs_node_config.h" 6 | #include 7 | 8 | Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345); 9 | 10 | 11 | /**************************************************************************/ 12 | /* 13 | Configures the gain and integration time for the TSL2561 14 | */ 15 | /**************************************************************************/ 16 | void configureSensor(void) 17 | { 18 | /* You can also manually set the gain or enable auto-gain support */ 19 | // tsl.setGain(TSL2561_GAIN_1X); /* No gain ... use in bright light to avoid sensor saturation */ 20 | // tsl.setGain(TSL2561_GAIN_16X); /* 16x gain ... use in low light to boost sensitivity */ 21 | tsl.enableAutoRange(true); /* Auto-gain ... switches automatically between 1x and 16x */ 22 | 23 | /* Changing the integration time gives you better sensor resolution (402ms = 16-bit data) */ 24 | tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); /* fast but low resolution */ 25 | // tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_101MS); /* medium resolution and speed */ 26 | // tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_402MS); /* 16-bit data but slowest conversions */ 27 | 28 | } 29 | 30 | /**************************************************************************/ 31 | /* 32 | Arduino setup function (automatically called at startup) 33 | */ 34 | /**************************************************************************/ 35 | void setup(void) 36 | { 37 | beginFDRS(); 38 | /* Initialise the sensor */ 39 | //use tsl.begin() to default to Wire, 40 | //tsl.begin(&Wire2) directs api to use Wire2, etc. 41 | if(!tsl.begin()) 42 | { 43 | DBG("Ooops, no TSL2561 detected ... Check your wiring or I2C ADDR!"); 44 | while(1); 45 | } 46 | configureSensor(); 47 | } 48 | 49 | void loop(void) 50 | { 51 | sensors_event_t event; 52 | tsl.getEvent(&event); 53 | if (event.light) 54 | { 55 | DBG(String(event.light) + " lux"); 56 | loadFDRS(float(event.light), LIGHT_T); 57 | sendFDRS(); 58 | sleepFDRS(10); //Sleep time in seconds 59 | } 60 | else 61 | { 62 | /* If event.light = 0 lux the sensor is probably saturated 63 | and no reliable data could be generated! */ 64 | Serial.println("Sensor overload"); 65 | } 66 | delay(250); 67 | } 68 | -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map List 3 | ####################################### 4 | 5 | 6 | ####################################### 7 | # Constants (LITERAL1) 8 | ####################################### 9 | INVERSE LITERAL1 10 | 11 | TEXT_ALIGN_LEFT LITERAL1 12 | TEXT_ALIGN_RIGHT LITERAL1 13 | TEXT_ALIGN_CENTER LITERAL1 14 | TEXT_ALIGN_CENTER_BOTH LITERAL1 15 | 16 | GEOMETRY_128_64 LITERAL1 17 | GEOMETRY_128_32 LITERAL1 18 | GEOMETRY_RAWMODE LITERAL1 19 | 20 | ArialMT_Plain_10 LITERAL1 21 | ArialMT_Plain_16 LITERAL1 22 | ArialMT_Plain_24 LITERAL1 23 | 24 | SLIDE_UP LITERAL1 25 | SLIDE_DOWN LITERAL1 26 | SLIDE_LEFT LITERAL1 27 | SLIDE_RIGHT LITERAL1 28 | 29 | TOP LITERAL1 30 | RIGHT LITERAL1 31 | BOTTOM LITERAL1 32 | LEFT LITERAL1 33 | 34 | LEFT_RIGHT LITERAL1 35 | RIGHT_LEFT LITERAL1 36 | 37 | IN_TRANSITION LITERAL1 38 | FIXED LITERAL1 39 | 40 | 41 | ####################################### 42 | # Datatypes (KEYWORD1) 43 | ####################################### 44 | OLEDDisplay KEYWORD1 45 | OLEDDisplayUi KEYWORD1 46 | 47 | SH1106Wire KEYWORD1 48 | SH1106Brzo KEYWORD1 49 | SH1106Spi KEYWORD1 50 | 51 | SSD1306Wire KEYWORD1 52 | SSD1306Brzo KEYWORD1 53 | SSD1306I2C KEYWORD1 54 | SSD1306Spi KEYWORD1 55 | 56 | 57 | ####################################### 58 | # Methods and Functions (KEYWORD2) 59 | ####################################### 60 | allocateBuffer KEYWORD2 61 | init KEYWORD2 62 | resetDisplay KEYWORD2 63 | setColor KEYWORD2 64 | getColor KEYWORD2 65 | setPixel KEYWORD2 66 | setPixelColor KEYWORD2 67 | clearPixel KEYWORD2 68 | drawLine KEYWORD2 69 | drawRect KEYWORD2 70 | fillRect KEYWORD2 71 | drawCircle KEYWORD2 72 | drawCircleQuads KEYWORD2 73 | fillCircle KEYWORD2 74 | fillRing KEYWORD2 75 | drawHorizontalLine KEYWORD2 76 | drawVerticalLine KEYWORD2 77 | drawProgressBar KEYWORD2 78 | drawFastImage KEYWORD2 79 | drawXbm KEYWORD2 80 | drawIco16x16 KEYWORD2 81 | drawString KEYWORD2 82 | drawStringMaxWidth KEYWORD2 83 | getStringWidth KEYWORD2 84 | setTextAlignment KEYWORD2 85 | setFont KEYWORD2 86 | setFontTableLookupFunction KEYWORD2 87 | displayOn KEYWORD2 88 | displayOff KEYWORD2 89 | invertDisplay KEYWORD2 90 | normalDisplay KEYWORD2 91 | setContrast KEYWORD2 92 | setBrightness KEYWORD2 93 | resetOrientation KEYWORD2 94 | flipScreenVertically KEYWORD2 95 | mirrorScreen KEYWORD2 96 | display KEYWORD2 97 | setLogBuffer KEYWORD2 98 | drawLogBuffer KEYWORD2 99 | getWidth KEYWORD2 100 | getHeight KEYWORD2 101 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################################################### 2 | # Syntax Coloring Map For Farm-Data-Relay-System 3 | ####################################################################### 4 | # 5 | # Format for each line: 6 | # KEYWORD KEYWORD_TOKENTYPE REFERENCE_LINK RSYNTAXTEXTAREA_TOKENTYPE 7 | # (only the first two are used) 8 | # 9 | ####################################################################### 10 | 11 | 12 | ####################################################################### 13 | # Datatypes and Class names (KEYWORD1) 14 | ####################################################################### 15 | DataReading KEYWORD1 16 | SystemPacket KEYWORD1 17 | FDRSBase KEYWORD1 18 | FDRSLoRa KEYWORD1 19 | FDRS_EspNow KEYWORD1 20 | 21 | ####################################################################### 22 | # Methods and Functions (KEYWORD2) 23 | ####################################################################### 24 | FDRS_DBG KEYWORD2 25 | begin KEYWORD2 26 | beginFDRS KEYWORD2 27 | begin_espnow KEYWORD2 28 | begin_FS KEYWORD2 29 | begin_lora KEYWORD2 30 | begin_SD KEYWORD2 31 | bufferESPNOW KEYWORD2 32 | bufferLoRa KEYWORD2 33 | bufferMQTT KEYWORD2 34 | bufferSerial KEYWORD2 35 | crc16_update KEYWORD2 36 | getLoRa KEYWORD2 37 | getSerial KEYWORD2 38 | handleCommands KEYWORD2 39 | load KEYWORD2 40 | loadFDRS KEYWORD2 41 | OnDataSent KEYWORD2 42 | OnDataRecv KEYWORD2 43 | pingFDRS KEYWORD2 44 | printLoraPacket KEYWORD2 45 | reconnect KEYWORD2 46 | releaseLogBuffer KEYWORD2 47 | releaseMQTT KEYWORD2 48 | sendESPNOW KEYWORD2 49 | sendFDRS KEYWORD2 50 | sendLog KEYWORD2 51 | sendMQTT KEYWORD2 52 | sendSerial KEYWORD2 53 | sleep KEYWORD2 54 | sleepFDRS KEYWORD2 55 | transmitLoRa KEYWORD2 56 | 57 | ####################################################################### 58 | # structures (KEYWORD3) 59 | ####################################################################### 60 | 61 | 62 | ####################################################################### 63 | # Literals (LITERAL1) 64 | ####################################################################### 65 | DEBUG_CONFIG LITERAL1 66 | DEEP_SLEEP LITERAL1 67 | FDRS_BAND LITERAL1 68 | FDRS_DEBUG LITERAL1 69 | FDRS_GLOBALS LITERAL1 70 | FDRS_SF LITERAL1 71 | GTWY_MAC LITERAL1 72 | GTWY_MAC LITERAL1 73 | LORA_DIO0 LITERAL1 74 | LORA_RST LITERAL1 75 | LORA_SS LITERAL1 76 | MAC_PREFIX LITERAL1 77 | POWER_CTRL LITERAL1 78 | READING_ID LITERAL1 79 | SPI_MISO LITERAL1 80 | SPI_MOSI LITERAL1 81 | SPI_SCK LITERAL1 82 | UNIT_MAC LITERAL1 83 | USE_LORA LITERAL1 84 | 85 | ####################################################################### 86 | # ? (LITERAL2) 87 | ####################################################################### 88 | -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/examples/SSD1306TwoScreenDemo/SSD1306TwoScreenDemo.ino: -------------------------------------------------------------------------------- 1 | /** 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2018 by ThingPulse, Daniel Eichhorn 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | ThingPulse invests considerable time and money to develop these open source libraries. 25 | Please support us by buying our products (and not the clones) from 26 | https://thingpulse.com 27 | 28 | */ 29 | 30 | // Include the correct display library 31 | // For a connection via I2C using Wire include 32 | #include // Only needed for Arduino 1.6.5 and earlier 33 | #include "SSD1306Wire.h" // legacy include: `#include "SSD1306.h"` 34 | #include "images.h" 35 | 36 | // Initialize the OLED display using Wire library 37 | SSD1306Wire display(0x3c, 0, 14); 38 | SSD1306Wire display2(0x3c, 5, 4); 39 | 40 | void setup() { 41 | Serial.begin(115200); 42 | Serial.println(); 43 | Serial.println(); 44 | 45 | 46 | // Initialising the UI will init the display too. 47 | display.init(); 48 | display2.init(); 49 | 50 | // This will make sure that multiple instances of a display driver 51 | // running on different ports will work together transparently 52 | display.setI2cAutoInit(true); 53 | display2.setI2cAutoInit(true); 54 | 55 | display.flipScreenVertically(); 56 | display.setFont(ArialMT_Plain_10); 57 | display.setTextAlignment(TEXT_ALIGN_LEFT); 58 | 59 | display2.flipScreenVertically(); 60 | display2.setFont(ArialMT_Plain_10); 61 | display2.setTextAlignment(TEXT_ALIGN_LEFT); 62 | 63 | } 64 | 65 | void loop() { 66 | display.clear(); 67 | display.drawString(0, 0, "Hello world: " + String(millis())); 68 | display.display(); 69 | 70 | display2.clear(); 71 | display2.drawString(0, 0, "Hello world: " + String(millis())); 72 | display2.display(); 73 | 74 | delay(10); 75 | } 76 | -------------------------------------------------------------------------------- /src/fdrs_globals.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | 3 | // Global Configuration 4 | 5 | // Developed by Timm Bogner (timmbogner@gmail.com) in Urbana, Illinois, USA. 6 | #ifndef __FDRS_GLOBALS_h__ 7 | #define __FDRS_GLOBALS_h__ 8 | 9 | #define GLOBAL_DBG_LEVEL 0 10 | 11 | 12 | #define GLOBAL_WIFI_SSID "Your SSID" 13 | #define GLOBAL_WIFI_PASS "Password" 14 | 15 | #define GLOBAL_DNS1_IPADDRESS "8.8.8.8" // Default to Google Primary DNS 16 | #define GLOBAL_DNS2_IPADDRESS "8.8.4.4" // Default to Google Secondary DNS 17 | 18 | #define GLOBAL_MQTT_ADDR "192.168.0.8" 19 | #define GLOBAL_MQTT_PORT 1883 20 | 21 | //#define GLOBAL_MQTT_AUTH //uncomment to enable MQTT authentication 22 | #define GLOBAL_MQTT_USER "Your MQTT Username" 23 | #define GLOBAL_MQTT_PASS "Your MQTT Password" 24 | // MQTT Topics 25 | #define GLOBAL_TOPIC_DATA "fdrs/data" 26 | #define GLOBAL_TOPIC_STATUS "fdrs/status" 27 | #define GLOBAL_TOPIC_COMMAND "fdrs/command" 28 | 29 | // NTP Time Server 30 | #define GLOBAL_DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 31 | #define GLOBAL_TIME_SERVER "0.us.pool.ntp.org" 32 | #define GLOBAL_STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 33 | #define GLOBAL_DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 34 | #define GLOBAL_TIME_FETCHNTP 60 // Time in minutes between fetching time from NTP server 35 | #define GLOBAL_TIME_PRINTTIME 15 // Time in minutes between printing local time 36 | #define GLOBAL_TIME_SEND_INTERVAL 60 // Time in minutes between sending out time 37 | 38 | #define GLOBAL_LORA_FREQUENCY 915.0 // Carrier frequency in MHz. Allowed values range from 137.0 MHz to 1020.0 MHz (varies by chip). 39 | #define GLOBAL_LORA_SF 7 // LoRa link spreading factor. Allowed values range from 6 to 12. 40 | #define GLOBAL_LORA_BANDWIDTH 125.0 // LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz. 41 | #define GLOBAL_LORA_CR 5 // LoRa link coding rate denominator. Allowed values range from 5 to 8. 42 | #define GLOBAL_LORA_SYNCWORD 0x12 // LoRa sync word. Can be used to distinguish different LoRa networks. Note that 0x34 is reserved for LoRaWAN. 43 | #define GLOBAL_LORA_INTERVAL 5000 // Interval between LoRa buffer releases. Must be longer than transmission time-on-air. 44 | 45 | #define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE // MAC address prefix. Can be used to distinguish different ESP-NOW networks. 46 | 47 | #if defined(USE_OLED) || defined(USE_RTC_DS3231) || defined(USE_RTC_DS1307) 48 | #define USE_I2C 49 | #endif 50 | 51 | #if defined(USE_RTC_DS3231) || defined(USE_RTC_DS1307) 52 | #define USE_RTC 53 | #endif 54 | 55 | #if defined(USE_GPS) && defined(ESP8266) 56 | #error "For ESP8266 only one UART has both Tx and Rx capabilities. GPS not supported for ESP8266" 57 | #endif 58 | 59 | #if defined(USE_ETHERNET) && !defined(ESP32) 60 | #error "Ethernet only supported for ESP32." 61 | #endif 62 | 63 | #if defined(USE_OLED) && (!defined(ESP32) && !defined(ESP8266)) 64 | #warning "OLED current supported for only ESP32 or ESP8266." 65 | #undef USE_OLED 66 | #endif 67 | 68 | #endif // __FDRS_GLOBALS_h__ 69 | -------------------------------------------------------------------------------- /examples/Sensor_Examples/LilyGo_HiGrow_32/LilyGo_HiGrow_32.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // LILYGO HIGROW SENSOR MODULE 4 | // 5 | 6 | 7 | #define I2C_SDA 25 8 | #define I2C_SCL 26 9 | #define DHT12_PIN 16 10 | #define BAT_ADC 33 11 | #define SALT_PIN 34 12 | #define SOIL_PIN 32 13 | #define BOOT_PIN 0 14 | #define USER_BUTTON 35 15 | #define DS18B20_PIN 21 16 | 17 | #include "fdrs_node_config.h" 18 | #include 19 | #include 20 | #include 21 | 22 | BH1750 lightMeter(0x23); //0x23 23 | Adafruit_BME280 bme; //0x77 24 | RTC_DATA_ATTR int the_count = 0; 25 | 26 | void setup() { 27 | beginFDRS(); 28 | 29 | //Init Sensors 30 | Wire.begin(I2C_SDA, I2C_SCL); 31 | // while (!bme.begin()) { 32 | // Serial.println("bme"); 33 | // delay(10); 34 | // } 35 | 36 | if (lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE)) { 37 | Serial.println(F("BH1750 Advanced begin")); 38 | } else { 39 | Serial.println(F("Error initialising BH1750")); 40 | } 41 | 42 | } 43 | 44 | void loadData() { 45 | float s_battery = readBattery(); 46 | // float bme_temp = bme.readTemperature(); 47 | // float bme_pressure = (bme.readPressure() / 100.0F); 48 | //float bme_altitude = bme.readAltitude(1013.25); 49 | // float bme_humidity = bme.readHumidity(); 50 | float s_soil = readSoil(); 51 | float s_salt = readSalt(); 52 | while (! lightMeter.measurementReady()) { 53 | delay(10); 54 | } 55 | float lux = lightMeter.readLightLevel(); 56 | the_count++; 57 | 58 | Serial.println(); 59 | // Serial.println("Temp: " + String(bme_temp)); 60 | // Serial.println("Humidity: " + String(bme_humidity)); 61 | Serial.println("Light: " + String(lux)); 62 | // Serial.println("Pressure: " + String(bme_pressure)); 63 | Serial.println("Salt: " + String(s_salt)); 64 | Serial.println("Soil: " + String(s_soil)); 65 | Serial.println("Voltage: " + String(s_battery)); 66 | Serial.println("Count: " + String(the_count)); 67 | 68 | // loadFDRS(bme_temp, TEMP_T); 69 | 70 | // loadFDRS(bme_humidity, HUMIDITY_T); 71 | 72 | 73 | loadFDRS(lux, LIGHT_T); 74 | // loadFDRS(bme_pressure, PRESSURE_T); 75 | loadFDRS(s_salt, SOILR_T); 76 | loadFDRS(s_soil, SOIL_T); 77 | loadFDRS(s_battery, VOLTAGE_T); 78 | loadFDRS(float(the_count), IT_T); 79 | 80 | } 81 | 82 | uint32_t readSalt() //Soil Electrodes: This code came from the LilyGo documentation. 83 | { 84 | uint8_t samples = 120; 85 | uint32_t humi = 0; 86 | uint16_t array[120]; 87 | for (int i = 0; i < samples; i++) { 88 | array[i] = analogRead(SALT_PIN); 89 | delay(2); 90 | } 91 | std::sort(array, array + samples); 92 | for (int i = 0; i < samples; i++) { 93 | if (i == 0 || i == samples - 1)continue; 94 | humi += array[i]; 95 | } 96 | humi /= samples - 2; 97 | return humi; 98 | } 99 | 100 | uint16_t readSoil() //Soil Capacitance 101 | { 102 | uint16_t soil = analogRead(SOIL_PIN); 103 | return soil; 104 | } 105 | 106 | float readBattery() //Battery Voltage: This code came from the LilyGo documentation. 107 | { 108 | int vref = 1100; 109 | uint16_t volt = analogRead(BAT_ADC); 110 | float battery_voltage = ((float)volt / 4095.0) * 2.0 * 3.3 * (vref); 111 | return battery_voltage; 112 | } 113 | void loop() { 114 | loadData(); 115 | sendFDRS(); 116 | sleepFDRS(30); 117 | } 118 | -------------------------------------------------------------------------------- /examples/Controller_examples/FastLED/FastLED.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // FastLED Lantern 4 | // 5 | // Developed by Timm Bogner (timmbogner@gmail.com) in Urbana, Illinois, USA. 6 | // Rest in Peace, Daniel Garcia. Thank you for bringing so much light to the world! 7 | 8 | // Type 9 | // 1: Red 10 | // 2: Green 11 | // 3: Blue 12 | // 4: Hue 13 | // 5: Saturation 14 | // 6: Brightness 15 | // 7: Sleep time (minutes) 16 | // 17 | 18 | // #define USE_PWM //If using an RGB LED 19 | // #define PIN_R 18 //ESP32 WeMos 20 | // #define PIN_G 19 21 | // #define PIN_B 23 22 | #define PIN_R 14 //8266 WeMos 23 | #define PIN_G 12 24 | #define PIN_B 13 25 | 26 | #define PIN_DATA 4 // If using a NeoPixel 27 | #define NUM_LEDS 24 // Number of physical LEDs. 28 | 29 | #include 30 | #include "fdrs_node_config.h" 31 | #include 32 | 33 | CRGB rgb_color = CRGB::Black; 34 | CHSV hsv_color(0, 255, 255); 35 | bool hsv_mode = false; 36 | bool new_data = false; 37 | 38 | CRGB leds[NUM_LEDS]; 39 | 40 | void fdrs_recv_cb(DataReading theData) { 41 | 42 | new_data = true; 43 | int id = (int)theData.id; 44 | uint8_t type = (uint8_t)theData.t; 45 | uint8_t data = (uint8_t)theData.d; 46 | switch (type) { 47 | case 1: 48 | rgb_color.red = data; 49 | hsv_mode = false; 50 | break; 51 | case 2: 52 | rgb_color.green = data; 53 | hsv_mode = false; 54 | break; 55 | case 3: 56 | rgb_color.blue = data; 57 | hsv_mode = false; 58 | break; 59 | case 4: 60 | hsv_color.hue = data; 61 | hsv_mode = true; 62 | break; 63 | case 5: 64 | hsv_color.sat = data; 65 | hsv_mode = true; 66 | break; 67 | case 6: 68 | hsv_color.val = data; 69 | hsv_mode = true; 70 | break; 71 | case 7: 72 | sleepFDRS(data * 60); 73 | break; 74 | } 75 | } 76 | void setup_pwm() { 77 | #ifdef ESP8266 78 | pinMode(PIN_R, OUTPUT); 79 | pinMode(PIN_G, OUTPUT); 80 | pinMode(PIN_B, OUTPUT); 81 | #endif 82 | #ifdef ESP32 83 | ledcSetup(0, 5000, 8); 84 | ledcSetup(1, 5000, 8); 85 | ledcSetup(2, 5000, 8); 86 | ledcAttachPin(PIN_R, 0); 87 | ledcAttachPin(PIN_G, 1); 88 | ledcAttachPin(PIN_B, 2); 89 | #endif 90 | } 91 | 92 | void set_color(CRGB new_color) { 93 | #ifdef USE_PWM 94 | #ifdef ESP8266 95 | analogWrite(PIN_R, new_color.r); 96 | analogWrite(PIN_G, new_color.g); 97 | analogWrite(PIN_B, new_color.b); 98 | #elif ESP32 99 | ledcWrite(0, new_color.r); 100 | ledcWrite(1, new_color.g); 101 | ledcWrite(2, new_color.b); 102 | #endif 103 | #else 104 | fill_solid(leds, NUM_LEDS, new_color); 105 | FastLED.show(); 106 | #endif // USE_PWM 107 | } 108 | 109 | void color_bars() { 110 | set_color(CRGB::Red); 111 | delay(250); 112 | set_color(CRGB::Green); 113 | delay(250); 114 | set_color(CRGB::Blue); 115 | delay(250); 116 | set_color(CRGB::Black); 117 | } 118 | 119 | void setup() { 120 | #ifdef USE_PWM 121 | setup_pwm(); 122 | #else 123 | FastLED.addLeds(leds, NUM_LEDS); 124 | #endif 125 | color_bars(); 126 | 127 | beginFDRS(); 128 | addFDRS(1000, fdrs_recv_cb); 129 | subscribeFDRS(READING_ID); 130 | subscribeFDRS(0); 131 | } 132 | void loop() { 133 | loopFDRS(); 134 | if (new_data) { 135 | new_data = false; 136 | if (hsv_mode) { 137 | set_color(hsv_color); 138 | } else { 139 | set_color(rgb_color); 140 | } 141 | } 142 | } -------------------------------------------------------------------------------- /examples/Gateway_Examples/Repeater_Voltage/fdrs_gateway_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // GATEWAY CONFIGURATION 4 | 5 | //Addresses 6 | #define UNIT_MAC 0x02 // The address of this gateway 7 | 8 | #define ESPNOW_NEIGHBOR_1 0x01 // Address of ESP-NOW neighbor #1 9 | #define ESPNOW_NEIGHBOR_2 0x04 // Address of ESP-NOW neighbor #2 10 | #define LORA_NEIGHBOR_1 0x00 // Address of LoRa neighbor #1 11 | #define LORA_NEIGHBOR_2 0x00 // Address of LoRa neighbor #2 12 | 13 | // Interfaces 14 | #define USE_ESPNOW 15 | //#define USE_LORA 16 | //#define USE_WIFI // Will cause errors if used with ESP-NOW. Use a serial link instead! 17 | //#define USE_ETHERNET 18 | 19 | // Routing 20 | // Options: sendESPNowNbr(1 or 2); sendESPNowPeers(); sendLoRaNbr(1 or 2); broadcastLoRa(); sendSerial(); sendMQTT(); 21 | #define ESPNOWG_ACT sendESPNowNbr(1); 22 | #define LORAG_ACT 23 | #define SERIAL_ACT 24 | #define MQTT_ACT 25 | #define INTERNAL_ACT sendESPNowNbr(1); 26 | #define ESPNOW1_ACT sendESPNowNbr(2); sendESPNowPeers(); 27 | #define ESPNOW2_ACT sendESPNowNbr(1); 28 | #define LORA1_ACT 29 | #define LORA2_ACT 30 | 31 | // LoRa Configuration 32 | #define RADIOLIB_MODULE SX1276 33 | #define LORA_SS 18 34 | #define LORA_RST 14 35 | #define LORA_DIO 26 36 | #define LORA_BUSY 33 37 | //#define USE_SX126X 38 | 39 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 40 | 41 | //#define CUSTOM_SPI 42 | #define LORA_SPI_SCK 5 43 | #define LORA_SPI_MISO 19 44 | #define LORA_SPI_MOSI 27 45 | 46 | #define FDRS_DEBUG // Enable USB-Serial debugging 47 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 48 | 49 | // I2C - OLED or RTC 50 | #define I2C_SDA 4 51 | #define I2C_SCL 15 52 | 53 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 54 | ///#define USE_OLED 55 | #define OLED_HEADER "FDRS" 56 | #define OLED_PAGE_SECS 30 57 | #define OLED_RST 16 58 | 59 | // RTC - I2C 60 | // #define USE_RTC_DS3231 61 | // #define RTC_ADDR 0x57 62 | // #define USE_RTC_DS1307 63 | // #define RTC_ADDR 0x68 64 | 65 | // UART data interface pins (if available) 66 | #define RXD2 14 67 | #define TXD2 15 68 | 69 | //#define USE_LR // Use ESP-NOW LR mode (ESP32 only) 70 | 71 | // WiFi and MQTT Credentials -- These will override the global settings 72 | //#define WIFI_SSID "Your SSID" 73 | //#define WIFI_PASS "Your Password" 74 | 75 | // MQTT Settings 76 | // #define MQTT_ADDR "192.168.0.8" 77 | // #define MQTT_PORT 1883 // Default MQTT port is 1883 78 | // #define MQTT_AUTH //Enable MQTT authentication 79 | // #define MQTT_USER "Your MQTT Username" 80 | // #define MQTT_PASS "Your MQTT Password" 81 | // #define TOPIC_DATA "fdrs/data" 82 | // #define TOPIC_STATUS "fdrs/status" 83 | // #define TOPIC_COMMAND "fdrs/command" 84 | 85 | // NTP Time settings for gateways 86 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 87 | #define TIME_SERVER "0.us.pool.ntp.org" // NTP time server to use. If FQDN at least one DNS server is required to resolve name 88 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 89 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 90 | #define TIME_FETCHNTP 60 // Time, in minutes, between fetching time from NTP server 91 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug 92 | #define TIME_SEND_INTERVAL 10 // Time, in minutes, between sending out time to remote devices. 0 will only send when time is updated -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/examples/SSD1306ScrollVerticalDemo/SSD1306ScrollVerticalDemo.ino: -------------------------------------------------------------------------------- 1 | /** 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2022 by Stefan Seyfried 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | // Include the correct display library 26 | // For a connection via I2C using Wire include 27 | #include // Only needed for Arduino 1.6.5 and earlier 28 | #include "SSD1306Wire.h" // legacy include: `#include "SSD1306.h"` 29 | // or #include "SH1106Wire.h", legacy include: `#include "SH1106.h"` 30 | // For a connection via I2C using brzo_i2c (must be installed) include 31 | // #include // Only needed for Arduino 1.6.5 and earlier 32 | // #include "SSD1306Brzo.h" 33 | // #include "SH1106Brzo.h" 34 | // For a connection via SPI include 35 | // #include // Only needed for Arduino 1.6.5 and earlier 36 | // #include "SSD1306Spi.h" 37 | // #include "SH1106Spi.h" 38 | 39 | // Use the corresponding display class: 40 | 41 | // Initialize the OLED display using SPI 42 | // D5 -> CLK 43 | // D7 -> MOSI (DOUT) 44 | // D0 -> RES 45 | // D2 -> DC 46 | // D8 -> CS 47 | // SSD1306Spi display(D0, D2, D8); 48 | // or 49 | // SH1106Spi display(D0, D2); 50 | 51 | // Initialize the OLED display using brzo_i2c 52 | // D3 -> SDA 53 | // D5 -> SCL 54 | // SSD1306Brzo display(0x3c, D3, D5); 55 | // or 56 | // SH1106Brzo display(0x3c, D3, D5); 57 | 58 | // Initialize the OLED display using Wire library 59 | SSD1306Wire display(0x3c, SDA, SCL); // ADDRESS, SDA, SCL - SDA and SCL usually populate automatically based on your board's pins_arduino.h e.g. https://github.com/esp8266/Arduino/blob/master/variants/nodemcu/pins_arduino.h 60 | // SH1106Wire display(0x3c, SDA, SCL); 61 | 62 | // UTF-8 sprinkled within, because it tests special conditions in the char-counting code 63 | const String loremipsum = "Lorem ipsum dolor sit ämet, " 64 | "consetetur sadipscing elitr, sed diam nonümy eirmöd " 65 | "tempor invidunt ut labore et dolore mägnä aliquyam erat, " 66 | "sed diam voluptua. At vero eos et accusam et justo duo " 67 | "dolores et ea rebum. Stet clita kasd gubergren, no sea " 68 | "takimata sanctus est Lorem ipsum dolor sit amet. " 69 | "äöü-ÄÖÜ/߀é/çØ."; 70 | 71 | void setup() { 72 | display.init(); 73 | display.setContrast(255); 74 | display.setTextAlignment(TEXT_ALIGN_LEFT); 75 | display.setFont(ArialMT_Plain_16); 76 | display.display(); 77 | } 78 | 79 | void loop() { 80 | static uint16_t start_at = 0; 81 | display.clear(); 82 | uint16_t firstline = display.drawStringMaxWidth(0, 0, 128, loremipsum.substring(start_at)); 83 | display.display(); 84 | if (firstline != 0) { 85 | start_at += firstline; 86 | } else { 87 | start_at = 0; 88 | delay(1000); // additional pause before going back to start 89 | } 90 | delay(1000); 91 | } 92 | -------------------------------------------------------------------------------- /examples/0_MQTT_Gateway/fdrs_gateway_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // GATEWAY CONFIGURATION 4 | 5 | //Addresses 6 | #define UNIT_MAC 0x00 // The address of this gateway 7 | 8 | #define ESPNOW_NEIGHBOR_1 0x00 // Address of ESP-NOW neighbor #1 9 | #define ESPNOW_NEIGHBOR_2 0x00 // Address of ESP-NOW neighbor #2 10 | #define LORA_NEIGHBOR_1 0x00 // Address of LoRa neighbor #1 11 | #define LORA_NEIGHBOR_2 0x00 // Address of LoRa neighbor #2 12 | 13 | // Interfaces 14 | //#define USE_ESPNOW 15 | //#define USE_LORA 16 | #define USE_WIFI // Will cause errors if used with ESP-NOW. Use a serial link instead! 17 | //#define USE_ETHERNET 18 | 19 | // Routing 20 | // Options: sendESPNowNbr(1 or 2); sendESPNowPeers(); sendLoRaNbr(1 or 2); broadcastLoRa(); sendSerial(); sendMQTT(); 21 | #define ESPNOWG_ACT 22 | #define LORAG_ACT 23 | #define SERIAL_ACT sendMQTT(); 24 | #define MQTT_ACT sendSerial(); 25 | #define INTERNAL_ACT sendMQTT(); 26 | #define ESPNOW1_ACT 27 | #define ESPNOW2_ACT 28 | #define LORA1_ACT 29 | #define LORA2_ACT 30 | 31 | // LoRa Configuration 32 | #define RADIOLIB_MODULE SX1276 33 | #define LORA_SS 18 34 | #define LORA_RST 14 35 | #define LORA_DIO 26 36 | #define LORA_BUSY 33 37 | //#define USE_SX126X 38 | 39 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 40 | 41 | //#define CUSTOM_SPI 42 | #define LORA_SPI_SCK 5 43 | #define LORA_SPI_MISO 19 44 | #define LORA_SPI_MOSI 27 45 | 46 | #define FDRS_DEBUG // Enable USB-Serial debugging 47 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 48 | 49 | // I2C - OLED or RTC 50 | #define I2C_SDA 4 51 | #define I2C_SCL 15 52 | 53 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 54 | ///#define USE_OLED 55 | #define OLED_HEADER "FDRS" 56 | #define OLED_PAGE_SECS 30 57 | #define OLED_RST 16 58 | 59 | // RTC - I2C 60 | // #define USE_RTC_DS3231 61 | // #define RTC_ADDR 0x57 62 | // #define USE_RTC_DS1307 63 | // #define RTC_ADDR 0x68 64 | 65 | // UART data interface pins (ESP32 only) 66 | //#define RXD2 14 67 | //#define TXD2 15 68 | 69 | //#define USE_LR // Use ESP-NOW LR mode (ESP32 only) 70 | 71 | // WiFi and MQTT Credentials -- These will override the global settings 72 | //#define WIFI_SSID "Your SSID" 73 | //#define WIFI_PASS "Your Password" 74 | 75 | // Use Static IP Address for WiFi connections 76 | // #define USE_STATIC_IPADDRESS 77 | // #define HOST_IPADDRESS "192.168.0.100" 78 | // #define GW_IPADDRESS "192.168.0.1" 79 | // #define SUBNET_ADDRESS "255.255.255.0" 80 | // #define DNS1_IPADDRESS "192.168.0.1" 81 | // #define DNS2_IPADDRESS "192.168.0.2" 82 | 83 | // MQTT Settings 84 | // #define MQTT_ADDR "192.168.0.8" 85 | // #define MQTT_PORT 1883 // Default MQTT port is 1883 86 | // #define MQTT_AUTH //Enable MQTT authentication 87 | // #define MQTT_USER "Your MQTT Username" 88 | // #define MQTT_PASS "Your MQTT Password" 89 | // #define TOPIC_DATA "fdrs/data" 90 | // #define TOPIC_STATUS "fdrs/status" 91 | // #define TOPIC_COMMAND "fdrs/command" 92 | 93 | // NTP Time settings for gateways 94 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 95 | #define TIME_SERVER "0.us.pool.ntp.org" // NTP time server to use. If FQDN at least one DNS server is required to resolve name 96 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 97 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 98 | #define TIME_FETCHNTP 60 // Time, in minutes, between fetching time from NTP server 99 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug 100 | #define TIME_SEND_INTERVAL 10 // Time, in minutes, between sending out time to remote devices. 0 will only send when time is updated -------------------------------------------------------------------------------- /examples/3_LoRa_Repeater/fdrs_gateway_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // GATEWAY CONFIGURATION 4 | 5 | //Addresses 6 | #define UNIT_MAC 0x03 // The address of this gateway 7 | 8 | #define ESPNOW_NEIGHBOR_1 0x00 // Address of ESP-NOW neighbor #1 9 | #define ESPNOW_NEIGHBOR_2 0x00 // Address of ESP-NOW neighbor #2 10 | #define LORA_NEIGHBOR_1 0x01 // Address of LoRa neighbor #1 11 | #define LORA_NEIGHBOR_2 0x05 // Address of LoRa neighbor #2 12 | 13 | // Interfaces 14 | //#define USE_ESPNOW 15 | #define USE_LORA 16 | //#define USE_WIFI // Will cause errors if used with ESP-NOW. Use a serial link instead! 17 | //#define USE_ETHERNET 18 | 19 | // Routing 20 | // Options: sendESPNowNbr(1 or 2); sendESPNowPeers(); sendLoRaNbr(1 or 2); broadcastLoRa(); sendSerial(); sendMQTT(); 21 | #define ESPNOWG_ACT 22 | #define LORAG_ACT sendLoRaNbr(1); 23 | #define SERIAL_ACT 24 | #define MQTT_ACT 25 | #define INTERNAL_ACT sendLoRaNbr(1); 26 | #define ESPNOW1_ACT 27 | #define ESPNOW2_ACT 28 | #define LORA1_ACT sendLoRaNbr(2); broadcastLoRa(); 29 | #define LORA2_ACT sendLoRaNbr(1); 30 | 31 | // LoRa Configuration 32 | #define RADIOLIB_MODULE SX1276 33 | #define LORA_SS 18 34 | #define LORA_RST 14 35 | #define LORA_DIO 26 36 | #define LORA_BUSY 33 37 | //#define USE_SX126X 38 | 39 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 40 | 41 | //#define CUSTOM_SPI 42 | #define LORA_SPI_SCK 5 43 | #define LORA_SPI_MISO 19 44 | #define LORA_SPI_MOSI 27 45 | 46 | #define FDRS_DEBUG // Enable USB-Serial debugging 47 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 48 | 49 | // I2C - OLED or RTC 50 | #define I2C_SDA 4 51 | #define I2C_SCL 15 52 | 53 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 54 | ///#define USE_OLED 55 | #define OLED_HEADER "FDRS" 56 | #define OLED_PAGE_SECS 30 57 | #define OLED_RST 16 58 | 59 | // RTC - I2C 60 | // #define USE_RTC_DS3231 61 | // #define RTC_ADDR 0x57 62 | // #define USE_RTC_DS1307 63 | // #define RTC_ADDR 0x68 64 | 65 | // UART data interface pins (ESP32 only) 66 | //#define RXD2 14 67 | //#define TXD2 15 68 | 69 | //#define USE_LR // Use ESP-NOW LR mode (ESP32 only) 70 | 71 | // WiFi and MQTT Credentials -- These will override the global settings 72 | //#define WIFI_SSID "Your SSID" 73 | //#define WIFI_PASS "Your Password" 74 | 75 | // Use Static IP Address for WiFi connections 76 | // #define USE_STATIC_IPADDRESS 77 | // #define HOST_IPADDRESS "192.168.0.100" 78 | // #define GW_IPADDRESS "192.168.0.1" 79 | // #define SUBNET_ADDRESS "255.255.255.0" 80 | // #define DNS1_IPADDRESS "192.168.0.1" 81 | // #define DNS2_IPADDRESS "192.168.0.2" 82 | 83 | // MQTT Settings 84 | // #define MQTT_ADDR "192.168.0.8" 85 | // #define MQTT_PORT 1883 // Default MQTT port is 1883 86 | // #define MQTT_AUTH //Enable MQTT authentication 87 | // #define MQTT_USER "Your MQTT Username" 88 | // #define MQTT_PASS "Your MQTT Password" 89 | // #define TOPIC_DATA "fdrs/data" 90 | // #define TOPIC_STATUS "fdrs/status" 91 | // #define TOPIC_COMMAND "fdrs/command" 92 | 93 | /// NTP Time settings for gateways 94 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 95 | #define TIME_SERVER "0.us.pool.ntp.org" // NTP time server to use. If FQDN at least one DNS server is required to resolve name 96 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 97 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 98 | #define TIME_FETCHNTP 60 // Time, in minutes, between fetching time from NTP server 99 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug 100 | #define TIME_SEND_INTERVAL 10 // Time, in minutes, between sending out time to remote devices. 0 will only send when time is updated -------------------------------------------------------------------------------- /examples/2_ESPNOW_Repeater/fdrs_gateway_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // GATEWAY CONFIGURATION 4 | 5 | //Addresses 6 | #define UNIT_MAC 0x02 // The address of this gateway 7 | 8 | #define ESPNOW_NEIGHBOR_1 0x01 // Address of ESP-NOW neighbor #1 9 | #define ESPNOW_NEIGHBOR_2 0x04 // Address of ESP-NOW neighbor #2 10 | #define LORA_NEIGHBOR_1 0x00 // Address of LoRa neighbor #1 11 | #define LORA_NEIGHBOR_2 0x00 // Address of LoRa neighbor #2 12 | 13 | // Interfaces 14 | #define USE_ESPNOW 15 | //#define USE_LORA 16 | //#define USE_WIFI // Will cause errors if used with ESP-NOW. Use a serial link instead! 17 | //#define USE_ETHERNET 18 | 19 | // Routing 20 | // Options: sendESPNowNbr(1 or 2); sendESPNowPeers(); sendLoRaNbr(1 or 2); broadcastLoRa(); sendSerial(); sendMQTT(); 21 | #define ESPNOWG_ACT sendESPNowNbr(1); 22 | #define LORAG_ACT 23 | #define SERIAL_ACT 24 | #define MQTT_ACT 25 | #define INTERNAL_ACT sendESPNowNbr(1); 26 | #define ESPNOW1_ACT sendESPNowNbr(2); sendESPNowPeers(); 27 | #define ESPNOW2_ACT sendESPNowNbr(1); 28 | #define LORA1_ACT 29 | #define LORA2_ACT 30 | 31 | // LoRa Configuration 32 | #define RADIOLIB_MODULE SX1276 33 | #define LORA_SS 18 34 | #define LORA_RST 14 35 | #define LORA_DIO 26 36 | #define LORA_BUSY 33 37 | //#define USE_SX126X 38 | 39 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 40 | 41 | //#define CUSTOM_SPI 42 | #define LORA_SPI_SCK 5 43 | #define LORA_SPI_MISO 19 44 | #define LORA_SPI_MOSI 27 45 | 46 | #define FDRS_DEBUG // Enable USB-Serial debugging 47 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 48 | 49 | // I2C - OLED or RTC 50 | #define I2C_SDA 4 51 | #define I2C_SCL 15 52 | 53 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 54 | ///#define USE_OLED 55 | #define OLED_HEADER "FDRS" 56 | #define OLED_PAGE_SECS 30 57 | #define OLED_RST 16 58 | 59 | // RTC - I2C 60 | // #define USE_RTC_DS3231 61 | // #define RTC_ADDR 0x57 62 | // #define USE_RTC_DS1307 63 | // #define RTC_ADDR 0x68 64 | 65 | // UART data interface pins (ESP32 only) 66 | //#define RXD2 14 67 | //#define TXD2 15 68 | 69 | //#define USE_LR // Use ESP-NOW LR mode (ESP32 only) 70 | 71 | // WiFi and MQTT Credentials -- These will override the global settings 72 | //#define WIFI_SSID "Your SSID" 73 | //#define WIFI_PASS "Your Password" 74 | 75 | // Use Static IP Address for WiFi connections 76 | // #define USE_STATIC_IPADDRESS 77 | // #define HOST_IPADDRESS "192.168.0.100" 78 | // #define GW_IPADDRESS "192.168.0.1" 79 | // #define SUBNET_ADDRESS "255.255.255.0" 80 | // #define DNS1_IPADDRESS "192.168.0.1" 81 | // #define DNS2_IPADDRESS "192.168.0.2" 82 | 83 | // MQTT Settings 84 | // #define MQTT_ADDR "192.168.0.8" 85 | // #define MQTT_PORT 1883 // Default MQTT port is 1883 86 | // #define MQTT_AUTH //Enable MQTT authentication 87 | // #define MQTT_USER "Your MQTT Username" 88 | // #define MQTT_PASS "Your MQTT Password" 89 | // #define TOPIC_DATA "fdrs/data" 90 | // #define TOPIC_STATUS "fdrs/status" 91 | // #define TOPIC_COMMAND "fdrs/command" 92 | 93 | // NTP Time settings for gateways 94 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 95 | #define TIME_SERVER "0.us.pool.ntp.org" // NTP time server to use. If FQDN at least one DNS server is required to resolve name 96 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 97 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 98 | #define TIME_FETCHNTP 60 // Time, in minutes, between fetching time from NTP server 99 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug 100 | #define TIME_SEND_INTERVAL 10 // Time, in minutes, between sending out time to remote devices. 0 will only send when time is updated -------------------------------------------------------------------------------- /examples/Gateway_Examples/1_MQTT_Gateway_Ethernet/fdrs_gateway_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // ETHERNET GATEWAY CONFIGURATION 4 | 5 | //Addresses 6 | #define UNIT_MAC 0x01 // The address of this gateway 7 | 8 | #define ESPNOW_NEIGHBOR_1 0x00 // Address of ESP-NOW neighbor #1 9 | #define ESPNOW_NEIGHBOR_2 0x02 // Address of ESP-NOW neighbor #2 10 | #define LORA_NEIGHBOR_1 0x00 // Address of LoRa neighbor #1 11 | #define LORA_NEIGHBOR_2 0x00 // Address of LoRa neighbor #2 12 | 13 | // Interfaces 14 | #define USE_ESPNOW 15 | //#define USE_LORA 16 | //#define USE_WIFI // Will cause errors if used with ESP-NOW. Use a serial link instead! 17 | #define USE_ETHERNET 18 | 19 | // Routing 20 | // Options: sendESPNowNbr(1 or 2); sendESPNowPeers(); sendLoRaNbr(1 or 2); broadcastLoRa(); sendSerial(); sendMQTT(); 21 | #define ESPNOWG_ACT sendMQTT(); 22 | #define LORAG_ACT 23 | #define SERIAL_ACT sendESPNowNbr(2); sendESPNowPeers(); 24 | #define MQTT_ACT 25 | #define INTERNAL_ACT sendMQTT(); 26 | #define ESPNOW1_ACT 27 | #define ESPNOW2_ACT sendMQTT(); 28 | #define LORA1_ACT 29 | #define LORA2_ACT 30 | 31 | // LoRa Configuration 32 | #define RADIOLIB_MODULE SX1276 33 | #define LORA_SS 18 34 | #define LORA_RST 14 35 | #define LORA_DIO 26 36 | #define LORA_BUSY 33 37 | //#define USE_SX126X 38 | 39 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 40 | 41 | //#define CUSTOM_SPI 42 | #define LORA_SPI_SCK 5 43 | #define LORA_SPI_MISO 19 44 | #define LORA_SPI_MOSI 27 45 | 46 | #define FDRS_DEBUG // Enable USB-Serial debugging 47 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 48 | 49 | // I2C - OLED or RTC 50 | #define I2C_SDA 4 51 | #define I2C_SCL 15 52 | 53 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 54 | ///#define USE_OLED 55 | #define OLED_HEADER "FDRS" 56 | #define OLED_PAGE_SECS 30 57 | #define OLED_RST 16 58 | 59 | // RTC - I2C 60 | // #define USE_RTC_DS3231 61 | // #define RTC_ADDR 0x57 62 | // #define USE_RTC_DS1307 63 | // #define RTC_ADDR 0x68 64 | 65 | // UART data interface pins (ESP32 only) 66 | //#define RXD2 14 67 | //#define TXD2 15 68 | 69 | //#define USE_LR // Use ESP-NOW LR mode (ESP32 only) 70 | 71 | // WiFi and MQTT Credentials -- These will override the global settings 72 | //#define WIFI_SSID "Your SSID" 73 | //#define WIFI_PASS "Your Password" 74 | 75 | // Use Static IP Address for WiFi connections 76 | // #define USE_STATIC_IPADDRESS 77 | // #define HOST_IPADDRESS "192.168.0.100" 78 | // #define GW_IPADDRESS "192.168.0.1" 79 | // #define SUBNET_ADDRESS "255.255.255.0" 80 | // #define DNS1_IPADDRESS "192.168.0.1" 81 | // #define DNS2_IPADDRESS "192.168.0.2" 82 | 83 | // MQTT Settings 84 | // #define MQTT_ADDR "192.168.0.8" 85 | // #define MQTT_PORT 1883 // Default MQTT port is 1883 86 | // #define MQTT_AUTH //Enable MQTT authentication 87 | // #define MQTT_USER "Your MQTT Username" 88 | // #define MQTT_PASS "Your MQTT Password" 89 | // #define TOPIC_DATA "fdrs/data" 90 | // #define TOPIC_STATUS "fdrs/status" 91 | // #define TOPIC_COMMAND "fdrs/command" 92 | 93 | // NTP Time settings for gateways 94 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 95 | #define TIME_SERVER "0.us.pool.ntp.org" // NTP time server to use. If FQDN at least one DNS server is required to resolve name 96 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 97 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 98 | #define TIME_FETCHNTP 60 // Time, in minutes, between fetching time from NTP server 99 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug 100 | #define TIME_SEND_INTERVAL 10 // Time, in minutes, between sending out time to remote devices. 0 will only send when time is updated -------------------------------------------------------------------------------- /examples/1_UART_Gateway/fdrs_gateway_config.h: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // GATEWAY CONFIGURATION 4 | 5 | //Addresses 6 | #define UNIT_MAC 0x01 // The address of this gateway 7 | 8 | #define ESPNOW_NEIGHBOR_1 0x00 // Address of ESP-NOW neighbor #1 9 | #define ESPNOW_NEIGHBOR_2 0x02 // Address of ESP-NOW neighbor #2 10 | #define LORA_NEIGHBOR_1 0x00 // Address of LoRa neighbor #1 11 | #define LORA_NEIGHBOR_2 0x03 // Address of LoRa neighbor #2 12 | 13 | // Interfaces 14 | #define USE_ESPNOW 15 | //#define USE_LORA 16 | //#define USE_WIFI // Will cause errors if used with ESP-NOW. Use a serial link instead! 17 | //#define USE_ETHERNET 18 | 19 | // Routing 20 | // Options: sendESPNowNbr(1 or 2); sendESPNowPeers(); sendLoRaNbr(1 or 2); broadcastLoRa(); sendSerial(); sendMQTT(); 21 | #define ESPNOWG_ACT sendSerial(); 22 | #define LORAG_ACT sendSerial(); 23 | #define SERIAL_ACT sendESPNowNbr(2); sendESPNowPeers(); sendLoRaNbr(2); broadcastLoRa(); 24 | #define MQTT_ACT 25 | #define INTERNAL_ACT sendSerial(); 26 | #define ESPNOW1_ACT 27 | #define ESPNOW2_ACT sendSerial(); 28 | #define LORA1_ACT 29 | #define LORA2_ACT sendSerial(); 30 | 31 | // LoRa Configuration 32 | #define RADIOLIB_MODULE SX1276 33 | #define LORA_SS 18 34 | #define LORA_RST 14 35 | #define LORA_DIO 26 36 | #define LORA_BUSY 33 37 | //#define USE_SX126X 38 | 39 | #define LORA_TXPWR 17 // LoRa TX power in dBm (: +2dBm - +17dBm (for SX1276-7) +20dBm (for SX1278)) 40 | 41 | //#define CUSTOM_SPI 42 | #define LORA_SPI_SCK 5 43 | #define LORA_SPI_MISO 19 44 | #define LORA_SPI_MOSI 27 45 | 46 | #define FDRS_DEBUG // Enable USB-Serial debugging 47 | //#define DBG_LEVEL 0 // 0 for minimal messaging, 1 for troubleshooting, 2 for development 48 | 49 | // I2C - OLED or RTC 50 | #define I2C_SDA 4 51 | #define I2C_SCL 15 52 | 53 | // OLED -- Displays console debugging messages on an SSD1306 I²C OLED 54 | ///#define USE_OLED 55 | #define OLED_HEADER "FDRS" 56 | #define OLED_PAGE_SECS 30 57 | #define OLED_RST 16 58 | 59 | // RTC - I2C 60 | // #define USE_RTC_DS3231 61 | // #define RTC_ADDR 0x57 62 | // #define USE_RTC_DS1307 63 | // #define RTC_ADDR 0x68 64 | 65 | // UART data interface pins (ESP32 only) 66 | //#define RXD2 14 67 | //#define TXD2 15 68 | 69 | //#define USE_LR // Use ESP-NOW LR mode (ESP32 only) 70 | 71 | // WiFi and MQTT Credentials -- These will override the global settings 72 | //#define WIFI_SSID "Your SSID" 73 | //#define WIFI_PASS "Your Password" 74 | 75 | // Use Static IP Address for WiFi connections 76 | // #define USE_STATIC_IPADDRESS 77 | // #define HOST_IPADDRESS "192.168.0.100" 78 | // #define GW_IPADDRESS "192.168.0.1" 79 | // #define SUBNET_ADDRESS "255.255.255.0" 80 | // #define DNS1_IPADDRESS "192.168.0.1" 81 | // #define DNS2_IPADDRESS "192.168.0.2" 82 | 83 | // MQTT Settings 84 | // #define MQTT_ADDR "192.168.0.8" 85 | // #define MQTT_PORT 1883 // Default MQTT port is 1883 86 | // #define MQTT_AUTH //Enable MQTT authentication 87 | // #define MQTT_USER "Your MQTT Username" 88 | // #define MQTT_PASS "Your MQTT Password" 89 | // #define TOPIC_DATA "fdrs/data" 90 | // #define TOPIC_STATUS "fdrs/status" 91 | // #define TOPIC_COMMAND "fdrs/command" 92 | 93 | // NTP Time settings for gateways 94 | #define DST_RULE USDST // Daylight saving time rules: Use USDST for United States DST rules, EUDST for European Union 95 | #define TIME_SERVER "0.us.pool.ntp.org" // NTP time server to use. If FQDN at least one DNS server is required to resolve name 96 | #define STD_OFFSET (-6) // Local standard time offset in hours from UTC - if unsure, check https://time.is 97 | #define DST_OFFSET (STD_OFFSET + 1) // Local savings time offset in hours from UTC - if unsure, check https://time.is 98 | #define TIME_FETCHNTP 60 // Time, in minutes, between fetching time from NTP server 99 | #define TIME_PRINTTIME 15 // Time, in minutes, between printing local time to debug 100 | #define TIME_SEND_INTERVAL 10 // Time, in minutes, between sending out time to remote devices. 0 will only send when time is updated -------------------------------------------------------------------------------- /examples/Sensor_Examples/KisssysGypsum/KisssysGypsum.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Gypsum-based Soil Moisture Sensor 4 | // 5 | // Uses a Ezsbc.com Dev board, a Kisssys moisture sensor board, and a DS3231 RTC. 6 | // Deep sleep current is less than 20µA. 7 | // https://www.printables.com/model/176752-gypson-water-sensor 8 | 9 | #define DEBUG 10 | #define CREDENTIALS 11 | 12 | #include "fdrs_node_config.h" 13 | #include 14 | #include 15 | RTC_DS3231 rtc; 16 | 17 | #define BUTTON_PIN_BITMASK 0x100000000 // 2^32 in hex the pin that is connected to SQW 18 | #define CLOCK_INTERRUPT_PIN 32 // yep same pin 19 | //#define SupplyPin 33 // power to DS3231 20 | #define BatteryReadPin 35 // read battey voltage on this pin 21 | 22 | 23 | const int FreqIn1 = 18; // gpio32 24 | const int FreqPower = 19; 25 | const int RTCPower = 25; 26 | volatile uint16_t Freq1 = 0; 27 | static uint16_t FreqOut1; 28 | 29 | void SensorInt1() { 30 | // If the pin is Rising, increment counter 31 | Freq1++; 32 | }; 33 | 34 | 35 | 36 | void setup() { 37 | beginFDRS(); 38 | DBG(__FILE__); 39 | pinMode(FreqIn1, INPUT); 40 | pinMode(CLOCK_INTERRUPT_PIN, INPUT_PULLUP); // On deep sleep the pin needs and external 330k pullup 41 | pinMode(RTCPower, OUTPUT); // for the SQW pin to stay high when RTC power is removed 42 | digitalWrite(RTCPower, HIGH); // DS3231 needs the SQW pullup removed on the board to 43 | pinMode(FreqPower, OUTPUT); // lower the deepsleep current by 60ua's 44 | digitalWrite(FreqPower, HIGH); 45 | 46 | Freq1 = 0; 47 | delay(50); 48 | 49 | Wire.begin(13, 14); // moved from 21 22 normal I2C pins because it allows me to set these pins to input later 50 | if (!rtc.begin()) { 51 | DBG("Couldn't find RTC!"); 52 | Serial.flush(); 53 | while (1) delay(10); 54 | } 55 | 56 | if (rtc.lostPower()) { 57 | // this will adjust to the date and time at compilation 58 | rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); 59 | } 60 | 61 | rtc.disable32K(); // Don't use this so we shut it down on the board 62 | // set alarm 1, 2 flag to false (so alarm 1, 2 didn't happen so far) 63 | // if not done, this easily leads to problems, as both register aren't reset on reboot/recompile 64 | rtc.clearAlarm(1); 65 | rtc.clearAlarm(2); 66 | 67 | // stop oscillating signals at SQW Pin 68 | // otherwise setAlarm1 will fail 69 | rtc.writeSqwPinMode(DS3231_OFF); 70 | 71 | // turn off alarm 2 (in case it isn't off already) 72 | // again, this isn't done at reboot, so a previously set alarm could easily go overlooked 73 | rtc.disableAlarm(2); 74 | 75 | 76 | // for one second we count the pulses and get our moisture reading in pps 77 | attachInterrupt(FreqIn1, SensorInt1, RISING); 78 | delay(1000); // delay in ms is 1 seconds-- not the most accurate way to do this but more than accurate enough for our low frequency and 10 second read 79 | FreqOut1 = Freq1; // our frequency * 10 80 | detachInterrupt(FreqIn1); // only reading once so turn off the interrupt 81 | 82 | 83 | if (rtc.alarmFired(1)) { 84 | rtc.clearAlarm(1); 85 | Serial.println("Alarm cleared"); 86 | } 87 | 88 | float supply = analogRead(BatteryReadPin) * .001833; 89 | DBG("WaterSensor 1 = " + String(FreqOut1)); 90 | DBG("Supply Voltage = " + String(supply)); 91 | 92 | loadFDRS(FreqOut1, SOIL_T); 93 | loadFDRS(supply, VOLTAGE_T); 94 | sendFDRS(); 95 | // Lowers SQW int pin32 every 10 seconds 96 | rtc.setAlarm1(DateTime(0, 0, 0, 00, 00, 10), DS3231_A1_Second); //DateTime (year,month,day,hour,min,sec) 97 | 98 | esp_sleep_enable_ext1_wakeup(BUTTON_PIN_BITMASK, ESP_EXT1_WAKEUP_ALL_LOW); 99 | 100 | char date[10] = "hh:mm:ss"; 101 | rtc.now().toString(date); 102 | Serial.println(date); // Print the time 103 | Serial.println("Going to sleep soon"); 104 | 105 | // prepare for low current shutdown 106 | digitalWrite(FreqPower, LOW); 107 | digitalWrite(RTCPower, LOW); 108 | pinMode(13, INPUT); 109 | pinMode(14, INPUT); 110 | 111 | esp_deep_sleep_start(); 112 | 113 | } 114 | 115 | void loop() { 116 | // nuttin honey 117 | } 118 | -------------------------------------------------------------------------------- /src/fdrs_datatypes.h: -------------------------------------------------------------------------------- 1 | // A list of all datatypes you can use within FDRS. 2 | // If you are missing any data type, please open an issue at: 3 | // https://github.com/timmbogner/Farm-Data-Relay-System/issues 4 | 5 | #ifdef AVR 6 | typedef unsigned int uint; 7 | #endif 8 | 9 | typedef struct FDRSPeer { 10 | uint8_t mac[6]; 11 | uint32_t last_seen = 0; 12 | 13 | } FDRSPeer; 14 | 15 | typedef struct __attribute__((packed)) DataReading { 16 | float d; 17 | uint16_t id; 18 | uint8_t t; 19 | 20 | } DataReading; 21 | 22 | typedef struct __attribute__((packed)) SystemPacket { 23 | uint8_t cmd; 24 | uint32_t param; 25 | } SystemPacket; 26 | 27 | enum crcResult { 28 | CRC_NULL, 29 | CRC_OK, 30 | CRC_BAD, 31 | } returnCRC; 32 | 33 | enum cmd_t { 34 | cmd_clear, 35 | cmd_ping, 36 | cmd_add, 37 | cmd_ack, 38 | cmd_time 39 | }; 40 | 41 | enum ping_t { 42 | ping_request, 43 | ping_reply 44 | }; 45 | 46 | enum commstate_t { 47 | stReady, 48 | stInProcess, 49 | stCrcMismatch, 50 | stCrcMatch, 51 | stInterMessageDelay, 52 | stCompleted 53 | }; 54 | 55 | 56 | enum 57 | { 58 | event_clear, 59 | event_espnowg, 60 | event_espnow1, 61 | event_espnow2, 62 | event_serial, 63 | event_mqtt, 64 | event_lorag, 65 | event_lora1, 66 | event_lora2, 67 | event_internal 68 | }; 69 | 70 | // Interface type that is the time source 71 | enum TmNetIf { 72 | TMIF_NONE, 73 | TMIF_LORA, 74 | TMIF_ESPNOW, 75 | TMIF_SERIAL, 76 | TMIF_LOCAL, 77 | }; 78 | // Local time source that is setting the time 79 | enum TmSource { 80 | TMS_NONE, 81 | TMS_NET, 82 | TMS_RTC, 83 | TMS_NTP, 84 | TMS_GPS, 85 | }; 86 | 87 | struct TimeSource { 88 | TmNetIf tmNetIf; 89 | uint16_t tmAddress; 90 | TmSource tmSource; 91 | unsigned long tmLastTimeSet; 92 | }; 93 | 94 | struct DRRingBuffer { 95 | DataReading *dr; 96 | uint16_t *address; 97 | uint startIdx; 98 | uint endIdx; 99 | uint size; 100 | }; 101 | 102 | struct SPRingBuffer { 103 | SystemPacket *sp; 104 | uint16_t *address; 105 | uint startIdx; 106 | uint endIdx; 107 | uint size; 108 | }; 109 | 110 | struct Ping { 111 | commstate_t status = stReady; 112 | unsigned long start; 113 | uint timeout; 114 | uint16_t address; 115 | uint32_t response = __UINT32_MAX__; 116 | }; 117 | 118 | #ifndef ESP32 119 | typedef int esp_err_t; 120 | #define ESP_FAIL 0 121 | #define ESP_OK 1 122 | #endif 123 | 124 | #ifndef FDRS_DATA_TYPES 125 | #define FDRS_DATA_TYPES 126 | 127 | #define STATUS_T 0 // Status 128 | #define TEMP_T 1 // Temperature 129 | #define TEMP2_T 2 // Temperature #2 130 | #define HUMIDITY_T 3 // Relative Humidity 131 | #define PRESSURE_T 4 // Atmospheric Pressure 132 | #define LIGHT_T 5 // Light (lux) 133 | #define SOIL_T 6 // Soil Moisture 134 | #define SOIL2_T 7 // Soil Moisture #2 135 | #define SOILR_T 8 // Soil Resistance 136 | #define SOILR2_T 9 // Soil Resistance #2 137 | #define OXYGEN_T 10 // Oxygen 138 | #define CO2_T 11 // Carbon Dioxide 139 | #define WINDSPD_T 12 // Wind Speed 140 | #define WINDHDG_T 13 // Wind Direction 141 | #define RAINFALL_T 14 // Rainfall 142 | #define MOTION_T 15 // Motion 143 | #define VOLTAGE_T 16 // Voltage 144 | #define VOLTAGE2_T 17 // Voltage #2 145 | #define CURRENT_T 18 // Current 146 | #define CURRENT2_T 19 // Current #2 147 | #define IT_T 20 // Iterations 148 | #define LATITUDE_T 21 // GPS Latitude 149 | #define LONGITUDE_T 22 // GPS Longitude 150 | #define ALTITUDE_T 23 // GPS Altitude 151 | #define HDOP_T 24 // GPS HDOP 152 | #define LEVEL_T 25 // Fluid Level 153 | #define UV_T 26 // UV 154 | #define PM1_T 27 // 1 Particles 155 | #define PM2_5_T 28 // 2.5 Particles 156 | #define PM10_T 29 // 10 Particles 157 | #define POWER_T 30 // Power 158 | #define POWER2_T 31 // Power #2 159 | #define ENERGY_T 32 // Energy 160 | #define ENERGY2_T 33 // Energy #2 161 | #define WEIGHT_T 34 // Weight 162 | #define WEIGHT2_T 35 // Weight #2 163 | #define NOISE_T 36 // Noise level #1 164 | #define NOISE2_T 37 // Noise level #2 165 | 166 | #endif //FDRS_DATA_TYPES -------------------------------------------------------------------------------- /examples/LoRa_Stress_Test/LoRa_Stress_Test.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // LoRa Stress Tester or "Spammer" 4 | // 5 | // 6 | 7 | #include "fdrs_node_config.h" 8 | #include 9 | 10 | #define PING_TIME_DELAY 300 11 | #define REQ_TIME_DELAY 300 12 | #define LOAD_TIME_DELAY 1000 13 | #define CYCLES 15 14 | unsigned long lastruntime = 0; 15 | int test = 0; 16 | unsigned long lastCycle = 0; 17 | 18 | void setup() { 19 | beginFDRS(); 20 | } 21 | void loop() { 22 | loopFDRS(); 23 | 24 | switch (test) { 25 | case 0: 26 | DBG("Sending pings in quick succession."); 27 | delay(4000); 28 | for(int i=1; i < CYCLES + 1; i) { 29 | if(TDIFF(lastruntime,PING_TIME_DELAY)) { 30 | lastruntime = millis(); 31 | Serial.println(); 32 | DBG("--- Test #" + String(i) + " ---"); 33 | Serial.println(); 34 | pingFDRS(1000); 35 | i++; 36 | } 37 | loopFDRS(); 38 | } 39 | while(millis()-lastruntime < 1000) { 40 | loopFDRS(); 41 | } 42 | test++; 43 | Serial.println(); 44 | Serial.println(); 45 | break; 46 | 47 | case 1: 48 | DBG("Sending time requests in quick succession."); 49 | delay(4000); 50 | for(int i=1; i < CYCLES + 1; i) { 51 | if(TDIFF(lastruntime,REQ_TIME_DELAY)) { 52 | lastruntime = millis(); 53 | Serial.println(); 54 | DBG("--- Test #" + String(i) + " ---"); 55 | Serial.println(); 56 | reqTimeFDRS(); 57 | i++; 58 | } 59 | loopFDRS(); 60 | } 61 | while(millis()-lastruntime < 1000) { 62 | loopFDRS(); 63 | } 64 | test++; 65 | Serial.println(); 66 | Serial.println(); 67 | break; 68 | 69 | case 2: 70 | DBG("No ACK - data cycles in quick succession."); 71 | ack = false; 72 | delay(4000); 73 | for(int i=1; i < CYCLES + 1; i) { 74 | if(TDIFF(lastruntime,LOAD_TIME_DELAY)) { 75 | lastruntime = millis(); 76 | Serial.println(); 77 | DBG("--- Test #" + String(i) + " ---"); 78 | Serial.println(); 79 | for(int j=0; j < i; j++) { 80 | loadFDRS(READING_ID + j, STATUS_T); 81 | } 82 | if(sendFDRS()){ 83 | DBG("Big Success!"); 84 | } else { 85 | DBG("Nope, not so much."); 86 | } 87 | i++; 88 | } 89 | loopFDRS(); 90 | } 91 | while(millis()-lastruntime < 1000) { 92 | loopFDRS(); 93 | } 94 | test++; 95 | Serial.println(); 96 | Serial.println(); 97 | break; 98 | 99 | case 3: 100 | DBG("ACK - data cycles in quick succession."); 101 | ack = true; 102 | delay(4000); 103 | for(int i=1; i < CYCLES + 1; i) { 104 | if(TDIFF(lastruntime,LOAD_TIME_DELAY)) { 105 | lastruntime = millis(); 106 | Serial.println(); 107 | DBG("--- Test #" + String(i) + " ---"); 108 | Serial.println(); 109 | for(int j=0; j < i; j++) { 110 | loadFDRS(READING_ID + j, STATUS_T); 111 | } 112 | if(sendFDRS()){ 113 | DBG("Big Success!"); 114 | } else { 115 | DBG("Nope, not so much."); 116 | } 117 | i++; 118 | } 119 | loopFDRS(); 120 | } 121 | while(millis()-lastruntime < 1000) { 122 | loopFDRS(); 123 | } 124 | test++; 125 | Serial.println(); 126 | Serial.println(); 127 | break; 128 | 129 | case 4: 130 | DBG("Combination of commands in quick succession."); 131 | delay(4000); 132 | for(int i=1; i < CYCLES + 1; i) { 133 | if(TDIFF(lastruntime,5000)) { 134 | lastruntime = millis(); 135 | Serial.println(); 136 | DBG("--- Test #" + String(i) + " ---"); 137 | Serial.println(); 138 | pingFDRS(1000); 139 | reqTimeFDRS(); 140 | subscribeFDRS(READING_ID); 141 | i++; 142 | } 143 | loopFDRS(); 144 | } 145 | while(millis()-lastruntime < 2000) { 146 | loopFDRS(); 147 | } 148 | test++; 149 | Serial.println(); 150 | Serial.println(); 151 | break; 152 | 153 | default: 154 | DBG("DONE! Starting over again soon."); 155 | Serial.println(); 156 | Serial.println(); 157 | delay(4000); 158 | test = 0; 159 | break; 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /src/fdrs_oled.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #define DISPLAY_PAGES 4 5 | 6 | String debug_buffer[5] = {"", "", "", "", ""}; 7 | SSD1306Wire display(0x3c, I2C_SDA, I2C_SCL); // ADDRESS, SDA, SCL 8 | unsigned long displayEvent = 0; 9 | uint8_t displayPage = 0; 10 | 11 | void draw_OLED_header() 12 | { 13 | #ifdef FDRS_GATEWAY 14 | display.setFont(ArialMT_Plain_10); 15 | display.clear(); 16 | display.setTextAlignment(TEXT_ALIGN_LEFT); 17 | display.drawString(0, 0, "MAC: " + String(UNIT_MAC, HEX)); 18 | display.setTextAlignment(TEXT_ALIGN_CENTER); 19 | display.drawString(63, 0, OLED_HEADER); 20 | display.setTextAlignment(TEXT_ALIGN_RIGHT); 21 | display.drawString(127, 0, "TBD"); 22 | display.display(); 23 | display.setTextAlignment(TEXT_ALIGN_LEFT); 24 | display.setFont(ArialMT_Plain_10); 25 | #endif 26 | #ifdef FDRS_NODE 27 | display.setFont(ArialMT_Plain_10); 28 | display.clear(); 29 | display.setTextAlignment(TEXT_ALIGN_LEFT); 30 | display.drawString(0, 0, "ID: " + String(READING_ID)); 31 | display.setTextAlignment(TEXT_ALIGN_CENTER); 32 | display.drawString(63, 0, OLED_HEADER); 33 | display.setTextAlignment(TEXT_ALIGN_RIGHT); 34 | display.drawString(127, 0, "GW: " + String(GTWY_MAC, HEX)); 35 | display.display(); 36 | display.setTextAlignment(TEXT_ALIGN_LEFT); 37 | display.setFont(ArialMT_Plain_10); 38 | #endif 39 | display.drawHorizontalLine(0, 15, 128); 40 | display.drawHorizontalLine(0, 16, 128); 41 | } 42 | 43 | void drawDebugPage() { 44 | draw_OLED_header(); 45 | uint8_t lineNumber = 0; 46 | for (uint8_t i = 0; i < 5; i++) 47 | { 48 | uint8_t ret = display.FDRS_drawStringMaxWidth(0, 17 + (lineNumber * 9), 127, debug_buffer[i]); 49 | lineNumber = ret + lineNumber; 50 | if (lineNumber > 5) 51 | break; 52 | } 53 | display.display(); 54 | } 55 | 56 | void debug_OLED(String debug_text) 57 | { 58 | displayEvent = millis()/1000; // Display Event is tracked in units of seconds 59 | displayPage = 0; 60 | display.clear(); 61 | 62 | for (uint8_t i = 4; i > 0; i--) 63 | { 64 | 65 | debug_buffer[i] = debug_buffer[i - 1]; 66 | } 67 | debug_buffer[0] = String(millis() / 1000) + " " + debug_text; 68 | drawDebugPage(); 69 | } 70 | 71 | void drawBlankPage() { 72 | display.clear(); 73 | display.display(); 74 | } 75 | 76 | void drawStatusPage() { 77 | // draw_OLED_header(); 78 | // display.FDRS_drawStringMaxWidth(0, 17, 127, "Status Page 1 " + String(millis()/1000)); 79 | // display.display(); 80 | } 81 | 82 | void drawPage2() { 83 | // draw_OLED_header(); 84 | // display.FDRS_drawStringMaxWidth(0, 17, 127, "Page 2 " + String(millis()/1000)); 85 | // display.display(); 86 | } 87 | 88 | void drawPage3() { 89 | // draw_OLED_header(); 90 | // display.FDRS_drawStringMaxWidth(0, 17, 127, "Page 3 " + String(millis()/1000)); 91 | // display.display(); 92 | } 93 | 94 | // write display content to display buffer 95 | // nextpage = true -> flip 1 page 96 | // When debug info comes in then switch to debug page 97 | // after 60 seconds switch to blank page to save screen 98 | void drawPageOLED(bool nextpage) { 99 | 100 | if((millis()/1000 - displayEvent) > OLED_PAGE_SECS && nextpage) { 101 | displayPage = (displayPage >= DISPLAY_PAGES) ? 0 : (displayPage + 1); 102 | displayEvent = millis()/1000; 103 | display.clear(); 104 | 105 | switch(displayPage) { 106 | 107 | // page 0: debug output 108 | // page 1: gateway/node status 109 | // page 2: to be defined 110 | // page 3: to be defined 111 | // page 4: blank (screen saver) 112 | 113 | case 0: // display debug output 114 | drawDebugPage(); 115 | break; 116 | case 1: // gateway/node status 117 | // drawStatusPage(); 118 | // break; 119 | case 2: // to be defined later 120 | // drawPage2(); 121 | // break; 122 | case 3: // to be defined later 123 | // drawPage3(); 124 | // break; 125 | case 4: // Blank page 126 | drawBlankPage(); 127 | break; 128 | default: // Blank page 129 | drawBlankPage(); 130 | break; 131 | } 132 | } 133 | } 134 | 135 | void init_oled(){ 136 | pinMode(OLED_RST, OUTPUT); 137 | digitalWrite(OLED_RST, LOW); 138 | delay(30); 139 | digitalWrite(OLED_RST, HIGH); 140 | display.init(); 141 | display.flipScreenVertically(); 142 | draw_OLED_header(); 143 | } -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/examples/SSD1306OTADemo/SSD1306OTADemo.ino: -------------------------------------------------------------------------------- 1 | /** 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2018 by ThingPulse, Daniel Eichhorn 5 | Copyright (c) 2018 by Fabrice Weinberg 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | ThingPulse invests considerable time and money to develop these open source libraries. 26 | Please support us by buying our products (and not the clones) from 27 | https://thingpulse.com 28 | 29 | */ 30 | 31 | #if defined(ESP8266) 32 | #include 33 | #include 34 | #elif defined(ESP32) 35 | #include 36 | #include 37 | #include 38 | #endif 39 | 40 | #include 41 | 42 | const char *ssid = "[Your SSID]"; 43 | const char *password = "[Your Password]"; 44 | 45 | 46 | // Include the correct display library 47 | // For a connection via I2C using Wire include 48 | #include // Only needed for Arduino 1.6.5 and earlier 49 | #include "SSD1306Wire.h" // legacy include: `#include "SSD1306.h"` 50 | // or #include "SH1106Wire.h", legacy include: `#include "SH1106.h"` 51 | // For a connection via I2C using brzo_i2c (must be installed) include 52 | // #include // Only needed for Arduino 1.6.5 and earlier 53 | // #include "SSD1306Brzo.h" 54 | // #include "SH1106Brzo.h" 55 | // For a connection via SPI include 56 | // #include // Only needed for Arduino 1.6.5 and earlier 57 | // #include "SSD1306Spi.h" 58 | // #include "SH1106SPi.h" 59 | 60 | // Use the corresponding display class: 61 | 62 | // Initialize the OLED display using SPI 63 | // D5 -> CLK 64 | // D7 -> MOSI (DOUT) 65 | // D0 -> RES 66 | // D2 -> DC 67 | // D8 -> CS 68 | // SSD1306Spi display(D0, D2, D8); 69 | // or 70 | // SH1106Spi display(D0, D2); 71 | 72 | // Initialize the OLED display using brzo_i2c 73 | // D3 -> SDA 74 | // D5 -> SCL 75 | // SSD1306Brzo display(0x3c, D3, D5); 76 | // or 77 | // SH1106Brzo display(0x3c, D3, D5); 78 | 79 | // Initialize the OLED display using Wire library 80 | SSD1306Wire display(0x3c, SDA, SCL); // ADDRESS, SDA, SCL - SDA and SCL usually populate automatically based on your board's pins_arduino.h e.g. https://github.com/esp8266/Arduino/blob/master/variants/nodemcu/pins_arduino.h 81 | // SH1106Wire display(0x3c, SDA, SCL); 82 | 83 | 84 | void setup() { 85 | WiFi.begin ( ssid, password ); 86 | 87 | // Wait for connection 88 | while ( WiFi.status() != WL_CONNECTED ) { 89 | delay ( 10 ); 90 | } 91 | 92 | display.init(); 93 | display.flipScreenVertically(); 94 | display.setContrast(255); 95 | 96 | ArduinoOTA.begin(); 97 | ArduinoOTA.onStart([]() { 98 | display.clear(); 99 | display.setFont(ArialMT_Plain_10); 100 | display.setTextAlignment(TEXT_ALIGN_CENTER_BOTH); 101 | display.drawString(display.getWidth() / 2, display.getHeight() / 2 - 10, "OTA Update"); 102 | display.display(); 103 | }); 104 | 105 | ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { 106 | display.drawProgressBar(4, 32, 120, 8, progress / (total / 100) ); 107 | display.display(); 108 | }); 109 | 110 | ArduinoOTA.onEnd([]() { 111 | display.clear(); 112 | display.setFont(ArialMT_Plain_10); 113 | display.setTextAlignment(TEXT_ALIGN_CENTER_BOTH); 114 | display.drawString(display.getWidth() / 2, display.getHeight() / 2, "Restart"); 115 | display.display(); 116 | }); 117 | 118 | // Align text vertical/horizontal center 119 | display.setTextAlignment(TEXT_ALIGN_CENTER_BOTH); 120 | display.setFont(ArialMT_Plain_10); 121 | display.drawString(display.getWidth() / 2, display.getHeight() / 2, "Ready for OTA:\n" + WiFi.localIP().toString()); 122 | display.display(); 123 | } 124 | 125 | void loop() { 126 | ArduinoOTA.handle(); 127 | } 128 | -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/src/SH1106Brzo.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 by ThingPulse, Daniel Eichhorn 5 | * Copyright (c) 2018 by Fabrice Weinberg 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | * 25 | * ThingPulse invests considerable time and money to develop these open source libraries. 26 | * Please support us by buying our products (and not the clones) from 27 | * https://thingpulse.com 28 | * 29 | */ 30 | 31 | #ifndef SH1106Brzo_h 32 | #define SH1106Brzo_h 33 | 34 | #include "OLEDDisplay.h" 35 | #include 36 | 37 | #if F_CPU == 160000000L 38 | #define BRZO_I2C_SPEED 1000 39 | #else 40 | #define BRZO_I2C_SPEED 800 41 | #endif 42 | 43 | class SH1106Brzo : public OLEDDisplay { 44 | private: 45 | uint8_t _address; 46 | uint8_t _sda; 47 | uint8_t _scl; 48 | 49 | public: 50 | SH1106Brzo(uint8_t _address, uint8_t _sda, uint8_t _scl, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64) { 51 | setGeometry(g); 52 | 53 | this->_address = _address; 54 | this->_sda = _sda; 55 | this->_scl = _scl; 56 | } 57 | 58 | bool connect(){ 59 | brzo_i2c_setup(_sda, _scl, 0); 60 | return true; 61 | } 62 | 63 | void display(void) { 64 | #ifdef OLEDDISPLAY_DOUBLE_BUFFER 65 | uint8_t minBoundY = UINT8_MAX; 66 | uint8_t maxBoundY = 0; 67 | 68 | uint8_t minBoundX = UINT8_MAX; 69 | uint8_t maxBoundX = 0; 70 | uint8_t x, y; 71 | 72 | // Calculate the Y bounding box of changes 73 | // and copy buffer[pos] to buffer_back[pos]; 74 | for (y = 0; y < (displayHeight / 8); y++) { 75 | for (x = 0; x < displayWidth; x++) { 76 | uint16_t pos = x + y * displayWidth; 77 | if (buffer[pos] != buffer_back[pos]) { 78 | minBoundY = _min(minBoundY, y); 79 | maxBoundY = _max(maxBoundY, y); 80 | minBoundX = _min(minBoundX, x); 81 | maxBoundX = _max(maxBoundX, x); 82 | } 83 | buffer_back[pos] = buffer[pos]; 84 | } 85 | yield(); 86 | } 87 | 88 | // If the minBoundY wasn't updated 89 | // we can savely assume that buffer_back[pos] == buffer[pos] 90 | // holdes true for all values of pos 91 | if (minBoundY == UINT8_MAX) return; 92 | 93 | byte k = 0; 94 | uint8_t sendBuffer[17]; 95 | sendBuffer[0] = 0x40; 96 | 97 | // Calculate the colum offset 98 | uint8_t minBoundXp2H = (minBoundX + 2) & 0x0F; 99 | uint8_t minBoundXp2L = 0x10 | ((minBoundX + 2) >> 4 ); 100 | 101 | brzo_i2c_start_transaction(this->_address, BRZO_I2C_SPEED); 102 | 103 | for (y = minBoundY; y <= maxBoundY; y++) { 104 | sendCommand(0xB0 + y); 105 | sendCommand(minBoundXp2H); 106 | sendCommand(minBoundXp2L); 107 | for (x = minBoundX; x <= maxBoundX; x++) { 108 | k++; 109 | sendBuffer[k] = buffer[x + y * displayWidth]; 110 | if (k == 16) { 111 | brzo_i2c_write(sendBuffer, 17, true); 112 | k = 0; 113 | } 114 | } 115 | if (k != 0) { 116 | brzo_i2c_write(sendBuffer, k + 1, true); 117 | k = 0; 118 | } 119 | yield(); 120 | } 121 | if (k != 0) { 122 | brzo_i2c_write(sendBuffer, k + 1, true); 123 | } 124 | brzo_i2c_end_transaction(); 125 | #else 126 | #endif 127 | } 128 | 129 | private: 130 | int getBufferOffset(void) { 131 | return 0; 132 | } 133 | inline void sendCommand(uint8_t com) __attribute__((always_inline)){ 134 | uint8_t command[2] = {0x80 /* command mode */, com}; 135 | brzo_i2c_start_transaction(_address, BRZO_I2C_SPEED); 136 | brzo_i2c_write(command, 2, true); 137 | brzo_i2c_end_transaction(); 138 | } 139 | }; 140 | 141 | #endif 142 | -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to ThingPulse OLED SSD1306 2 | 3 | :+1::tada: First off, thanks for taking the time to contribute! :tada::+1: 4 | 5 | The following is a set of guidelines for contributing to the ThingPulse OLED SSD1306 library on GitHub. These are just guidelines, not rules, use your best judgment and feel free to propose changes to this document in a pull request. 6 | 7 | It is appreciated if you raise an issue _before_ you start changing the code, discussing the proposed change; emphasizing that you are proposing to develop the patch yourself, and outlining the strategy for implementation. This type of discussion is what we should be doing on the issues list and it is better to do this before or in parallel to developing the patch rather than having "you should have done it this way" type of feedback on the PR itself. 8 | 9 | ### Table Of Contents 10 | * [General remarks](#general-remarks) 11 | * [Writing Documentation](#writing-documentation) 12 | * [Working with Git and GitHub](#working-with-git-and-github) 13 | * [General flow](#general-flow) 14 | * [Keeping your fork in sync](#keeping-your-fork-in-sync) 15 | * [Commit messages](#commit-messages) 16 | 17 | ## General remarks 18 | We are a friendly and welcoming community and look forward to your contributions. Once your contribution is integrated into this repository we feel responsible for it. Therefore, be prepared for constructive feedback. Before we merge anything we need to ensure that it fits in and is consistent with the rest of code. 19 | If you made something really cool but won't spend the time to integrate it into this upstream project please still share it in your fork on GitHub. If you mention it in an issue we'll take a look at it anyway. 20 | 21 | ## Writing Documentation 22 | ThingPulse maintains documentation for its products at [https://github.com/thingpulse/docs/](https://github.com/thingpulse/docs/). If you contribute features for this project that require altering the respective product guide then we ask you to prepare a pull request with the necessary documentation changes as well. 23 | 24 | ## Working with Git and GitHub 25 | 26 | Avoid intermediate merge commits. [Rebase](https://www.atlassian.com/git/tutorials/merging-vs-rebasing) your feature branch onto `master` to pull updates and verify your local changes against them before placing the pull request. 27 | 28 | ### General flow 29 | 1. [Fork](https://help.github.com/articles/fork-a-repo) this repository on GitHub. 30 | 1. [Create a branch](https://help.github.com/articles/creating-and-deleting-branches-within-your-repository/#creating-a-branch) in your fork on GitHub **based on the `master` branch**. 31 | 1. Clone the fork on your machine with `git clone https://github.com//.git` 32 | 1. `cd ` then run `git remote add upstream https://github.com/ThingPulse/esp8266-oled-ssd1306` 33 | 1. `git checkout ` 34 | 1. Make changes to the code base and commit them using e.g. `git commit -a -m 'Look ma, I did it'` 35 | 1. When you're done bring your fork up-to-date with the upstream repo ([see below](#keeping-your-fork-in-sync)). Then rebase your branch on `master` running `git rebase master`. 36 | 1. `git push` 37 | 1. [Create a pull request](https://help.github.com/articles/creating-a-pull-request/) (PR) on GitHub. 38 | 39 | This is just one way of doing things. If you're proficient in Git matters you're free to choose your own. If you want to read more then the [GitHub chapter in the Git book](http://git-scm.com/book/en/v2/GitHub-Contributing-to-a-Project#The-GitHub-Flow) is a way to start. [GitHub's own documentation](https://help.github.com/categories/collaborating/) contains a wealth of information as well. 40 | 41 | ### Keeping your fork in sync 42 | You need to sync your fork with the upstream repository from time to time, latest before you rebase (see flow above). 43 | 44 | 1. `git fetch upstream` 45 | 1. `git checkout master` 46 | 1. `git merge upstream/master` 47 | 48 | ### Commit messages 49 | 50 | From: [http://git-scm.com/book/ch5-2.html](http://git-scm.com/book/ch5-2.html) 51 |
52 | Short (50 chars or less) summary of changes
53 | 
54 | More detailed explanatory text, if necessary.  Wrap it to about 72
55 | characters or so.  In some contexts, the first line is treated as the
56 | subject of an email and the rest of the text as the body.  The blank
57 | line separating the summary from the body is critical (unless you omit
58 | the body entirely); tools like rebase can get confused if you run the
59 | two together.
60 | 
61 | Further paragraphs come after blank lines.
62 | 
63 | - Bullet points are okay, too
64 | - Typically a hyphen or asterisk is used for the bullet, preceded by a
65 |    single space, with blank lines in between, but conventions vary here
66 | 
67 | 68 | Don't forget to [reference affected issues](https://help.github.com/articles/closing-issues-via-commit-messages/) in the commit message to have them closed automatically on GitHub. 69 | 70 | [Amend](https://help.github.com/articles/changing-a-commit-message/) your commit messages if necessary to make sure what the world sees on GitHub is as expressive and meaningful as possible. 71 | -------------------------------------------------------------------------------- /examples/Controller_examples/Irrigation/Irrigation.ino: -------------------------------------------------------------------------------- 1 | // FARM DATA RELAY SYSTEM 2 | // 3 | // Irrigation Controller 4 | // 5 | // Developed by Timm Bogner (timmbogner@gmail.com) in Urbana, Illinois, USA. 6 | // 7 | // 8 | #include "fdrs_node_config.h" 9 | #include 10 | 11 | #define CONTROL_1 101 //Address for controller 1 12 | #define CONTROL_2 102 //Address for controller 2 13 | #define CONTROL_3 103 //Address for controller 3 14 | #define CONTROL_4 104 //Address for controller 4 15 | 16 | #define COIL_1 4 //Coil Pin 1 17 | #define COIL_2 5 //Coil Pin 2 18 | #define COIL_3 13 //Coil Pin 3 19 | #define COIL_4 14 //Coil Pin 4 20 | 21 | int status_1 = 0; 22 | int status_2 = 0; 23 | int status_3 = 0; 24 | int status_4 = 0; 25 | 26 | bool isData = false; 27 | bool newStatus = false; 28 | 29 | void fdrs_recv_cb(DataReading theData) { 30 | DBG(String(theData.id)); 31 | switch (theData.t) { 32 | case 0: // Incoming command is to SET a value 33 | 34 | switch (theData.id) { 35 | case CONTROL_1: 36 | status_1 = (int)theData.d; 37 | isData = true; 38 | break; 39 | case CONTROL_2: 40 | status_2 = (int)theData.d; 41 | isData = true; 42 | break; 43 | case CONTROL_3: 44 | status_3 = (int)theData.d; 45 | isData = true; 46 | break; 47 | case CONTROL_4: 48 | status_4 = (int)theData.d; 49 | isData = true; 50 | break; 51 | } 52 | break; 53 | 54 | case 1: // Incoming command is to GET a value 55 | switch (theData.id) { 56 | case CONTROL_1: 57 | if (digitalRead(COIL_1) == HIGH) { 58 | loadFDRS(1, STATUS_T, CONTROL_1); 59 | } else { 60 | loadFDRS(0, STATUS_T, CONTROL_1); 61 | } 62 | break; 63 | case CONTROL_2: 64 | if (digitalRead(COIL_2) == HIGH) { 65 | loadFDRS(1, STATUS_T, CONTROL_2); 66 | } else { 67 | loadFDRS(0, STATUS_T, CONTROL_2); 68 | } 69 | break; 70 | case CONTROL_3: 71 | if (digitalRead(COIL_3) == HIGH) { 72 | loadFDRS(1, STATUS_T, CONTROL_3); 73 | } else { 74 | loadFDRS(0, STATUS_T, CONTROL_3); 75 | } 76 | break; 77 | case CONTROL_4: 78 | if (digitalRead(COIL_4) == HIGH) { 79 | loadFDRS(1, STATUS_T, CONTROL_4); 80 | } else { 81 | loadFDRS(0, STATUS_T, CONTROL_4); 82 | } 83 | break; 84 | } 85 | newStatus = true; 86 | break; 87 | } 88 | } 89 | 90 | void checkCoils() { // Sends back a status report for each coil pin. 91 | if (digitalRead(COIL_1) == HIGH) { 92 | loadFDRS(1, STATUS_T, CONTROL_1); 93 | } else { 94 | loadFDRS(0, STATUS_T, CONTROL_1); 95 | } 96 | if (digitalRead(COIL_2) == HIGH) { 97 | loadFDRS(1, STATUS_T, CONTROL_2); 98 | } else { 99 | loadFDRS(0, STATUS_T, CONTROL_2); 100 | } 101 | if (digitalRead(COIL_3) == HIGH) { 102 | loadFDRS(1, STATUS_T, CONTROL_3); 103 | } else { 104 | loadFDRS(0, STATUS_T, CONTROL_3); 105 | } 106 | if (digitalRead(COIL_4) == HIGH) { 107 | loadFDRS(1, STATUS_T, CONTROL_4); 108 | } else { 109 | loadFDRS(0, STATUS_T, CONTROL_4); 110 | } 111 | if (sendFDRS()) { 112 | DBG("Packet received by gateway"); 113 | } else { 114 | DBG("Unable to communicate with gateway!"); 115 | } 116 | } 117 | 118 | void updateCoils() { //These are set up for relay module which are active-LOW. Swap 'HIGH'and 'LOW' in this function to use the inverse. 119 | if (status_1) { 120 | digitalWrite(COIL_1, LOW); 121 | } else { 122 | digitalWrite(COIL_1, HIGH); 123 | } 124 | if (status_2) { 125 | digitalWrite(COIL_2, LOW); 126 | } else { 127 | digitalWrite(COIL_2, HIGH); 128 | } 129 | if (status_3) { 130 | digitalWrite(COIL_3, LOW); 131 | } else { 132 | digitalWrite(COIL_3, HIGH); 133 | } 134 | if (status_4) { 135 | digitalWrite(COIL_4, LOW); 136 | } else { 137 | digitalWrite(COIL_4, HIGH); 138 | } 139 | } 140 | 141 | void setup() { 142 | beginFDRS(); 143 | pingFDRS(1000); 144 | if (addFDRS(1000, fdrs_recv_cb)) { 145 | subscribeFDRS(CONTROL_1); 146 | subscribeFDRS(CONTROL_2); 147 | subscribeFDRS(CONTROL_3); 148 | subscribeFDRS(CONTROL_4); 149 | } else { 150 | DBG("Not Connected"); 151 | } 152 | pinMode(COIL_1, OUTPUT); 153 | digitalWrite(COIL_1, HIGH); 154 | pinMode(COIL_2, OUTPUT); 155 | digitalWrite(COIL_2, HIGH); 156 | pinMode(COIL_3, OUTPUT); 157 | digitalWrite(COIL_3, HIGH); 158 | pinMode(COIL_4, OUTPUT); 159 | digitalWrite(COIL_4, HIGH); 160 | 161 | DBG("FARM DATA RELAY SYSTEM :: Irrigation Module"); 162 | } 163 | 164 | void loop() { 165 | loopFDRS(); 166 | if (isData) { 167 | isData = false; 168 | updateCoils(); 169 | checkCoils(); 170 | } 171 | if (newStatus) { 172 | newStatus = false; 173 | if (sendFDRS()) { 174 | DBG("Packet received by gateway"); 175 | } else { 176 | DBG("Unable to communicate with gateway!"); 177 | } 178 | } 179 | } -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/src/SH1106Spi.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 by ThingPulse, Daniel Eichhorn 5 | * Copyright (c) 2018 by Fabrice Weinberg 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | * 25 | * ThingPulse invests considerable time and money to develop these open source libraries. 26 | * Please support us by buying our products (and not the clones) from 27 | * https://thingpulse.com 28 | * 29 | */ 30 | 31 | #ifndef SH1106Spi_h 32 | #define SH1106Spi_h 33 | 34 | #include "OLEDDisplay.h" 35 | #include 36 | 37 | class SH1106Spi : public OLEDDisplay { 38 | private: 39 | uint8_t _rst; 40 | uint8_t _dc; 41 | uint8_t _cs; 42 | 43 | public: 44 | SH1106Spi(uint8_t _rst, uint8_t _dc, uint8_t _cs, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64) { 45 | setGeometry(g); 46 | 47 | this->_rst = _rst; 48 | this->_dc = _dc; 49 | this->_cs = _cs; 50 | } 51 | 52 | bool connect(){ 53 | pinMode(_dc, OUTPUT); 54 | pinMode(_cs, OUTPUT); 55 | pinMode(_rst, OUTPUT); 56 | 57 | SPI.begin (); 58 | SPI.setClockDivider (SPI_CLOCK_DIV2); 59 | 60 | // Pulse Reset low for 10ms 61 | digitalWrite(_rst, HIGH); 62 | delay(1); 63 | digitalWrite(_rst, LOW); 64 | delay(10); 65 | digitalWrite(_rst, HIGH); 66 | return true; 67 | } 68 | 69 | void display(void) { 70 | #ifdef OLEDDISPLAY_DOUBLE_BUFFER 71 | uint8_t minBoundY = UINT8_MAX; 72 | uint8_t maxBoundY = 0; 73 | 74 | uint8_t minBoundX = UINT8_MAX; 75 | uint8_t maxBoundX = 0; 76 | 77 | uint8_t x, y; 78 | 79 | // Calculate the Y bounding box of changes 80 | // and copy buffer[pos] to buffer_back[pos]; 81 | for (y = 0; y < (displayHeight / 8); y++) { 82 | for (x = 0; x < displayWidth; x++) { 83 | uint16_t pos = x + y * displayWidth; 84 | if (buffer[pos] != buffer_back[pos]) { 85 | minBoundY = _min(minBoundY, y); 86 | maxBoundY = _max(maxBoundY, y); 87 | minBoundX = _min(minBoundX, x); 88 | maxBoundX = _max(maxBoundX, x); 89 | } 90 | buffer_back[pos] = buffer[pos]; 91 | } 92 | yield(); 93 | } 94 | 95 | // If the minBoundY wasn't updated 96 | // we can savely assume that buffer_back[pos] == buffer[pos] 97 | // holdes true for all values of pos 98 | if (minBoundY == UINT8_MAX) return; 99 | 100 | // Calculate the colum offset 101 | uint8_t minBoundXp2H = (minBoundX + 2) & 0x0F; 102 | uint8_t minBoundXp2L = 0x10 | ((minBoundX + 2) >> 4 ); 103 | 104 | for (y = minBoundY; y <= maxBoundY; y++) { 105 | sendCommand(0xB0 + y); 106 | sendCommand(minBoundXp2H); 107 | sendCommand(minBoundXp2L); 108 | digitalWrite(_cs, HIGH); 109 | digitalWrite(_dc, HIGH); // data mode 110 | digitalWrite(_cs, LOW); 111 | for (x = minBoundX; x <= maxBoundX; x++) { 112 | SPI.transfer(buffer[x + y * displayWidth]); 113 | } 114 | digitalWrite(_cs, HIGH); 115 | yield(); 116 | } 117 | #else 118 | for (uint8_t y=0; ysetTextAlignment(TEXT_ALIGN_CENTER); 100 | display->setFont(ArialMT_Plain_10); 101 | // stage->process contains the text of the current progress e.q. "Connect to WiFi" 102 | display->drawString(64, 18, stage->process); 103 | // you could just print the current process without the progress bar 104 | display->drawString(64, 28, progress); 105 | } 106 | ``` 107 | 108 | After defining a function like that, you can pass it to the Ui library by use 109 | `ui.setLoadingDrawFunction(myLoadingDraw)`. 110 | 111 | 112 | ### Text Logging 113 | 114 | It is always useful to display some text on the display without worrying to much 115 | where it goes and managing it. In 3.0 we made the `OLEDDisplay` class implement 116 | [`Print`](https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/Print.h) 117 | so you can use it like you would use `Serial`. We calls this feature `LogBuffer` 118 | and the only thing you have to do is to define how many lines you want to display 119 | and how many characters there are on average on each. This is done by calling 120 | `setLogBuffer(lines, chars);`. If there is not enough memory the function will 121 | return false. 122 | 123 | After that you can draw the `LogBuffer` anywhere you want by calling `drawLogBuffer(x, y)`. 124 | (Note: You have to call `display()` to update the screen) 125 | We made a [video](https://www.youtube.com/watch?v=8Fiss77A3TE) showing this feature in action. 126 | -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/src/SSD1306I2C.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 by Helmut Tschemernjak - www.radioshuttle.de 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | * ThingPulse invests considerable time and money to develop these open source libraries. 25 | * Please support us by buying our products (and not the clones) from 26 | * https://thingpulse.com 27 | * 28 | */ 29 | 30 | #ifndef SSD1306I2C_h 31 | #define SSD1306I2C_h 32 | 33 | 34 | #ifdef __MBED__ 35 | 36 | #include "OLEDDisplay.h" 37 | #include 38 | 39 | #ifndef UINT8_MAX 40 | #define UINT8_MAX 0xff 41 | #endif 42 | 43 | class SSD1306I2C : public OLEDDisplay { 44 | public: 45 | SSD1306I2C(uint8_t _address, PinName _sda, PinName _scl, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64) { 46 | setGeometry(g); 47 | 48 | this->_address = _address << 1; // convert from 7 to 8 bit for mbed. 49 | this->_sda = _sda; 50 | this->_scl = _scl; 51 | _i2c = new I2C(_sda, _scl); 52 | } 53 | 54 | bool connect() { 55 | // mbed supports 100k and 400k some device maybe 1000k 56 | #ifdef TARGET_STM32L4 57 | _i2c->frequency(1000000); 58 | #else 59 | _i2c->frequency(400000); 60 | #endif 61 | return true; 62 | } 63 | 64 | void display(void) { 65 | const int x_offset = (128 - this->width()) / 2; 66 | #ifdef OLEDDISPLAY_DOUBLE_BUFFER 67 | uint8_t minBoundY = UINT8_MAX; 68 | uint8_t maxBoundY = 0; 69 | 70 | uint8_t minBoundX = UINT8_MAX; 71 | uint8_t maxBoundX = 0; 72 | uint8_t x, y; 73 | 74 | // Calculate the Y bounding box of changes 75 | // and copy buffer[pos] to buffer_back[pos]; 76 | for (y = 0; y < (this->height() / 8); y++) { 77 | for (x = 0; x < this->width(); x++) { 78 | uint16_t pos = x + y * this->width(); 79 | if (buffer[pos] != buffer_back[pos]) { 80 | minBoundY = std::min(minBoundY, y); 81 | maxBoundY = std::max(maxBoundY, y); 82 | minBoundX = std::min(minBoundX, x); 83 | maxBoundX = std::max(maxBoundX, x); 84 | } 85 | buffer_back[pos] = buffer[pos]; 86 | } 87 | yield(); 88 | } 89 | 90 | // If the minBoundY wasn't updated 91 | // we can savely assume that buffer_back[pos] == buffer[pos] 92 | // holdes true for all values of pos 93 | 94 | if (minBoundY == UINT8_MAX) return; 95 | 96 | sendCommand(COLUMNADDR); 97 | sendCommand(x_offset + minBoundX); // column start address (0 = reset) 98 | sendCommand(x_offset + maxBoundX); // column end address (127 = reset) 99 | 100 | sendCommand(PAGEADDR); 101 | sendCommand(minBoundY); // page start address 102 | sendCommand(maxBoundY); // page end address 103 | 104 | for (y = minBoundY; y <= maxBoundY; y++) { 105 | uint8_t *start = &buffer[(minBoundX + y * this->width())-1]; 106 | uint8_t save = *start; 107 | 108 | *start = 0x40; // control 109 | _i2c->write(_address, (char *)start, (maxBoundX-minBoundX) + 1 + 1); 110 | *start = save; 111 | } 112 | #else 113 | 114 | sendCommand(COLUMNADDR); 115 | sendCommand(x_offset); // column start address (0 = reset) 116 | sendCommand(x_offset + (this->width() - 1));// column end address (127 = reset) 117 | 118 | sendCommand(PAGEADDR); 119 | sendCommand(0x0); // page start address (0 = reset) 120 | 121 | if (geometry == GEOMETRY_128_64) { 122 | sendCommand(0x7); 123 | } else if (geometry == GEOMETRY_128_32) { 124 | sendCommand(0x3); 125 | } 126 | 127 | buffer[-1] = 0x40; // control 128 | _i2c->write(_address, (char *)&buffer[-1], displayBufferSize + 1); 129 | #endif 130 | } 131 | 132 | private: 133 | int getBufferOffset(void) { 134 | return 0; 135 | } 136 | 137 | inline void sendCommand(uint8_t command) __attribute__((always_inline)) { 138 | char _data[2]; 139 | _data[0] = 0x80; // control 140 | _data[1] = command; 141 | _i2c->write(_address, _data, sizeof(_data)); 142 | } 143 | 144 | uint8_t _address; 145 | PinName _sda; 146 | PinName _scl; 147 | I2C *_i2c; 148 | }; 149 | 150 | #endif 151 | 152 | #endif 153 | -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/src/SSD1306Spi.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 by ThingPulse, Daniel Eichhorn 5 | * Copyright (c) 2018 by Fabrice Weinberg 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | * 25 | * ThingPulse invests considerable time and money to develop these open source libraries. 26 | * Please support us by buying our products (and not the clones) from 27 | * https://thingpulse.com 28 | * 29 | */ 30 | 31 | #ifndef SSD1306Spi_h 32 | #define SSD1306Spi_h 33 | 34 | #include "OLEDDisplay.h" 35 | #include 36 | 37 | #if F_CPU == 160000000L 38 | #define BRZO_I2C_SPEED 1000 39 | #else 40 | #define BRZO_I2C_SPEED 800 41 | #endif 42 | 43 | class SSD1306Spi : public OLEDDisplay { 44 | private: 45 | uint8_t _rst; 46 | uint8_t _dc; 47 | uint8_t _cs; 48 | 49 | public: 50 | SSD1306Spi(uint8_t _rst, uint8_t _dc, uint8_t _cs, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64) { 51 | setGeometry(g); 52 | 53 | this->_rst = _rst; 54 | this->_dc = _dc; 55 | this->_cs = _cs; 56 | } 57 | 58 | bool connect(){ 59 | pinMode(_dc, OUTPUT); 60 | pinMode(_cs, OUTPUT); 61 | pinMode(_rst, OUTPUT); 62 | 63 | SPI.begin (); 64 | SPI.setClockDivider (SPI_CLOCK_DIV2); 65 | 66 | // Pulse Reset low for 10ms 67 | digitalWrite(_rst, HIGH); 68 | delay(1); 69 | digitalWrite(_rst, LOW); 70 | delay(10); 71 | digitalWrite(_rst, HIGH); 72 | return true; 73 | } 74 | 75 | void display(void) { 76 | #ifdef OLEDDISPLAY_DOUBLE_BUFFER 77 | uint8_t minBoundY = UINT8_MAX; 78 | uint8_t maxBoundY = 0; 79 | 80 | uint8_t minBoundX = UINT8_MAX; 81 | uint8_t maxBoundX = 0; 82 | 83 | uint8_t x, y; 84 | 85 | // Calculate the Y bounding box of changes 86 | // and copy buffer[pos] to buffer_back[pos]; 87 | for (y = 0; y < (displayHeight / 8); y++) { 88 | for (x = 0; x < displayWidth; x++) { 89 | uint16_t pos = x + y * displayWidth; 90 | if (buffer[pos] != buffer_back[pos]) { 91 | minBoundY = _min(minBoundY, y); 92 | maxBoundY = _max(maxBoundY, y); 93 | minBoundX = _min(minBoundX, x); 94 | maxBoundX = _max(maxBoundX, x); 95 | } 96 | buffer_back[pos] = buffer[pos]; 97 | } 98 | yield(); 99 | } 100 | 101 | // If the minBoundY wasn't updated 102 | // we can savely assume that buffer_back[pos] == buffer[pos] 103 | // holdes true for all values of pos 104 | if (minBoundY == UINT8_MAX) return; 105 | 106 | sendCommand(COLUMNADDR); 107 | sendCommand(minBoundX); 108 | sendCommand(maxBoundX); 109 | 110 | sendCommand(PAGEADDR); 111 | sendCommand(minBoundY); 112 | sendCommand(maxBoundY); 113 | 114 | digitalWrite(_cs, HIGH); 115 | digitalWrite(_dc, HIGH); // data mode 116 | digitalWrite(_cs, LOW); 117 | for (y = minBoundY; y <= maxBoundY; y++) { 118 | for (x = minBoundX; x <= maxBoundX; x++) { 119 | SPI.transfer(buffer[x + y * displayWidth]); 120 | } 121 | yield(); 122 | } 123 | digitalWrite(_cs, HIGH); 124 | #else 125 | // No double buffering 126 | sendCommand(COLUMNADDR); 127 | sendCommand(0x0); 128 | sendCommand(0x7F); 129 | 130 | sendCommand(PAGEADDR); 131 | sendCommand(0x0); 132 | 133 | if (geometry == GEOMETRY_128_64 || geometry == GEOMETRY_64_48 || geometry == GEOMETRY_64_32 ) { 134 | sendCommand(0x7); 135 | } else if (geometry == GEOMETRY_128_32) { 136 | sendCommand(0x3); 137 | } 138 | 139 | digitalWrite(_cs, HIGH); 140 | digitalWrite(_dc, HIGH); // data mode 141 | digitalWrite(_cs, LOW); 142 | for (uint16_t i=0; i 2 | #include 3 | 4 | // select MQTT server address 5 | #if defined(MQTT_ADDR) 6 | #define FDRS_MQTT_ADDR MQTT_ADDR 7 | #elif defined(GLOBAL_MQTT_ADDR) 8 | #define FDRS_MQTT_ADDR GLOBAL_MQTT_ADDR 9 | #else 10 | // ASSERT("NO MQTT address defined! Please define in fdrs_globals.h (recommended) or in fdrs_node_config.h"); 11 | #endif // MQTT_ADDR 12 | 13 | // select MQTT server port 14 | #if defined(MQTT_PORT) 15 | #define FDRS_MQTT_PORT MQTT_PORT 16 | #elif defined(GLOBAL_MQTT_PORT) 17 | #define FDRS_MQTT_PORT GLOBAL_MQTT_PORT 18 | #else 19 | #define FDRS_MQTT_PORT 1883 20 | #endif // MQTT_PORT 21 | 22 | // select MQTT user name 23 | #if defined(MQTT_USER) 24 | #define FDRS_MQTT_USER MQTT_USER 25 | #elif defined(GLOBAL_MQTT_USER) 26 | #define FDRS_MQTT_USER GLOBAL_MQTT_USER 27 | #else 28 | // ASSERT("NO MQTT user defined! Please define in fdrs_globals.h (recommended) or in fdrs_node_config.h"); 29 | #endif // MQTT_USER 30 | 31 | // select MQTT user password 32 | #if defined(MQTT_PASS) 33 | #define FDRS_MQTT_PASS MQTT_PASS 34 | #elif defined(GLOBAL_MQTT_PASS) 35 | #define FDRS_MQTT_PASS GLOBAL_MQTT_PASS 36 | #else 37 | // ASSERT("NO MQTT password defined! Please define in fdrs_globals.h (recommended) or in fdrs_node_config.h"); 38 | #endif // MQTT_PASS 39 | #if defined(MQTT_AUTH) || defined(GLOBAL_MQTT_AUTH) 40 | #define FDRS_MQTT_AUTH 41 | #endif // MQTT_AUTH 42 | 43 | #if defined(TOPIC_DATA) 44 | #define FDRS_TOPIC_DATA TOPIC_DATA 45 | #else 46 | #define FDRS_TOPIC_DATA GLOBAL_TOPIC_DATA 47 | #endif // TOPIC_DATA 48 | 49 | #if defined(TOPIC_STATUS) 50 | #define FDRS_TOPIC_STATUS TOPIC_STATUS 51 | #else 52 | #define FDRS_TOPIC_STATUS GLOBAL_TOPIC_STATUS 53 | #endif // TOPIC_STATUS 54 | 55 | #if defined(TOPIC_COMMAND) 56 | #define FDRS_TOPIC_COMMAND TOPIC_COMMAND 57 | #else 58 | #define FDRS_TOPIC_COMMAND GLOBAL_TOPIC_COMMAND 59 | #endif // TOPIC_COMMAND 60 | 61 | #define MQTT_MAX_BUFF_SIZE 1024 62 | 63 | WiFiClient espClient; 64 | PubSubClient client(espClient); 65 | unsigned long lastMqttConnectAttempt = 0; 66 | 67 | const char *mqtt_server = FDRS_MQTT_ADDR; 68 | const int mqtt_port = FDRS_MQTT_PORT; 69 | 70 | 71 | #ifdef FDRS_MQTT_AUTH 72 | const char *mqtt_user = FDRS_MQTT_USER; 73 | const char *mqtt_pass = FDRS_MQTT_PASS; 74 | #else 75 | const char *mqtt_user = NULL; 76 | const char *mqtt_pass = NULL; 77 | #endif // FDRS_MQTT_AUTH 78 | 79 | void reconnect_mqtt(short int attempts, bool silent) 80 | { 81 | if (!silent) 82 | DBG("Connecting MQTT..."); 83 | 84 | for (short int i = 1; i <= attempts; i++) 85 | { 86 | // Attempt to connect 87 | if (client.connect("FDRS_GATEWAY", mqtt_user, mqtt_pass)) 88 | { 89 | // Subscribe 90 | client.subscribe(FDRS_TOPIC_COMMAND); 91 | if (!silent) 92 | DBG(" MQTT Connected"); 93 | return; 94 | } 95 | else 96 | { 97 | if (!silent) 98 | { 99 | char msg[23]; 100 | sprintf(msg, " Attempt %d/%d", i, attempts); 101 | DBG(msg); 102 | } 103 | if ((attempts != 1)) 104 | { 105 | delay(3000); 106 | } 107 | } 108 | } 109 | 110 | if (!silent) 111 | DBG(" Connecting MQTT failed."); 112 | } 113 | 114 | void reconnect_mqtt(int attempts) 115 | { 116 | reconnect_mqtt(attempts, false); 117 | } 118 | 119 | // Handles MQTT in loop() 120 | void handleMQTT() 121 | { 122 | if (!client.connected()) 123 | { 124 | if(TDIFF(lastMqttConnectAttempt,5000)) { 125 | reconnect_mqtt(1, true); 126 | lastMqttConnectAttempt = millis(); 127 | } 128 | } 129 | client.loop(); // for recieving incoming messages and maintaining connection 130 | } 131 | 132 | void mqtt_callback(char *topic, byte *message, unsigned int length) 133 | { 134 | String incomingString; 135 | DBG(topic); 136 | for (unsigned int i = 0; i < length; i++) 137 | { 138 | incomingString += (char)message[i]; 139 | } 140 | JsonDocument doc; 141 | DeserializationError error = deserializeJson(doc, incomingString); 142 | if (error) 143 | { // Test if parsing succeeds. 144 | DBG2("json parse err"); 145 | DBG2(incomingString); 146 | return; 147 | } 148 | else 149 | { 150 | int s = doc.size(); 151 | // UART_IF.println(s); 152 | for (int i = 0; i < s; i++) 153 | { 154 | theData[i].id = doc[i]["id"]; 155 | theData[i].t = doc[i]["type"]; 156 | theData[i].d = doc[i]["data"]; 157 | } 158 | ln = s; 159 | newData = event_mqtt; 160 | DBG("Incoming MQTT."); 161 | } 162 | } 163 | 164 | void begin_mqtt() 165 | { 166 | client.setServer(mqtt_server, mqtt_port); 167 | client.setBufferSize(MQTT_MAX_BUFF_SIZE); 168 | 169 | if (!client.connected()) 170 | { 171 | reconnect_mqtt(5); 172 | } 173 | client.setCallback(mqtt_callback); 174 | } 175 | 176 | void mqtt_publish(const char *payload) 177 | { 178 | if (!client.publish(FDRS_TOPIC_DATA, payload)) 179 | { 180 | DBG(" Error on sending MQTT"); 181 | 182 | } 183 | } 184 | 185 | void sendMQTT() 186 | { 187 | DBG("Sending MQTT."); 188 | JsonDocument doc; 189 | for (int i = 0; i < ln; i++) 190 | { 191 | doc[i]["id"] = theData[i].id; 192 | doc[i]["type"] = theData[i].t; 193 | doc[i]["data"] = theData[i].d; 194 | } 195 | String outgoingString; 196 | serializeJson(doc, outgoingString); 197 | mqtt_publish((char *)outgoingString.c_str()); 198 | } -------------------------------------------------------------------------------- /src/ESP8266_and_ESP32_OLED_driver_for_SSD1306_displays/src/SSD1306Brzo.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 by ThingPulse, Daniel Eichhorn 5 | * Copyright (c) 2018 by Fabrice Weinberg 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | * 25 | * ThingPulse invests considerable time and money to develop these open source libraries. 26 | * Please support us by buying our products (and not the clones) from 27 | * https://thingpulse.com 28 | * 29 | */ 30 | 31 | #ifndef SSD1306Brzo_h 32 | #define SSD1306Brzo_h 33 | 34 | #include "OLEDDisplay.h" 35 | #include 36 | 37 | #if F_CPU == 160000000L 38 | #define BRZO_I2C_SPEED 1000 39 | #else 40 | #define BRZO_I2C_SPEED 800 41 | #endif 42 | 43 | class SSD1306Brzo : public OLEDDisplay { 44 | private: 45 | uint8_t _address; 46 | uint8_t _sda; 47 | uint8_t _scl; 48 | 49 | public: 50 | SSD1306Brzo(uint8_t _address, uint8_t _sda, uint8_t _scl, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64) { 51 | setGeometry(g); 52 | 53 | this->_address = _address; 54 | this->_sda = _sda; 55 | this->_scl = _scl; 56 | } 57 | 58 | bool connect(){ 59 | brzo_i2c_setup(_sda, _scl, 0); 60 | return true; 61 | } 62 | 63 | void display(void) { 64 | const int x_offset = (128 - this->width()) / 2; 65 | 66 | #ifdef OLEDDISPLAY_DOUBLE_BUFFER 67 | uint8_t minBoundY = UINT8_MAX; 68 | uint8_t maxBoundY = 0; 69 | 70 | uint8_t minBoundX = UINT8_MAX; 71 | uint8_t maxBoundX = 0; 72 | 73 | uint8_t x, y; 74 | 75 | // Calculate the Y bounding box of changes 76 | // and copy buffer[pos] to buffer_back[pos]; 77 | for (y = 0; y < (this->height() / 8); y++) { 78 | for (x = 0; x < this->width(); x++) { 79 | uint16_t pos = x + y * this->width(); 80 | if (buffer[pos] != buffer_back[pos]) { 81 | minBoundY = _min(minBoundY, y); 82 | maxBoundY = _max(maxBoundY, y); 83 | minBoundX = _min(minBoundX, x); 84 | maxBoundX = _max(maxBoundX, x); 85 | } 86 | buffer_back[pos] = buffer[pos]; 87 | } 88 | yield(); 89 | } 90 | 91 | // If the minBoundY wasn't updated 92 | // we can savely assume that buffer_back[pos] == buffer[pos] 93 | // holdes true for all values of pos 94 | if (minBoundY == UINT8_MAX) return; 95 | 96 | sendCommand(COLUMNADDR); 97 | sendCommand(x_offset + minBoundX); 98 | sendCommand(x_offset + maxBoundX); 99 | 100 | sendCommand(PAGEADDR); 101 | sendCommand(minBoundY); 102 | sendCommand(maxBoundY); 103 | 104 | byte k = 0; 105 | 106 | int buflen = ( this->width() / 8 ) + 1; 107 | 108 | uint8_t sendBuffer[buflen]; 109 | sendBuffer[0] = 0x40; 110 | brzo_i2c_start_transaction(this->_address, BRZO_I2C_SPEED); 111 | for (y = minBoundY; y <= maxBoundY; y++) { 112 | for (x = minBoundX; x <= maxBoundX; x++) { 113 | k++; 114 | sendBuffer[k] = buffer[x + y * this->width()]; 115 | if (k == (buflen-1)) { 116 | brzo_i2c_write(sendBuffer, buflen, true); 117 | k = 0; 118 | } 119 | } 120 | yield(); 121 | } 122 | brzo_i2c_write(sendBuffer, k + 1, true); 123 | brzo_i2c_end_transaction(); 124 | #else 125 | // No double buffering 126 | sendCommand(COLUMNADDR); 127 | 128 | sendCommand(x_offset); 129 | sendCommand(x_offset + (this->width() - 1)); 130 | 131 | sendCommand(PAGEADDR); 132 | sendCommand(0x0); 133 | sendCommand((this->height() / 8) - 1); 134 | 135 | int buflen = ( this->width() / 8 ) + 1; 136 | 137 | uint8_t sendBuffer[buflen]; 138 | sendBuffer[0] = 0x40; 139 | 140 | brzo_i2c_start_transaction(this->_address, BRZO_I2C_SPEED); 141 | 142 | for (uint16_t i=0; i 3 | #include 4 | #elif defined(ESP32) 5 | #include 6 | #include 7 | #include 8 | #endif 9 | 10 | const uint8_t broadcast_mac[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; 11 | crcResult esp_now_ack_flag; 12 | bool is_added = false; 13 | uint32_t last_refresh = 0; 14 | uint32_t gtwy_timeout = 300000; 15 | bool pingFlag = false; 16 | 17 | // Request time from gateway - Optionally used in sensors 18 | bool reqTimeEspNow() { 19 | unsigned long pingStart = millis(); 20 | SystemPacket sys_packet = {.cmd = cmd_time, .param = 0}; 21 | DBG1("Requesting time from gateway 0x" + String(gatewayAddress[5],HEX)); 22 | esp_now_send(gatewayAddress, (uint8_t *)&sys_packet, sizeof(SystemPacket)); 23 | while(timeSource.tmNetIf < TMIF_ESPNOW && (millis() - pingStart < 300)) { 24 | // wait for time to be set 25 | // magic happens here :) 26 | yield(); 27 | delay(0); 28 | } 29 | if(timeSource.tmNetIf == TMIF_ESPNOW) { 30 | return true; 31 | } 32 | else { 33 | return false; 34 | } 35 | } 36 | 37 | void recvTimeEspNow(uint32_t t) { 38 | // Process time if there is no master set yet or if LoRa is the master or if we are already the time master 39 | if(timeSource.tmNetIf < TMIF_ESPNOW || (timeSource.tmNetIf == TMIF_ESPNOW && timeSource.tmAddress == (incMAC[4] << 8 | incMAC[5]))) { 40 | DBG1("Received time via ESP-NOW from 0x" + String(incMAC[5], HEX)); 41 | if(timeSource.tmNetIf < TMIF_ESPNOW) { 42 | timeSource.tmNetIf = TMIF_ESPNOW; 43 | timeSource.tmSource = TMS_NET; 44 | timeSource.tmAddress = (incMAC[4] << 8 | incMAC[5]); 45 | DBG1("ESP-NOW time source is now 0x" + String(incMAC[5], HEX)); 46 | } 47 | setTime(t); 48 | timeSource.tmLastTimeSet = millis(); 49 | } 50 | else { 51 | DBG2("ESP-NOW 0x" + String(incMAC[5], HEX) + " is not our time source, discarding request"); 52 | } 53 | return; 54 | } 55 | 56 | // Set ESP-NOW send and receive callbacks for either ESP8266 or ESP32 57 | #if defined(ESP8266) 58 | void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) 59 | { 60 | if (sendStatus == 0) 61 | { 62 | esp_now_ack_flag = CRC_OK; 63 | } 64 | else 65 | { 66 | esp_now_ack_flag = CRC_BAD; 67 | } 68 | } 69 | void OnDataRecv(uint8_t *mac, uint8_t *incomingData, uint8_t len) 70 | { 71 | memcpy(&incMAC, mac, sizeof(incMAC)); 72 | #elif defined(ESP32) 73 | void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) 74 | { 75 | if (status == ESP_NOW_SEND_SUCCESS) 76 | { 77 | esp_now_ack_flag = CRC_OK; 78 | } 79 | else 80 | { 81 | esp_now_ack_flag = CRC_BAD; 82 | } 83 | } 84 | void OnDataRecv(const esp_now_recv_info *pkt_info, const uint8_t *incomingData, int len) 85 | { 86 | memcpy(&incMAC, pkt_info->src_addr, sizeof(incMAC)); 87 | #endif 88 | if (len == sizeof(SystemPacket)) 89 | { 90 | SystemPacket command; 91 | memcpy(&command, incomingData, sizeof(command)); 92 | DBG2("Incoming ESP-NOW System Packet from 0x" + String(incMAC[5], HEX)); 93 | switch (command.cmd) 94 | { 95 | case cmd_ping: 96 | if(command.param == ping_reply) { 97 | pingFlag = true; 98 | } 99 | break; 100 | case cmd_add: 101 | is_added = true; 102 | gtwy_timeout = command.param; 103 | break; 104 | case cmd_time: 105 | if(command.param > MIN_TS) { 106 | recvTimeEspNow(command.param); 107 | } 108 | break; 109 | } 110 | } 111 | else if((len == sizeof(DataReading))) 112 | { 113 | memcpy(&theData, incomingData, len); 114 | ln = len / sizeof(DataReading); 115 | DBG2("Incoming ESP-NOW DataReading from 0x" + String(incMAC[5], HEX)); 116 | newData = event_espnowg; 117 | // Processing done by handleIncoming() in fdrs_node.h 118 | } 119 | else { 120 | DBG2("Incoming ESP-NOW Data from 0x" + String(incMAC[5], HEX) + " of unexpected size " + String(len)); 121 | } 122 | } 123 | 124 | // FDRS node pings gateway and listens for a defined amount of time for a reply 125 | // ESP-NOW is on the order of 10 milliseconds so happens very quickly. 126 | int pingFDRSEspNow(uint8_t *dstaddr, uint32_t timeout) { 127 | SystemPacket sys_packet = {.cmd = cmd_ping, .param = ping_request}; 128 | unsigned long pingTime = 0; 129 | 130 | pingFlag = false; 131 | pingTime = millis(); 132 | DBG1("ESP-NOW ping sent to 0x" + String(*(dstaddr + 5),HEX)); 133 | esp_now_send(dstaddr, (uint8_t *)&sys_packet, sizeof(SystemPacket)); 134 | while(pingFlag == false && (millis() - pingTime < timeout)) { 135 | yield(); 136 | delay(0); 137 | } 138 | if(pingFlag == true) { 139 | 140 | pingTime = millis() - pingTime; 141 | DBG1("ESP-NOW Ping Reply in " + String(pingTime) + "ms from 0x" + String(*(dstaddr + 5), HEX)); 142 | } 143 | else { 144 | DBG1("No ESP-NOW ping returned within " + String(timeout) + "ms."); 145 | pingTime = -1; 146 | } 147 | pingFlag = false; 148 | return pingTime; 149 | 150 | } 151 | 152 | bool refresh_registration() 153 | { 154 | #ifdef USE_ESPNOW 155 | SystemPacket sys_packet = {.cmd = cmd_add, .param = 0}; 156 | esp_now_send(gatewayAddress, (uint8_t *)&sys_packet, sizeof(SystemPacket)); 157 | DBG1("Refreshing registration to 0x" + String(gatewayAddress[5],HEX)); 158 | uint32_t add_start = millis(); 159 | is_added = false; 160 | while ((millis() - add_start) <= 1000) // 1000ms timeout 161 | { 162 | yield(); 163 | if (is_added) 164 | { 165 | DBG1("Registration accepted. Timeout: " + String(gtwy_timeout)); 166 | last_refresh = millis(); 167 | return true; 168 | } 169 | } 170 | DBG1("No gateways accepted the request"); 171 | return false; 172 | #endif // USE_ESPNOW 173 | return true; 174 | } 175 | 176 | esp_err_t sendTimeESPNow() { 177 | return ESP_OK; 178 | } --------------------------------------------------------------------------------