Migrate to PlatformIO
This commit is contained in:
parent
22dd57d831
commit
729ecb5602
24 changed files with 370 additions and 55 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/ipch
|
163
.vscode/c_cpp_properties.json
vendored
163
.vscode/c_cpp_properties.json
vendored
|
@ -1,28 +1,153 @@
|
|||
//
|
||||
// !!! WARNING !!! AUTO-GENERATED FILE!
|
||||
// PLEASE DO NOT MODIFY IT AND USE "platformio.ini":
|
||||
// https://docs.platformio.org/page/projectconf/section_env_build.html#build-flags
|
||||
//
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Linux",
|
||||
"name": "PlatformIO",
|
||||
"includePath": [
|
||||
"/home/rob/Arduino/libraries/",
|
||||
"/home/rob/.arduino15/packages/esp8266/tools/**",
|
||||
"/home/rob/.arduino15/packages/esp8266/hardware/esp8266/2.4.0/**",
|
||||
"/home/rob/Apps/arduino-1.8.5/tools/**",
|
||||
"/home/rob/Apps/arduino-1.8.5/hardware/arduino/avr/**",
|
||||
"/home/rob/.arduino15/staging/libraries"
|
||||
"/home/rob/Code/FishTankMonitor/include",
|
||||
"/home/rob/Code/FishTankMonitor/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266HTTPClient/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WiFi/src",
|
||||
"/home/rob/Code/FishTankMonitor/.pio/libdeps/d1_mini_lite/PubSubClient/src",
|
||||
"/home/rob/Code/FishTankMonitor/.pio/libdeps/d1_mini_lite/DallasTemperature",
|
||||
"/home/rob/Code/FishTankMonitor/.pio/libdeps/d1_mini_lite/OneWire",
|
||||
"/home/rob/Code/FishTankMonitor/.pio/libdeps/d1_mini_lite/Adafruit SSD1306",
|
||||
"/home/rob/Code/FishTankMonitor/.pio/libdeps/d1_mini_lite/Adafruit GFX Library",
|
||||
"/home/rob/Code/FishTankMonitor/.pio/libdeps/d1_mini_lite/Adafruit ADS1X15",
|
||||
"/home/rob/Code/FishTankMonitor/.pio/libdeps/d1_mini_lite/Adafruit BusIO",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/Wire",
|
||||
"/home/rob/Code/FishTankMonitor/.pio/libdeps/d1_mini_lite/FastLED/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/SPI",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/SoftwareSerial/src",
|
||||
"/home/rob/Code/FishTankMonitor/.pio/libdeps/d1_mini_lite/ArduinoJson/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/tools/sdk/include",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/cores/esp8266",
|
||||
"/home/rob/.platformio/packages/toolchain-xtensa/include",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/tools/sdk/lwip2/include",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/variants/d1_mini",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ArduinoOTA",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/DNSServer/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/EEPROM",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266AVRISP/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266HTTPUpdateServer/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266LLMNR",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266NetBIOS",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266SSDP",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266SdFat/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WebServer/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WiFiMesh/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266httpUpdate/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266mDNS/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/Ethernet/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/GDBStub/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/Hash/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/I2S/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/LittleFS/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/Netdump/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/SD/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/SDFS/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/SPISlave/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/Servo/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/TFT_Touch_Shield_V2",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/Ticker/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/esp8266/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/lwIP_PPP/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/lwIP_enc28j60/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/lwIP_w5100/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/lwIP_w5500/src",
|
||||
""
|
||||
],
|
||||
"intelliSenseMode": "clang-x64",
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "c11",
|
||||
"cppStandard": "c++17"
|
||||
},
|
||||
{
|
||||
"name": "Win32",
|
||||
"includePath": [
|
||||
"C:\\Users\\Rob\\AppData\\Local\\Arduino15\\packages\\esp8266\\tools\\**",
|
||||
"C:\\Users\\Rob\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.4.0\\**",
|
||||
"C:\\Users\\Rob\\Documents\\Arduino\\libraries\\**"
|
||||
"browse": {
|
||||
"limitSymbolsToIncludedHeaders": true,
|
||||
"path": [
|
||||
"/home/rob/Code/FishTankMonitor/include",
|
||||
"/home/rob/Code/FishTankMonitor/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266HTTPClient/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WiFi/src",
|
||||
"/home/rob/Code/FishTankMonitor/.pio/libdeps/d1_mini_lite/PubSubClient/src",
|
||||
"/home/rob/Code/FishTankMonitor/.pio/libdeps/d1_mini_lite/DallasTemperature",
|
||||
"/home/rob/Code/FishTankMonitor/.pio/libdeps/d1_mini_lite/OneWire",
|
||||
"/home/rob/Code/FishTankMonitor/.pio/libdeps/d1_mini_lite/Adafruit SSD1306",
|
||||
"/home/rob/Code/FishTankMonitor/.pio/libdeps/d1_mini_lite/Adafruit GFX Library",
|
||||
"/home/rob/Code/FishTankMonitor/.pio/libdeps/d1_mini_lite/Adafruit ADS1X15",
|
||||
"/home/rob/Code/FishTankMonitor/.pio/libdeps/d1_mini_lite/Adafruit BusIO",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/Wire",
|
||||
"/home/rob/Code/FishTankMonitor/.pio/libdeps/d1_mini_lite/FastLED/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/SPI",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/SoftwareSerial/src",
|
||||
"/home/rob/Code/FishTankMonitor/.pio/libdeps/d1_mini_lite/ArduinoJson/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/tools/sdk/include",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/cores/esp8266",
|
||||
"/home/rob/.platformio/packages/toolchain-xtensa/include",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/tools/sdk/lwip2/include",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/variants/d1_mini",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ArduinoOTA",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/DNSServer/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/EEPROM",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266AVRISP/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266HTTPUpdateServer/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266LLMNR",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266NetBIOS",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266SSDP",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266SdFat/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WebServer/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WiFiMesh/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266httpUpdate/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266mDNS/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/Ethernet/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/GDBStub/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/Hash/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/I2S/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/LittleFS/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/Netdump/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/SD/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/SDFS/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/SPISlave/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/Servo/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/TFT_Touch_Shield_V2",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/Ticker/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/esp8266/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/lwIP_PPP/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/lwIP_enc28j60/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/lwIP_w5100/src",
|
||||
"/home/rob/.platformio/packages/framework-arduinoespressif8266/libraries/lwIP_w5500/src",
|
||||
""
|
||||
]
|
||||
},
|
||||
"defines": [
|
||||
"PLATFORMIO=60111",
|
||||
"ESP8266",
|
||||
"ARDUINO_ARCH_ESP8266",
|
||||
"ARDUINO_ESP8266_WEMOS_D1MINILITE",
|
||||
"F_CPU=80000000L",
|
||||
"__ets__",
|
||||
"ICACHE_FLASH",
|
||||
"ARDUINO=10805",
|
||||
"ARDUINO_BOARD=\"PLATFORMIO_D1_MINI_LITE\"",
|
||||
"FLASHMODE_DOUT",
|
||||
"LWIP_OPEN_SRC",
|
||||
"NONOSDK22x_190703=1",
|
||||
"TCP_MSS=536",
|
||||
"LWIP_FEATURES=1",
|
||||
"LWIP_IPV6=0",
|
||||
"VTABLES_IN_FLASH",
|
||||
"MMU_IRAM_SIZE=0x8000",
|
||||
"MMU_ICACHE_SIZE=0x8000",
|
||||
""
|
||||
],
|
||||
"cStandard": "gnu17",
|
||||
"cppStandard": "gnu++17",
|
||||
"compilerPath": "/home/rob/.platformio/packages/toolchain-xtensa/bin/xtensa-lx106-elf-gcc",
|
||||
"compilerArgs": [
|
||||
"-mlongcalls",
|
||||
"-mtext-section-literals",
|
||||
""
|
||||
]
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
}
|
||||
|
|
10
.vscode/extensions.json
vendored
Normal file
10
.vscode/extensions.json
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"platformio.platformio-ide"
|
||||
],
|
||||
"unwantedRecommendations": [
|
||||
"ms-vscode.cpptools-extension-pack"
|
||||
]
|
||||
}
|
44
.vscode/launch.json
vendored
Normal file
44
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,44 @@
|
|||
// AUTOMATICALLY GENERATED FILE. PLEASE DO NOT MODIFY IT MANUALLY
|
||||
//
|
||||
// PIO Unified Debugger
|
||||
//
|
||||
// Documentation: https://docs.platformio.org/page/plus/debugging.html
|
||||
// Configuration: https://docs.platformio.org/page/projectconf/section_env_debug.html
|
||||
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "platformio-debug",
|
||||
"request": "launch",
|
||||
"name": "PIO Debug",
|
||||
"executable": "/home/rob/Code/FishTankMonitor/.pio/build/d1_mini_lite/firmware.elf",
|
||||
"projectEnvName": "d1_mini_lite",
|
||||
"toolchainBinDir": "/home/rob/.platformio/packages/toolchain-xtensa/bin",
|
||||
"internalConsoleOptions": "openOnSessionStart",
|
||||
"preLaunchTask": {
|
||||
"type": "PlatformIO",
|
||||
"task": "Pre-Debug"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "platformio-debug",
|
||||
"request": "launch",
|
||||
"name": "PIO Debug (skip Pre-Debug)",
|
||||
"executable": "/home/rob/Code/FishTankMonitor/.pio/build/d1_mini_lite/firmware.elf",
|
||||
"projectEnvName": "d1_mini_lite",
|
||||
"toolchainBinDir": "/home/rob/.platformio/packages/toolchain-xtensa/bin",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"type": "platformio-debug",
|
||||
"request": "launch",
|
||||
"name": "PIO Debug (without uploading)",
|
||||
"executable": "/home/rob/Code/FishTankMonitor/.pio/build/d1_mini_lite/firmware.elf",
|
||||
"projectEnvName": "d1_mini_lite",
|
||||
"toolchainBinDir": "/home/rob/.platformio/packages/toolchain-xtensa/bin",
|
||||
"internalConsoleOptions": "openOnSessionStart",
|
||||
"loadMode": "manual"
|
||||
}
|
||||
]
|
||||
}
|
39
include/README
Normal file
39
include/README
Normal file
|
@ -0,0 +1,39 @@
|
|||
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the usual convention is to give header files names that end with `.h'.
|
||||
It is most portable to use only letters, digits, dashes, and underscores in
|
||||
header file names, and at most one dot.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
46
lib/README
Normal file
46
lib/README
Normal file
|
@ -0,0 +1,46 @@
|
|||
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into executable file.
|
||||
|
||||
The source code of each library should be placed in a an own separate directory
|
||||
("lib/your_library_name/[here are source files]").
|
||||
|
||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||
| |
|
||||
| |--Foo
|
||||
| | |- Foo.c
|
||||
| | |- Foo.h
|
||||
| |
|
||||
| |- README --> THIS FILE
|
||||
|
|
||||
|- platformio.ini
|
||||
|--src
|
||||
|- main.c
|
||||
|
||||
and a contents of `src/main.c`:
|
||||
```
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
PlatformIO Library Dependency Finder will find automatically dependent
|
||||
libraries scanning project source files.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
24
platformio.ini
Normal file
24
platformio.ini
Normal file
|
@ -0,0 +1,24 @@
|
|||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:d1_mini_lite]
|
||||
platform = espressif8266
|
||||
board = d1_mini_lite
|
||||
framework = arduino
|
||||
|
||||
lib_deps =
|
||||
ArduinoJson
|
||||
FastLED
|
||||
adafruit/Adafruit ADS1X15
|
||||
adafruit/Adafruit SSD1306
|
||||
OneWire
|
||||
DallasTemperature
|
||||
PubSubClient
|
||||
Wire
|
|
@ -2,6 +2,16 @@
|
|||
#include <FastLED.h>
|
||||
|
||||
#define MAX_HEAT_INDEX 240.0
|
||||
#define PWMRANGE 1023
|
||||
|
||||
DEFINE_GRADIENT_PALETTE(_sunrise_p) {
|
||||
0, 0, 0, 0,
|
||||
8, 0, 0, 16,
|
||||
128, 255, 128, 0,
|
||||
224, 255, 255, 0,
|
||||
240, 255, 255, 255, // Hack to get around LINEARBLEND problem (for now, hopefully)
|
||||
255, 255, 255, 255
|
||||
};
|
||||
|
||||
Lighting::Lighting(NaturalLight* naturalLight, Weather* weather, float cloudCoverLimit) {
|
||||
_naturalLight = naturalLight;
|
||||
|
@ -10,6 +20,8 @@ Lighting::Lighting(NaturalLight* naturalLight, Weather* weather, float cloudCove
|
|||
|
||||
CRGB leds = CRGB(_ledCount);
|
||||
_leds = &leds;
|
||||
|
||||
analogWriteFreq(PWMRANGE);
|
||||
}
|
||||
|
||||
float Lighting::getIndexMultiplier(int now, int startTime, int endTime, bool swap) {
|
|
@ -5,14 +5,7 @@
|
|||
#include "NaturalLight.h"
|
||||
#include "Weather.h"
|
||||
|
||||
DEFINE_GRADIENT_PALETTE(_sunrise_p) {
|
||||
0, 0, 0, 0,
|
||||
8, 0, 0, 16,
|
||||
128, 255, 128, 0,
|
||||
224, 255, 255, 0,
|
||||
240, 255, 255, 255, // Hack to get around LINEARBLEND problem (for now, hopefully)
|
||||
255, 255, 255, 255
|
||||
};
|
||||
DECLARE_GRADIENT_PALETTE(_sunrise_p);
|
||||
|
||||
class Lighting {
|
||||
int _ledCount, _whitePin, _rPin, _gPin, _bPin;
|
|
@ -3,14 +3,15 @@
|
|||
#include <ArduinoJson.h>
|
||||
#include <time.h>
|
||||
|
||||
NaturalLight::NaturalLight(char *lat, char *lon, int timezoneOffset) {
|
||||
NaturalLight::NaturalLight(WiFiClient wifiClient, char *lat, char *lon, int timezoneOffset) {
|
||||
_wifiClient = wifiClient;
|
||||
_timezoneOffset = timezoneOffset;
|
||||
sprintf(_url, SOLAR_EVENT_URL, lat, lon);
|
||||
}
|
||||
|
||||
String NaturalLight::getSolarEventJson() {
|
||||
HTTPClient http;
|
||||
http.begin(_url);
|
||||
http.begin(_wifiClient, _url);
|
||||
int httpCode = http.GET();
|
||||
String result = "";
|
||||
if (httpCode > 0)
|
||||
|
@ -35,16 +36,16 @@ int NaturalLight::adjustForTimezone(int epoch) {
|
|||
|
||||
void NaturalLight::update() {
|
||||
String json = getSolarEventJson();
|
||||
StaticJsonBuffer<1024> jsonBuffer;
|
||||
JsonObject &root = jsonBuffer.parseObject(json);
|
||||
StaticJsonDocument<1024> document;
|
||||
|
||||
if (!root.success())
|
||||
DeserializationError error = deserializeJson(document, json);
|
||||
if (error)
|
||||
return;
|
||||
|
||||
const char *astronomicalTwilightBegin = root["results"]["astronomical_twilight_begin"];
|
||||
const char *sunrise = root["results"]["sunrise"];
|
||||
const char *sunset = root["results"]["sunset"];
|
||||
const char *astronomicalTwilightEnd = root["results"]["astronomical_twilight_end"];
|
||||
const char *astronomicalTwilightBegin = document["results"]["astronomical_twilight_begin"];
|
||||
const char *sunrise = document["results"]["sunrise"];
|
||||
const char *sunset = document["results"]["sunset"];
|
||||
const char *astronomicalTwilightEnd = document["results"]["astronomical_twilight_end"];
|
||||
|
||||
_astronomicalTwilightBegin = adjustForTimezone(getEpoch(astronomicalTwilightBegin));
|
||||
_sunrise = adjustForTimezone(getEpoch(sunrise));
|
|
@ -1,18 +1,21 @@
|
|||
#ifndef NaturalLight_h
|
||||
#define NaturalLight_h
|
||||
#include <Arduino.h>
|
||||
#include <WiFiClient.h>
|
||||
|
||||
#define SOLAR_EVENT_URL "http://api.sunrise-sunset.org/json?lat=%s&lng=%s&formatted=0"
|
||||
|
||||
class NaturalLight {
|
||||
int _astronomicalTwilightBegin, _sunrise, _sunset, _astronomicalTwilightEnd, _timezoneOffset;
|
||||
char _url[80];
|
||||
WiFiClient _wifiClient;
|
||||
|
||||
String getSolarEventJson();
|
||||
int getEpoch(const char *str);
|
||||
int adjustForTimezone(int epoch);
|
||||
|
||||
public:
|
||||
NaturalLight(char *lat, char *lon, int timezoneOffset);
|
||||
NaturalLight(WiFiClient wifiClient, char *lat, char *lon, int timezoneOffset);
|
||||
void update();
|
||||
int getAstronomicalTwilightBegin() { return _astronomicalTwilightBegin; }
|
||||
int getSunrise() { return _sunrise; }
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef Sensors_h
|
||||
#define Sensors_h
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_ADS1015.h>
|
||||
#include <Adafruit_ADS1X15.h>
|
||||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
#include <PubSubClient.h>
|
|
@ -2,18 +2,16 @@
|
|||
#include <Arduino.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "openWeatherMapApiKey.h"
|
||||
|
||||
Weather::Weather(char *lat, char *lon){
|
||||
Weather::Weather(WiFiClient wifiClient, char *lat, char *lon){
|
||||
_wifiClient = wifiClient;
|
||||
sprintf(_url, WEATHER_URL, lat, lon, OPEN_WEATHER_MAP_API_KEY);
|
||||
}
|
||||
|
||||
String Weather::getWeatherJson() {
|
||||
HTTPClient http;
|
||||
http.begin(_url);
|
||||
http.begin(_wifiClient, _url);
|
||||
int httpCode = http.GET();
|
||||
String result = "";
|
||||
if (httpCode > 0)
|
||||
|
@ -35,12 +33,12 @@ WeatherCondition Weather::parseCondition(int weatherId){
|
|||
|
||||
void Weather::update(){
|
||||
String json = getWeatherJson();
|
||||
StaticJsonBuffer<2048> jsonBuffer;
|
||||
JsonObject &root = jsonBuffer.parseObject(json);
|
||||
StaticJsonDocument<1024> document;
|
||||
|
||||
if (!root.success())
|
||||
DeserializationError error = deserializeJson(document, json);
|
||||
if (error)
|
||||
return;
|
||||
|
||||
_cloudCover = root["clouds"]["all"];
|
||||
_condition = parseCondition(root["weather"][0]["id"]);
|
||||
_cloudCover = document["clouds"]["all"];
|
||||
_condition = parseCondition(document["weather"][0]["id"]);
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef Weather_h
|
||||
#define Weather_h
|
||||
#include <Arduino.h>
|
||||
#include <WiFiClient.h>
|
||||
|
||||
#define WEATHER_URL "http://api.openweathermap.org/data/2.5/weather?lat=%s&lon=%s&appid=%s"
|
||||
|
||||
|
@ -16,11 +17,13 @@ class Weather{
|
|||
char _url[120];
|
||||
int _cloudCover;
|
||||
WeatherCondition _condition;
|
||||
WiFiClient _wifiClient;
|
||||
|
||||
String getWeatherJson();
|
||||
WeatherCondition parseCondition(int weatherId);
|
||||
|
||||
public:
|
||||
Weather(char *lat, char *lon);
|
||||
Weather(WiFiClient wifiClient, char *lat, char *lon);
|
||||
void update();
|
||||
int getCloudCover() { return _cloudCover; }
|
||||
WeatherCondition getCondition() { return _condition; }
|
|
@ -1,7 +1,7 @@
|
|||
/*-----------------+
|
||||
| Network settings |
|
||||
+-----------------*/
|
||||
#define HOSTNAME "Unconfigured_Aquarium"
|
||||
// #define HOSTNAME "Unconfigured_Aquarium"
|
||||
#define NETWORK_NAME "GCHQ Surveillance Van"
|
||||
#define PASSWORD "cocklol."
|
||||
#define MQTT_SERVER "192.168.1.3"
|
||||
|
@ -29,9 +29,9 @@
|
|||
/*---------------------------+
|
||||
| Location and time settings |
|
||||
+---------------------------*/
|
||||
#define LATITUDE "0"
|
||||
#define LONGITUDE "0"
|
||||
#define TIMEZONE_OFFSET 0
|
||||
// #define LATITUDE "0"
|
||||
// #define LONGITUDE "0"
|
||||
// #define TIMEZONE_OFFSET 0
|
||||
#define NTP_POOL "uk.pool.ntp.org"
|
||||
|
||||
/*------------+
|
||||
|
@ -62,13 +62,16 @@
|
|||
+----------------------------------------------------------*/
|
||||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
#include <WiFiClient.h>
|
||||
|
||||
WiFiClient _wifiClient;
|
||||
OneWire oneWire(TEMPERATURE_PIN);
|
||||
DallasTemperature temperatureSensor(&oneWire);
|
||||
|
||||
Networking _networking = Networking(HOSTNAME, NETWORK_NAME, PASSWORD ,MQTT_SERVER);
|
||||
Sensors _sensors = Sensors(TEMPERATURE_PIN, &_networking, &temperatureSensor);
|
||||
NaturalLight _naturalLight = NaturalLight(LATITUDE, LONGITUDE, TIMEZONE_OFFSET);
|
||||
Weather _weather = Weather(LATITUDE, LONGITUDE);
|
||||
NaturalLight _naturalLight = NaturalLight(_wifiClient, LATITUDE, LONGITUDE, TIMEZONE_OFFSET);
|
||||
Weather _weather = Weather(_wifiClient, LATITUDE, LONGITUDE);
|
||||
Lighting _lighting = Lighting(&_naturalLight, &_weather, CLOUD_COVER_LIMIT);
|
||||
Screen _display = Screen(&_sensors, SDA_PIN, SCL_PIN);
|
||||
|
11
test/README
Normal file
11
test/README
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
This directory is intended for PlatformIO Test Runner and project tests.
|
||||
|
||||
Unit Testing is a software testing method by which individual units of
|
||||
source code, sets of one or more MCU program modules together with associated
|
||||
control data, usage procedures, and operating procedures, are tested to
|
||||
determine whether they are fit for use. Unit testing finds problems early
|
||||
in the development cycle.
|
||||
|
||||
More information about PlatformIO Unit Testing:
|
||||
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
Loading…
Add table
Add a link
Reference in a new issue