Merge pull request #42 from anklimov/develop

Develop
This commit is contained in:
2019-04-30 15:37:43 +03:00
committed by GitHub
24 changed files with 16216 additions and 16024 deletions

View File

@@ -1,5 +1,6 @@
#! /bin/bash #! /bin/bash
export FLAGS="$FLAGS -DWiz5500" export FLAGS="$FLAGS -DWiz5500"
export FLAGS="$FLAGS -DW5500_CS_PIN=53"
export FLAGS="$FLAGS -DARTNET_ENABLE" export FLAGS="$FLAGS -DARTNET_ENABLE"
export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short)
CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_due-5500.sh CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_due-5500.sh

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
compiled/lighthub21/firmware.bin Executable file

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@@ -115,13 +115,16 @@ void Input::setup()
if (!isValid() || (!root)) return; if (!isValid() || (!root)) return;
#ifndef CSSHDC_DISABLE #ifndef CSSHDC_DISABLE
in_ccs811 ccs811(this);
in_hdc1080 hdc1080(this);
if (inType == IN_CCS811) if (inType == IN_CCS811)
{
in_ccs811 ccs811(this);
ccs811.Setup(pin); ccs811.Setup(pin);
}
else if (inType == IN_HDC1080) else if (inType == IN_HDC1080)
{
in_hdc1080 hdc1080(this);
hdc1080.Setup(pin); hdc1080.Setup(pin);
}
// TODO rest types setup // TODO rest types setup
#endif #endif
@@ -470,7 +473,7 @@ void Input::analogPoll() {
// Mapping // Mapping
if (inputMap && inputMap->type == aJson_Array) if (inputMap && inputMap->type == aJson_Array)
{ {
int max; int max=1024;
if (aJson.getArraySize(inputMap)>=4) if (aJson.getArraySize(inputMap)>=4)
mappedInputVal = map (mappedInputVal, mappedInputVal = map (mappedInputVal,
aJson.getArrayItem(inputMap, 0)->valueint, aJson.getArrayItem(inputMap, 0)->valueint,

View File

@@ -119,8 +119,10 @@ lan_status lanStatus = INITIAL_STATE;
const char configserver[] PROGMEM = CONFIG_SERVER; const char configserver[] PROGMEM = CONFIG_SERVER;
const char verval_P[] PROGMEM = QUOTE(PIO_SRC_REV); const char verval_P[] PROGMEM = QUOTE(PIO_SRC_REV);
#if defined(__SAM3X8E__)
UID UniqueID;
#endif
unsigned int UniqueID[5] = {0,0,0,0,0};
char *deviceName = NULL; char *deviceName = NULL;
aJsonObject *topics = NULL; aJsonObject *topics = NULL;
aJsonObject *root = NULL; aJsonObject *root = NULL;
@@ -243,7 +245,8 @@ else
itemName=topic+pfxlen; itemName=topic+pfxlen;
if(!strcmp(itemName,CMDTOPIC)) { if(!strcmp(itemName,CMDTOPIC) && payload && (strlen((char*) payload)>1)) {
// mqttClient.publish(topic, "");
cmd_parse((char *)payload); cmd_parse((char *)payload);
return; return;
} }
@@ -273,12 +276,15 @@ else
void printMACAddress() { void printMACAddress() {
debugSerial<<F("MAC:"); debugSerial<<F("MAC:");
for (byte i = 0; i < 6; i++) for (byte i = 0; i < 6; i++)
{
if (mac[i]<16) debugSerial<<"0";
#ifdef WITH_PRINTEX_LIB #ifdef WITH_PRINTEX_LIB
(i < 5) ?debugSerial<<hex <<(mac[i])<<F(":"):debugSerial<<hex<<(mac[i])<<endl; (i < 5) ?debugSerial<<hex <<(mac[i])<<F(":"):debugSerial<<hex<<(mac[i])<<endl;
#else #else
(i < 5) ?debugSerial<<_HEX(mac[i])<<F(":"):debugSerial<<_HEX(mac[i])<<endl; (i < 5) ?debugSerial<<_HEX(mac[i])<<F(":"):debugSerial<<_HEX(mac[i])<<endl;
#endif #endif
} }
}
lan_status lanLoop() { lan_status lanLoop() {
@@ -560,6 +566,11 @@ void ip_ready_config_loaded_connecting_to_broker() {
debugSerial<<F("\nAttempting MQTT connection to ")<<servername<<F(":")<<port<<F(" user:")<<user<<F(" ..."); debugSerial<<F("\nAttempting MQTT connection to ")<<servername<<F(":")<<port<<F(" user:")<<user<<F(" ...");
if (!strlen(user))
{
user = NULL;
password= NULL;
}
// wdt_dis(); //potential unsafe for ethernetIdle(), but needed to avoid cyclic reboot if mosquitto out of order // wdt_dis(); //potential unsafe for ethernetIdle(), but needed to avoid cyclic reboot if mosquitto out of order
if (mqttClient.connect(deviceName, user, password,willTopic,MQTTQOS1,true,willMessage)) { if (mqttClient.connect(deviceName, user, password,willTopic,MQTTQOS1,true,willMessage)) {
mqttErrorRate = 0; mqttErrorRate = 0;
@@ -593,7 +604,7 @@ void ip_ready_config_loaded_connecting_to_broker() {
nextLanCheckTime = millis() + 5000; nextLanCheckTime = millis() + 5000;
debugSerial<<F("Awaiting for retained topics"); debugSerial<<F("Awaiting for retained topics");
} else { } else {
debugSerial<<F("failed, rc=")<<mqttClient.state()<<F(" try again in 5 seconds"); debugSerial<<F("failed, rc=")<<mqttClient.state()<<F(" try again in 5 seconds")<<endl;
nextLanCheckTime = millis() + 5000; nextLanCheckTime = millis() + 5000;
#ifdef RESTART_LAN_ON_MQTT_ERRORS #ifdef RESTART_LAN_ON_MQTT_ERRORS
mqttErrorRate++; mqttErrorRate++;
@@ -630,7 +641,7 @@ void onInitialStateInitLAN() {
wifi_connection_wait -= 500; wifi_connection_wait -= 500;
debugSerial<<"."; debugSerial<<".";
} }
wifiInitialized = true; wifiInitialized = true; //???
} }
#else #else
// Wifi Manager // Wifi Manager
@@ -1142,7 +1153,7 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
{ {
int responseStatusCode = 0; int responseStatusCode = 0;
char ch; char ch;
char URI[40]; char URI[64];
char configServer[32]=""; char configServer[32]="";
if (arg_cnt > 1) { if (arg_cnt > 1) {
strncpy(configServer, args[1], sizeof(configServer) - 1); strncpy(configServer, args[1], sizeof(configServer) - 1);
@@ -1150,13 +1161,13 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
} else if (!loadFlash(OFFSET_CONFIGSERVER, configServer)) } else if (!loadFlash(OFFSET_CONFIGSERVER, configServer))
strncpy_P(configServer,configserver,sizeof(configServer)); strncpy_P(configServer,configserver,sizeof(configServer));
#ifndef DEVICE_NAME #ifndef DEVICE_NAME
snprintf(URI, sizeof(URI), "/%02x-%02x-%02x-%02x-%02x-%02x.config.json", mac[0], mac[1], mac[2], mac[3], mac[4], snprintf(URI, sizeof(URI), "/cnf/%02x-%02x-%02x-%02x-%02x-%02x.config.json", mac[0], mac[1], mac[2], mac[3], mac[4],
mac[5]); mac[5]);
#else #else
#ifndef FLASH_64KB #ifndef FLASH_64KB
snprintf(URI, sizeof(URI), "/%s_config.json",QUOTE(DEVICE_NAME)); snprintf(URI, sizeof(URI), "/cnf/%s_config.json",QUOTE(DEVICE_NAME));
#else #else
strncpy(URI, "/", sizeof(URI)); strncpy(URI, "/cnf/", sizeof(URI));
strncat(URI, QUOTE(DEVICE_NAME), sizeof(URI)); strncat(URI, QUOTE(DEVICE_NAME), sizeof(URI));
strncat(URI, "_config.json", sizeof(URI)); strncat(URI, "_config.json", sizeof(URI));
#endif #endif
@@ -1209,8 +1220,8 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
return READ_RE_CONFIG;//-11; return READ_RE_CONFIG;//-11;
} }
#endif #endif
#if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_ESP32) #if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32) //|| defined(ARDUINO_ARCH_ESP32) //|| defined(ARDUINO_ARCH_ESP8266)
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
WiFiClient configEthClient; WiFiClient configEthClient;
#else #else
EthernetClient configEthClient; EthernetClient configEthClient;
@@ -1233,7 +1244,7 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
htclient.stop(); htclient.stop();
wdt_res(); wdt_res();
debugSerial<<F("HTTP Status code: "); debugSerial<<F("HTTP Status code: ");
debugSerial<<responseStatusCode; debugSerial<<responseStatusCode<<" ";
//debugSerial<<"GET Response: "); //debugSerial<<"GET Response: ");
if (responseStatusCode == 200) { if (responseStatusCode == 200) {
@@ -1257,7 +1268,8 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
return READ_RE_CONFIG;//-11; //Load from NVRAM return READ_RE_CONFIG;//-11; //Load from NVRAM
} }
#endif #endif
#if defined(ARDUINO_ARCH_ESP8266)
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
HTTPClient httpClient; HTTPClient httpClient;
String fullURI = "http://"; String fullURI = "http://";
fullURI+=configServer; fullURI+=configServer;
@@ -1315,6 +1327,10 @@ void postTransmission() {
void setup_main() { void setup_main() {
//Serial.println("Hello"); //Serial.println("Hello");
//delay(1000); //delay(1000);
#if defined(__SAM3X8E__)
memset(&UniqueID,0,sizeof(UniqueID));
#endif
setupCmdArduino(); setupCmdArduino();
printFirmwareVersionAndBuildOptions(); printFirmwareVersionAndBuildOptions();
@@ -1452,11 +1468,11 @@ debugSerial<<endl;
#if defined(__SAM3X8E__) #if defined(__SAM3X8E__)
Serial.println(F("Reading 128 bits unique identifier") ) ; Serial.println(F("Reading 128 bits unique identifier") ) ;
ReadUniqueID( UniqueID ) ; ReadUniqueID( UniqueID.UID_Long ) ;
Serial.print ("ID: ") ; Serial.print ("ID: ") ;
for (byte b = 0 ; b < 4 ; b++) for (byte b = 0 ; b < 4 ; b++)
Serial.print ((unsigned int) UniqueID [b], HEX) ; Serial.print ((unsigned int) UniqueID.UID_Long [b], HEX) ;
Serial.println () ; Serial.println () ;
#endif #endif
@@ -1509,9 +1525,9 @@ if (!isMacValid) {
#elif defined(__SAM3X8E__) #elif defined(__SAM3X8E__)
//Lets make MAC from MPU serial# //Lets make MAC from MPU serial#
mac[0]=0xDE; mac[0]=0xDE;
//firmwareMacAddress[1]=0xAD;
for (byte b = 0 ; b < 5 ; b++) for (byte b = 0 ; b < 5 ; b++)
mac[b+1]=UniqueID [b] ; mac[b+1]=UniqueID.UID_Byte [b*3] + UniqueID.UID_Byte [b*3+1] + UniqueID.UID_Byte [b*3+2];
#elif defined DEFAULT_FIRMWARE_MAC #elif defined DEFAULT_FIRMWARE_MAC
uint8_t defaultMac[6] = DEFAULT_FIRMWARE_MAC;//comma(,) separated hex-array, hard-coded uint8_t defaultMac[6] = DEFAULT_FIRMWARE_MAC;//comma(,) separated hex-array, hard-coded

View File

@@ -18,6 +18,8 @@
#include <FS.h> //this needs to be first, or it all crashes and burns... #include <FS.h> //this needs to be first, or it all crashes and burns...
#include <ESP_EEPROM.h> #include <ESP_EEPROM.h>
#include <ESP8266HTTPClient.h> #include <ESP8266HTTPClient.h>
//#include <ArduinoHttpClient.h>
//#include "HttpClient.h"
#include <WiFiManager.h> #include <WiFiManager.h>
#include <DNSServer.h> #include <DNSServer.h>
#include <ESP8266WebServer.h> #include <ESP8266WebServer.h>
@@ -27,10 +29,12 @@
#endif #endif
#if defined ARDUINO_ARCH_ESP32 #if defined ARDUINO_ARCH_ESP32
//#include <FS.h> //this needs to be first, or it all crashes and burns... #include <FS.h> //this needs to be first, or it all crashes and burns...
//#include <EEPROM.h> //#include <EEPROM.h>
#include <NRFFlashStorage.h> #include <NRFFlashStorage.h>
#include <HttpClient.h> //#include "HttpClient.h"
//#include <ArduinoHttpClient.h>
#include <HTTPClient.h>
#include <WiFi.h> #include <WiFi.h>
#include <WiFiClient.h> #include <WiFiClient.h>
#include <WiFiClientSecure.h> #include <WiFiClientSecure.h>
@@ -169,6 +173,10 @@ enum lan_status {
DO_NOTHING = -14 DO_NOTHING = -14
}; };
typedef union {
uint32_t UID_Long[5];
uint8_t UID_Byte[20];
} UID;
//void watchdogSetup(void); //void watchdogSetup(void);

View File

@@ -7,6 +7,9 @@ CCS811 ccs811(CCS811_ADDR);
ClosedCube_HDC1080 hdc1080; ClosedCube_HDC1080 hdc1080;
long ccs811Baseline; long ccs811Baseline;
bool CCS811ready = false;
bool HDC1080ready = false;
int in_ccs811::Setup(int addr) int in_ccs811::Setup(int addr)
{ {
#ifdef WAK_PIN #ifdef WAK_PIN
@@ -15,7 +18,7 @@ int in_ccs811::Setup(int addr)
#endif #endif
Serial.println("CCS811 Init"); Serial.println("CCS811 Init");
if (CCS811ready) return 0;
Wire.begin(); //Inialize I2C Harware Wire.begin(); //Inialize I2C Harware
//It is recommended to check return status on .begin(), but it is not //It is recommended to check return status on .begin(), but it is not
@@ -28,11 +31,13 @@ Wire.begin(); //Inialize I2C Harware
return 0; return 0;
} }
ccs811.setBaseline(62000); ccs811.setBaseline(62000);
CCS811ready = true;
return 1; return 1;
} }
int in_hdc1080::Setup(int addr) int in_hdc1080::Setup(int addr)
{ {
if (HDC1080ready) return 0;
Serial.println("HDC1080 Init "); Serial.println("HDC1080 Init ");
Wire.begin(); //Inialize I2C Harware Wire.begin(); //Inialize I2C Harware
// Default settings: // Default settings:
@@ -44,6 +49,7 @@ Serial.println(hdc1080.readManufacturerId(), HEX); // 0x5449 ID of Texas Instrum
Serial.print("Device ID=0x"); Serial.print("Device ID=0x");
Serial.println(hdc1080.readDeviceId(), HEX); // 0x1050 ID of the device Serial.println(hdc1080.readDeviceId(), HEX); // 0x1050 ID of the device
printSerialNumber(); printSerialNumber();
HDC1080ready = true;
return 1; return 1;
} }
@@ -60,37 +66,31 @@ int in_hdc1080::Poll()
{ {
float h,t; float h,t;
int reg; int reg;
if (!HDC1080ready) return 0;
// #ifdef WAK_PIN Serial.print("HDC Status=");
// digitalWrite(WAK_PIN,LOW); Serial.println(reg=hdc1080.readRegister().rawData,HEX);
// #endif if (reg!=0xff)
{
Serial.print("T="); Serial.print("T=");
Serial.print(t=hdc1080.readTemperature()); Serial.print(t=hdc1080.readTemperature());
Serial.print("C, RH="); Serial.print("C, RH=");
Serial.print(h=hdc1080.readHumidity()); Serial.print(h=hdc1080.readHumidity());
Serial.print("% Status="); Serial.print("%");
publish(t,"/T"); publish(t,"/T");
publish(h,"/H"); publish(h,"/H");
Serial.println(reg=hdc1080.readRegister().rawData,HEX);
ccs811.setEnvironmentalData(h,t); ccs811.setEnvironmentalData(h,t);
}
if (reg==0xff) //ESP I2C glitch else //ESP I2C glitch
{ {
Serial.println("I2C Reset"); Serial.println("I2C Reset");
i2cReset(); i2cReset();
} }
delay(100);
//#ifdef WAK_PIN
// digitalWrite(WAK_PIN,HIGH);
//#endif
return 1; return 1;
} }
int in_ccs811::Poll() int in_ccs811::Poll()
{ {
if (!CCS811ready) return 0;
#ifdef WAK_PIN #ifdef WAK_PIN
digitalWrite(WAK_PIN,LOW); digitalWrite(WAK_PIN,LOW);
#endif #endif

18
lighthub/mqtt.cpp Normal file
View File

@@ -0,0 +1,18 @@
/*
int mqtt::publish(int value)
{};
int mqtt::publish(float value)
{
};
int mqtt::publish(char * value)
{
char addrstr[MQTT_TOPIC_LENGTH];
aJsonObject *emit = aJson.getObjectItem(in, "emit");
strncpy(addrstr,emit->valuestring,sizeof(addrstr));
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
if mqttClient.connected() mqttClient.publish(addrstr, value, true);
};
*/

View File

@@ -76,7 +76,7 @@ int owUpdate() {
}//if }//if
} //while } //while
debugSerial<<F("1-wire count: ")<<t_count; debugSerial<<F("1-wire count: ")<<t_count<<endl;
#endif #endif
} }

View File

@@ -247,7 +247,7 @@ Awesome work Mark T!*/
__attribute__ ((section (".ramfunc"))) __attribute__ ((section (".ramfunc")))
void ReadUniqueID( unsigned int * pdwUniqueID ) void ReadUniqueID( uint32_t * pdwUniqueID )
{ {
unsigned int status ; unsigned int status ;

View File

@@ -51,7 +51,7 @@ unsigned long freeRam ();
void parseBytes(const char* str, char separator, byte* bytes, int maxBytes, int base); void parseBytes(const char* str, char separator, byte* bytes, int maxBytes, int base);
int log(const char *str, ...); int log(const char *str, ...);
void printFloatValueToStr(float value, char *valstr); void printFloatValueToStr(float value, char *valstr);
void ReadUniqueID( unsigned int * pdwUniqueID ); void ReadUniqueID( uint32_t * pdwUniqueID );
int inet_aton(const char* aIPAddrString, IPAddress& aResult); int inet_aton(const char* aIPAddrString, IPAddress& aResult);
char *inet_ntoa_r(IPAddress addr, char *buf, int buflen); char *inet_ntoa_r(IPAddress addr, char *buf, int buflen);
void printIPAddress(IPAddress ipAddress); void printIPAddress(IPAddress ipAddress);

View File

@@ -18,7 +18,7 @@ env_default =
; esp8266 ; esp8266
; esp32 ; esp32
; megaatmega2560-5500 ; megaatmega2560-5500
due-5500 ; due-5500
; controllino ; controllino
; stm32 ; stm32
; nrf52840 ; nrf52840
@@ -93,18 +93,17 @@ lib_ignore =
Ethernet Ethernet
Ethernet2 Ethernet2
Ethernet3 Ethernet3
HTTPClient
httpClient
EEPROM EEPROM
Artnet Artnet
HTTPClient
UIPEthernet UIPEthernet
ESP_EEPROM ESP_EEPROM
EEPROM httpClient
HttpClient_ID66
HttpClient
ArduinoHttpClient
lib_deps = lib_deps =
https://github.com/ebenolson/WIFIMANAGER-ESP32.git https://github.com/ebenolson/WIFIMANAGER-ESP32.git
https://github.com/zhouhan0126/WebServer-esp32.git https://github.com/zhouhan0126/WebServer-esp32.git
ArduinoHttpClient
https://github.com/anklimov/aJson https://github.com/anklimov/aJson
https://github.com/anklimov/CmdArduino https://github.com/anklimov/CmdArduino
https://github.com/knolleary/pubsubclient.git https://github.com/knolleary/pubsubclient.git
@@ -214,6 +213,8 @@ lib_ignore =
SdFat SdFat
httpClient httpClient
HTTPClient HTTPClient
HttpClient_ID66
HttpClient
ArduinoHttpClient ArduinoHttpClient
Ethernet3 Ethernet3
Ethernet2 Ethernet2