2020-10-25 20:48:57 +01:00
|
|
|
/*
|
|
|
|
***************************************************************************
|
|
|
|
** Program : OTGW-firmware.h
|
2021-12-20 19:31:38 +01:00
|
|
|
** Version : v0.9.1
|
2020-10-25 20:48:57 +01:00
|
|
|
**
|
2021-01-11 00:37:30 +01:00
|
|
|
** Copyright (c) 2021 Robert van den Breemen
|
2020-10-25 20:48:57 +01:00
|
|
|
**
|
|
|
|
** TERMS OF USE: MIT License. See bottom of file.
|
|
|
|
***************************************************************************
|
|
|
|
*/
|
2020-10-25 20:35:34 +01:00
|
|
|
|
2021-02-08 00:13:52 +01:00
|
|
|
#include <Arduino.h>
|
2021-10-16 20:36:00 +02:00
|
|
|
//#include <ezTime.h> // https://github.com/ropg/ezTime
|
2021-10-19 20:52:13 +02:00
|
|
|
|
2021-10-16 20:36:00 +02:00
|
|
|
#include <AceTime.h>
|
|
|
|
#include <TimeLib.h>
|
2021-10-19 20:52:13 +02:00
|
|
|
|
2020-10-25 20:35:34 +01:00
|
|
|
#include <TelnetStream.h> // https://github.com/jandrassy/TelnetStream/commit/1294a9ee5cc9b1f7e51005091e351d60c8cddecf
|
|
|
|
#include <ArduinoJson.h> // https://arduinojson.org/
|
2021-01-11 09:12:07 +01:00
|
|
|
#include "Wire.h"
|
2020-10-25 20:35:34 +01:00
|
|
|
#include "Debug.h"
|
|
|
|
#include "safeTimers.h"
|
2021-02-08 00:13:52 +01:00
|
|
|
#include "OTGWSerial.h" // Bron Schelte's Serial class - it upgrades and more
|
2021-01-30 18:35:11 +01:00
|
|
|
#include "OTGW-Core.h" // Core code for this firmware
|
2021-02-08 00:13:52 +01:00
|
|
|
|
|
|
|
//OTGW Nodoshop hardware definitions
|
|
|
|
#define I2CSCL D1
|
|
|
|
#define I2CSDA D2
|
|
|
|
#define BUTTON D3
|
|
|
|
#define PICRST D5
|
|
|
|
|
|
|
|
#define LED1 D4
|
|
|
|
#define LED2 D0
|
|
|
|
|
2021-02-14 19:26:37 +01:00
|
|
|
#define PICFIRMWARE "/gateway.hex"
|
2021-02-08 00:13:52 +01:00
|
|
|
|
|
|
|
extern OTGWSerial OTGWSerial(PICRST, LED2);
|
|
|
|
void fwupgradestart(const char *hexfile);
|
|
|
|
|
|
|
|
void blinkLEDnow();
|
|
|
|
void blinkLEDnow(uint8_t);
|
|
|
|
void setLed(int8_t, uint8_t);
|
|
|
|
|
2021-01-11 09:12:07 +01:00
|
|
|
//Defaults and macro definitions
|
2021-01-30 16:00:16 +01:00
|
|
|
#define _HOSTNAME "OTGW"
|
2020-10-25 20:35:34 +01:00
|
|
|
#define SETTINGS_FILE "/settings.ini"
|
2021-09-15 21:36:08 +02:00
|
|
|
#define NTP_DEFAULT_TIMEZONE "Europe/Amsterdam"
|
2021-10-16 20:36:00 +02:00
|
|
|
#define NTP_HOST_DEFAULT "pool.ntp.org"
|
|
|
|
#define NTP_RESYNC_TIME 1800 //seconds = every 30 minutes
|
2021-02-28 22:59:05 +01:00
|
|
|
#define HOME_ASSISTANT_DISCOVERY_PREFIX "homeassistant" // Home Assistant discovery prefix
|
2020-12-29 14:13:29 +01:00
|
|
|
#define CMSG_SIZE 512
|
2020-10-25 20:35:34 +01:00
|
|
|
#define JSON_BUFF_MAX 1024
|
2020-12-29 14:13:29 +01:00
|
|
|
#define CSTR(x) x.c_str()
|
2021-02-27 13:33:30 +01:00
|
|
|
#define CBOOLEAN(x) (x?"true":"false")
|
2021-01-03 23:12:19 +01:00
|
|
|
#define CONOFF(x) (x?"On":"Off")
|
2021-01-31 23:43:52 +01:00
|
|
|
#define CBINARY(x) (x?"1":"0")
|
|
|
|
#define EVALBOOLEAN(x) (stricmp(x,"true")==0||stricmp(x,"on")==0||stricmp(x,"1")==0)
|
2020-10-25 20:35:34 +01:00
|
|
|
|
2021-10-23 21:18:41 +02:00
|
|
|
|
2021-03-08 02:38:24 +01:00
|
|
|
//prototype
|
|
|
|
void sendMQTTData(const String, const String, const bool);
|
|
|
|
void sendMQTTData(const char*, const char*, const bool);
|
2021-11-15 21:32:19 +01:00
|
|
|
void addOTWGcmdtoqueue(const char* , int , const bool);
|
2021-02-24 22:57:37 +01:00
|
|
|
|
2021-01-11 09:12:07 +01:00
|
|
|
//Global variables
|
2020-10-25 22:56:18 +01:00
|
|
|
WiFiClient wifiClient;
|
2020-10-25 23:25:49 +01:00
|
|
|
char cMsg[CMSG_SIZE];
|
|
|
|
char fChar[10];
|
2021-02-19 01:48:31 +01:00
|
|
|
String lastReset = "";
|
2021-03-08 02:15:28 +01:00
|
|
|
uint32_t upTimeSeconds = 0;
|
2021-01-31 23:43:52 +01:00
|
|
|
uint32_t rebootCount = 0;
|
2021-02-19 01:48:31 +01:00
|
|
|
String sMessage = "";
|
2020-10-25 20:35:34 +01:00
|
|
|
|
2021-10-16 20:36:00 +02:00
|
|
|
//Use acetime
|
|
|
|
using namespace ace_time;
|
|
|
|
static BasicZoneProcessor timeProcessor;
|
|
|
|
static const int CACHE_SIZE = 3;
|
2021-12-05 23:01:49 +01:00
|
|
|
// static BasicZoneManager<CACHE_SIZE> manager(zonedb::kZoneRegistrySize, zonedb::kZoneRegistry);
|
|
|
|
static BasicZoneProcessorCache<CACHE_SIZE> zoneProcessorCache;
|
|
|
|
static BasicZoneManager timezoneManager(zonedb::kZoneRegistrySize, zonedb::kZoneRegistry, zoneProcessorCache);
|
2021-10-16 20:36:00 +02:00
|
|
|
|
2021-11-24 22:33:07 +01:00
|
|
|
const char *weekDayName[] { "Unknown", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Unknown" };
|
2020-10-25 20:35:34 +01:00
|
|
|
const char *flashMode[] { "QIO", "QOUT", "DIO", "DOUT", "Unknown" };
|
|
|
|
|
2021-01-31 23:43:52 +01:00
|
|
|
//Information on OTGW
|
|
|
|
String sPICfwversion = "";
|
2021-02-08 01:35:51 +01:00
|
|
|
String errorupgrade = "";
|
2021-03-28 18:45:15 +02:00
|
|
|
bool bOTGWonline = true;
|
|
|
|
bool bOTGWboilerstate = false;
|
|
|
|
bool bOTGWthermostatstate = false;
|
2021-04-23 00:24:04 +02:00
|
|
|
bool bPrintSummarymode = false; //default to PS=0 mode
|
2021-02-19 01:48:31 +01:00
|
|
|
|
2020-12-29 14:13:29 +01:00
|
|
|
//All things that are settings
|
2020-12-31 02:20:47 +01:00
|
|
|
String settingHostname = _HOSTNAME;
|
2021-02-19 01:48:31 +01:00
|
|
|
|
2020-10-25 22:56:18 +01:00
|
|
|
//MQTT settings
|
2021-02-08 01:00:21 +01:00
|
|
|
bool statusMQTTconnection = false;
|
2021-03-24 21:12:58 +01:00
|
|
|
bool settingMQTTenable = true;
|
2021-01-31 23:43:52 +01:00
|
|
|
bool settingMQTTsecure = false;
|
2020-10-25 23:25:49 +01:00
|
|
|
String settingMQTTbroker= "192.168.88.254";
|
2020-12-31 02:20:47 +01:00
|
|
|
int16_t settingMQTTbrokerPort = 1883;
|
2020-10-25 22:56:18 +01:00
|
|
|
String settingMQTTuser = "";
|
|
|
|
String settingMQTTpasswd = "";
|
2021-03-06 18:36:14 +01:00
|
|
|
String settingMQTThaprefix = HOME_ASSISTANT_DISCOVERY_PREFIX;
|
2021-03-06 10:38:44 +01:00
|
|
|
String settingMQTTtopTopic = "otgw";
|
2021-03-27 14:21:36 +01:00
|
|
|
String settingMQTTuniqueid = ""; // Intialized in readsettings
|
2021-03-09 00:45:45 +01:00
|
|
|
bool settingMQTTOTmessage = false;
|
2021-03-06 10:38:44 +01:00
|
|
|
bool settingNTPenable = true;
|
2021-09-15 21:36:08 +02:00
|
|
|
String settingNTPtimezone = NTP_DEFAULT_TIMEZONE;
|
|
|
|
String settingNTPhostname = NTP_HOST_DEFAULT;
|
2021-02-21 14:12:51 +01:00
|
|
|
bool settingLEDblink = true;
|
2020-10-25 22:56:18 +01:00
|
|
|
|
2021-03-12 09:07:17 +01:00
|
|
|
// GPIO Sensor Settings
|
|
|
|
bool settingGPIOSENSORSenabled = false;
|
|
|
|
int8_t settingGPIOSENSORSpin = 10;
|
2021-03-14 21:58:35 +01:00
|
|
|
int16_t settingGPIOSENSORSinterval = 5;
|
2021-03-12 09:07:17 +01:00
|
|
|
|
2021-12-15 12:57:30 +01:00
|
|
|
//boot commands
|
2021-03-14 23:05:56 +01:00
|
|
|
bool settingOTGWcommandenable = false;
|
2021-03-24 21:12:58 +01:00
|
|
|
String settingOTGWcommands = "";
|
2021-03-14 23:05:56 +01:00
|
|
|
|
2021-12-15 12:57:30 +01:00
|
|
|
//debug flags
|
|
|
|
bool bDebugOTmsg = true;
|
2021-03-23 23:33:00 +01:00
|
|
|
bool bDebugRestAPI = false;
|
2021-12-15 12:57:30 +01:00
|
|
|
bool bDebugMQTT = false;
|
2021-03-12 09:07:17 +01:00
|
|
|
|
2021-12-15 12:57:30 +01:00
|
|
|
//GPIO Output Settings
|
2021-03-13 10:35:18 +01:00
|
|
|
bool settingMyDEBUG = false;
|
|
|
|
bool settingGPIOOUTPUTSenabled = false;
|
|
|
|
int8_t settingGPIOOUTPUTSpin = 16;
|
|
|
|
int8_t settingGPIOOUTPUTStriggerBit = 0;
|
|
|
|
|
2021-02-14 19:26:37 +01:00
|
|
|
//Now load network suff
|
|
|
|
#include "networkStuff.h"
|
2021-01-30 18:35:11 +01:00
|
|
|
|
2021-03-13 10:35:18 +01:00
|
|
|
// That's all folks...
|
2021-01-30 18:35:11 +01:00
|
|
|
|
2021-12-19 20:47:20 +01:00
|
|
|
/***************************************************************************
|
2021-01-30 18:35:11 +01:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
* persons to whom the Software is furnished to do so, subject to the
|
|
|
|
* following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
|
|
|
|
* OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
|
|
|
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
****************************************************************************
|
|
|
|
*/
|