mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
Merge pull request #30 from livello/IS-ENC
device_name, PrintEx lib, refactoring
This commit is contained in:
@@ -153,6 +153,9 @@ platformio device monitor -b 115200
|
||||
* WIFI_MANAGER_DISABLE //Disable wifi manager for esp8266
|
||||
* DHT_DISABLE //disable DHT Input support
|
||||
* RESTART_LAN_ON_MQTT_ERRORS //reinit LAN if many mqtt errors occured
|
||||
* WITH_STREAMING_LIB use streaming libriary for serial debug output otherwise use PrintEx library
|
||||
* DEVICE_NAME short handy device name which is used instead of mac for download config http://{MY_CONFIG_SERVER}/{DEVICE_NAME}_config.json
|
||||
* SYSLOG_ENABLE enable UDP SYSLOG support feature(under DEVELOPMENT) that must be configured through config file
|
||||
|
||||
|
||||
|
||||
@@ -176,5 +179,8 @@ platformio device monitor -b 115200
|
||||
* DHT support enabled
|
||||
* Wifi manager for esp8266 enabled
|
||||
* RESTART_LAN_ON_MQTT_ERRORS disabled
|
||||
* WITH_STREAMING_LIB disabled
|
||||
* DEVICE_NAME disabled
|
||||
* SYSLOG_ENABLE disabled
|
||||
|
||||
If you've using Arduino IDE to compile & flash firmware, it will use Default options above and you will not able to configure additional compilers options except edit "options.h" file
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
#! /bin/bash
|
||||
# usage:
|
||||
# first make your own copy of template
|
||||
# cp build_flags_template.sh build_flags_ENVNAME.sh
|
||||
# then edit, change or comment something
|
||||
export FLAGS="-DMY_CONFIG_SERVER=lazyhome.ru"
|
||||
#export FLAGS="$FLAGS -DWATCH_DOG_TICKER_DISABLE"
|
||||
#export FLAGS="$FLAGS -DUSE_1W_PIN=12"
|
||||
#export FLAGS="$FLAGS -DSD_CARD_INSERTED"
|
||||
export FLAGS="$FLAGS -DSERIAL_BAUD=115200"
|
||||
#export FLAGS="$FLAGS -DWiz5500"
|
||||
#export FLAGS="$FLAGS -DDISABLE_FREERAM_PRINT"
|
||||
export FLAGS="$FLAGS -DCUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:fe"
|
||||
# export FLAGS="$FLAGS -DDMX_DISABLE"
|
||||
# export FLAGS="$FLAGS -DARTNET_ENABLE"
|
||||
# export FLAGS="$FLAGS -DMODBUS_DISABLE"
|
||||
# export FLAGS="$FLAGS -DOWIRE_DISABLE"
|
||||
# export FLAGS="$FLAGS -DAVR_DMXOUT_PIN=18"
|
||||
# export FLAGS="$FLAGS -DLAN_INIT_DELAY=2000"
|
||||
# export FLAGS="$FLAGS -DCONTROLLINO"
|
||||
# export FLAGS="$FLAGS -DESP_WIFI_AP=MYAP"
|
||||
# export FLAGS="$FLAGS -DESP_WIFI_PWD=MYPWD"
|
||||
# export FLAGS="$FLAGS -DWIFI_MANAGER_DISABLE"
|
||||
export FLAGS="$FLAGS -DDHT_DISABLE"
|
||||
# export FLAGS="$FLAGS -DRESET_PIN=5"
|
||||
# export FLAGS="$FLAGS -DDHCP_RETRY_INTERVAL=60000"
|
||||
# export FLAGS="$FLAGS -DRESTART_LAN_ON_MQTT_ERRORS"
|
||||
# export FLAGS="$FLAGS -DW5500_CS_PIN=53"
|
||||
export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short)
|
||||
echo $FLAGS
|
||||
@@ -1,30 +0,0 @@
|
||||
#! /bin/bash
|
||||
# usage:
|
||||
# first make your own copy of template
|
||||
# cp build_flags_template.sh build_flags_ENVNAME.sh
|
||||
# then edit, change or comment something
|
||||
export FLAGS="-DMY_CONFIG_SERVER=lazyhome.ru"
|
||||
#export FLAGS="$FLAGS -DWATCH_DOG_TICKER_DISABLE"
|
||||
#export FLAGS="$FLAGS -DUSE_1W_PIN=12"
|
||||
#export FLAGS="$FLAGS -DSD_CARD_INSERTED"
|
||||
export FLAGS="$FLAGS -DSERIAL_BAUD=115200"
|
||||
#export FLAGS="$FLAGS -DWiz5500"
|
||||
#export FLAGS="$FLAGS -DDISABLE_FREERAM_PRINT"
|
||||
export FLAGS="$FLAGS -DCUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:ed"
|
||||
# export FLAGS="$FLAGS -DDMX_DISABLE"
|
||||
# export FLAGS="$FLAGS -DARTNET_ENABLE"
|
||||
# export FLAGS="$FLAGS -DMODBUS_DISABLE"
|
||||
export FLAGS="$FLAGS -DOWIRE_DISABLE"
|
||||
# export FLAGS="$FLAGS -DAVR_DMXOUT_PIN=18"
|
||||
# export FLAGS="$FLAGS -DLAN_INIT_DELAY=2000"
|
||||
# export FLAGS="$FLAGS -DCONTROLLINO"
|
||||
# export FLAGS="$FLAGS -DESP_WIFI_AP=MYAP"
|
||||
# export FLAGS="$FLAGS -DESP_WIFI_PWD=MYPWD"
|
||||
# export FLAGS="$FLAGS -DWIFI_MANAGER_DISABLE"
|
||||
export FLAGS="$FLAGS -DDHT_DISABLE"
|
||||
# export FLAGS="$FLAGS -DRESET_PIN=5"
|
||||
# export FLAGS="$FLAGS -DDHCP_RETRY_INTERVAL=60000"
|
||||
# export FLAGS="$FLAGS -DRESTART_LAN_ON_MQTT_ERRORS"
|
||||
# export FLAGS="$FLAGS -DW5500_CS_PIN=53"
|
||||
export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short)
|
||||
echo $FLAGS
|
||||
@@ -25,5 +25,7 @@
|
||||
# export FLAGS="$FLAGS -DDHCP_RETRY_INTERVAL=60000"
|
||||
# export FLAGS="$FLAGS -DRESTART_LAN_ON_MQTT_ERRORS"
|
||||
# export FLAGS="$FLAGS -DW5500_CS_PIN=53"
|
||||
#export FLAGS="$FLAGS -DSYSLOG_ENABLE"
|
||||
#export FLAGS="$FLAGS -DDEVICE_NAME=MYDEVICE"
|
||||
export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short)
|
||||
echo $FLAGS
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,6 @@
|
||||
#pragma once
|
||||
#include "options.h"
|
||||
|
||||
#ifndef LIGHTHUB_MAIN_H
|
||||
#define LIGHTHUB_MAIN_H
|
||||
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
#define wdt_res() watchdogReset()
|
||||
#define wdt_en()
|
||||
@@ -172,7 +169,7 @@ void applyConfig();
|
||||
|
||||
void cmdFunctionLoad(int arg_cnt, char **args);
|
||||
|
||||
int loadConfigFromEEPROM(int arg_cnt, char **args);
|
||||
int loadConfigFromEEPROM();
|
||||
|
||||
void cmdFunctionReq(int arg_cnt, char **args);
|
||||
|
||||
@@ -196,7 +193,7 @@ void saveFlash(short n, IPAddress& ip);
|
||||
|
||||
int ipLoadFromFlash(short n, IPAddress &ip);
|
||||
|
||||
lan_status getConfig(int arg_cnt=0, char **args=NULL);
|
||||
lan_status loadConfigFromHttp(int arg_cnt = 0, char **args = NULL);
|
||||
|
||||
void preTransmission();
|
||||
|
||||
@@ -238,4 +235,7 @@ void onInitialStateInitLAN();
|
||||
|
||||
void ip_ready_config_loaded_connecting_to_broker();
|
||||
|
||||
#endif //LIGHTHUB_MAIN_H
|
||||
void printCurentLanConfig();
|
||||
|
||||
void printFreeRam();
|
||||
|
||||
|
||||
@@ -112,9 +112,11 @@
|
||||
#define dmxin DmxDue1
|
||||
#endif
|
||||
|
||||
#if defined(ESP8266)
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
#undef _dmxin
|
||||
#undef _modbus
|
||||
#define WITH_STREAMING_LIB
|
||||
|
||||
#ifndef DMX_DISABLE
|
||||
#define _espdmx
|
||||
#endif
|
||||
|
||||
@@ -47,7 +47,7 @@ int owUpdate() {
|
||||
short sr;
|
||||
|
||||
//net.setStrongPullup();
|
||||
Serial.println(F("Searching"));
|
||||
debugSerial.println(F("Searching"));
|
||||
if (net) net->reset_search();
|
||||
for (short i = 0; i < t_count; i++) wstat[i] &= ~SW_FIND; //absent
|
||||
|
||||
@@ -58,18 +58,18 @@ int owUpdate() {
|
||||
if (!memcmp(term[i], term[t_count], 8)) {
|
||||
ifind = i;
|
||||
wstat[i] |= SW_FIND;
|
||||
Serial.print(F(" Node:"));
|
||||
PrintBytes(term[t_count], 8);
|
||||
Serial.println(F(" alive"));
|
||||
debugSerial.print(F(" Node:"));
|
||||
PrintBytes(term[t_count], 8,0);
|
||||
debugSerial.println(F(" alive"));
|
||||
break;
|
||||
}; //alive
|
||||
if (ifind < 0 && sensors) {
|
||||
wstat[t_count] = SW_FIND; //Newly detected
|
||||
Serial.print(F("dev#"));
|
||||
Serial.print(t_count);
|
||||
Serial.print(F(" Addr:"));
|
||||
PrintBytes(term[t_count], 8);
|
||||
Serial.println();
|
||||
debugSerial.print(F("dev#"));
|
||||
debugSerial.print(t_count);
|
||||
debugSerial.print(F(" Addr:"));
|
||||
PrintBytes(term[t_count], 8,0);
|
||||
debugSerial.println();
|
||||
if (term[t_count][0] == 0x28) {
|
||||
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
|
||||
net->setStrongPullup();
|
||||
@@ -80,8 +80,8 @@ int owUpdate() {
|
||||
}//if
|
||||
} //while
|
||||
|
||||
Serial.print(F("1-wire count: "));
|
||||
Serial.println(t_count);
|
||||
debugSerial.print(F("1-wire count: "));
|
||||
debugSerial.println(t_count);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -91,12 +91,12 @@ int owSetup(owChangedType owCh) {
|
||||
//// todo - move memory allocation to here
|
||||
if (net) return true; // Already initialized
|
||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||
Serial.println(F("DS2482_100_I2C_TO_1W_BRIDGE init"));
|
||||
debugSerial.println(F("DS2482_100_I2C_TO_1W_BRIDGE init"));
|
||||
net = new OneWire;
|
||||
#else
|
||||
Serial.print(F("One wire setup on PIN:"));
|
||||
Serial.println(QUOTE(USE_1W_PIN));
|
||||
net = new OneWire (USE_1W_PIN);
|
||||
debugSerial.print(F("One wire setup on PIN:"));
|
||||
debugSerial.println(QUOTE(USE_1W_PIN));
|
||||
net = new OneWire (USE_1W_PIN);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -112,29 +112,29 @@ net = new OneWire (USE_1W_PIN);
|
||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||
Wire.begin();
|
||||
if (net->checkPresence()) {
|
||||
Serial.println(F("DS2482-100 present"));
|
||||
debugSerial.println(F("DS2482-100 present"));
|
||||
net->deviceReset();
|
||||
#ifdef APU_OFF
|
||||
Serial.println(F("APU off"));
|
||||
debugSerial.println(F("APU off"));
|
||||
#else
|
||||
net->setActivePullup();
|
||||
#endif
|
||||
|
||||
Serial.println(F("\tChecking for 1-Wire devices..."));
|
||||
debugSerial.println(F("\tChecking for 1-Wire devices..."));
|
||||
if (net->wireReset())
|
||||
Serial.println(F("\tReset done"));
|
||||
debugSerial.println(F("\tReset done"));
|
||||
|
||||
sensors->begin();
|
||||
owChanged = owCh;
|
||||
//owUpdate();
|
||||
//Serial.println(F("\t1-w Updated"));
|
||||
//debugSerial.println(F("\t1-w Updated"));
|
||||
sensors->setWaitForConversion(false);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
Serial.println(F("\tDS2482 error"));
|
||||
debugSerial.println(F("\tDS2482 error"));
|
||||
return false;
|
||||
// IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
|
||||
|
||||
@@ -158,7 +158,7 @@ int sensors_loop(void) {
|
||||
|
||||
case 0x28: // Thermomerer
|
||||
t = sensors->getTempC(term[si]);//*10.0;
|
||||
//Serial.println("o");
|
||||
//debugSerial.println("o");
|
||||
if (owChanged) owChanged(si, term[si], t);
|
||||
sensors->requestTemperaturesByAddress(term[si]);
|
||||
si++;
|
||||
@@ -192,11 +192,11 @@ void owAdd(DeviceAddress addr) {
|
||||
memcpy(term[t_count], addr, 8);
|
||||
//term[t_count]=addr;
|
||||
|
||||
Serial.print(F("dev#"));
|
||||
Serial.print(t_count);
|
||||
Serial.print(F(" Addr:"));
|
||||
PrintBytes(term[t_count], 8);
|
||||
Serial.println();
|
||||
debugSerial.print(F("dev#"));
|
||||
debugSerial.print(t_count);
|
||||
debugSerial.print(F(" Addr:"));
|
||||
PrintBytes(term[t_count], 8,0);
|
||||
debugSerial.println();
|
||||
if (term[t_count][0] == 0x28) {
|
||||
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
|
||||
net->setStrongPullup();
|
||||
|
||||
@@ -19,6 +19,7 @@ e-mail anklimov@gmail.com
|
||||
*/
|
||||
|
||||
#include "utils.h"
|
||||
#include "options.h"
|
||||
|
||||
#if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32F1)
|
||||
#include <malloc.h>
|
||||
@@ -134,5 +135,61 @@ void parseBytes(const char *str, char separator, byte *bytes, int maxBytes, int
|
||||
str++; // Point to next character after separator
|
||||
}
|
||||
}
|
||||
|
||||
#define ARDBUFFER 16 //Buffer for storing intermediate strings. Performance may vary depending on size.
|
||||
|
||||
int log(const char *str, ...)//TODO: __FlashStringHelper str support
|
||||
{
|
||||
int i, count=0, j=0, flag=0;
|
||||
char temp[ARDBUFFER+1];
|
||||
for(i=0; str[i]!='\0';i++) if(str[i]=='%') count++; //Evaluate number of arguments required to be printed
|
||||
|
||||
va_list argv;
|
||||
va_start(argv, count);
|
||||
for(i=0,j=0; str[i]!='\0';i++) //Iterate over formatting string
|
||||
{
|
||||
if(str[i]=='%')
|
||||
{
|
||||
//Clear buffer
|
||||
temp[j] = '\0';
|
||||
Serial.print(temp);
|
||||
j=0;
|
||||
temp[0] = '\0';
|
||||
|
||||
//Process argument
|
||||
switch(str[++i])
|
||||
{
|
||||
case 'd': debugSerial.print(va_arg(argv, int));
|
||||
break;
|
||||
case 'l': debugSerial.print(va_arg(argv, long));
|
||||
break;
|
||||
case 'f': debugSerial.print(va_arg(argv, double));
|
||||
break;
|
||||
case 'c': debugSerial.print((char)va_arg(argv, int));
|
||||
break;
|
||||
case 's': debugSerial.print(va_arg(argv, char *));
|
||||
break;
|
||||
default: ;
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
//Add to buffer
|
||||
temp[j] = str[i];
|
||||
j = (j+1)%ARDBUFFER;
|
||||
if(j==0) //If buffer is full, empty buffer.
|
||||
{
|
||||
temp[ARDBUFFER] = '\0';
|
||||
debugSerial.print(temp);
|
||||
temp[0]='\0';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Serial.println(); //Print trailing newline
|
||||
return count + 1; //Return number of arguments detected
|
||||
}
|
||||
|
||||
|
||||
#pragma message(VAR_NAME_VALUE(debugSerial))
|
||||
#pragma message(VAR_NAME_VALUE(SERIAL_BAUD))
|
||||
@@ -25,10 +25,11 @@ e-mail anklimov@gmail.com
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
void PrintBytes(uint8_t* addr, uint8_t count, bool newline=0);
|
||||
void PrintBytes(uint8_t* addr, uint8_t count, bool newline);
|
||||
void SetBytes(uint8_t* addr, uint8_t count, char * out);
|
||||
void SetAddr(char * out, uint8_t* addr);
|
||||
uint8_t HEX2DEC(char i);
|
||||
int getInt(char ** chan);
|
||||
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, ...);
|
||||
@@ -10,10 +10,10 @@
|
||||
[platformio]
|
||||
src_dir = lighthub
|
||||
env_default =
|
||||
megaatmega2560
|
||||
; megaatmega2560
|
||||
; megaatmega2560-net
|
||||
; due
|
||||
; esp8266
|
||||
esp8266
|
||||
; esp32
|
||||
; megaatmega2560-5500
|
||||
; due-5500
|
||||
@@ -43,6 +43,8 @@ lib_deps =
|
||||
Adafruit Unified Sensor
|
||||
DHT sensor library for ESPx
|
||||
DHT sensor library
|
||||
Streaming
|
||||
https://github.com/Chris--A/PrintEx.git
|
||||
|
||||
[env:stm32]
|
||||
platform = ststm32
|
||||
@@ -119,6 +121,7 @@ lib_deps =
|
||||
Adafruit Unified Sensor
|
||||
DHT sensor library
|
||||
https://github.com/arcao/Syslog.git
|
||||
Streaming
|
||||
|
||||
[env:esp8266]
|
||||
platform = espressif8266
|
||||
@@ -142,6 +145,8 @@ lib_deps =
|
||||
DHT sensor library
|
||||
WifiManager
|
||||
https://github.com/arcao/Syslog.git
|
||||
https://github.com/livello/PrintEx.git#is-select-redecl
|
||||
Streaming
|
||||
|
||||
[env:megaatmega2560-net]
|
||||
platform = atmelavr
|
||||
@@ -174,6 +179,7 @@ framework = arduino
|
||||
board = due
|
||||
;lib_ldf_mode = chain+
|
||||
build_flags = -D Wiz5500 -D ARTNET_ENABLE
|
||||
build_flags = !sh build_flags_due-5500.sh
|
||||
lib_deps =
|
||||
https://github.com/sebnil/DueFlashStorage
|
||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
||||
@@ -192,6 +198,9 @@ lib_deps =
|
||||
Adafruit Unified Sensor
|
||||
DHT sensor library
|
||||
https://github.com/arcao/Syslog.git
|
||||
; Streaming
|
||||
; PrintEx
|
||||
https://github.com/livello/PrintEx.git#is-select-redecl
|
||||
|
||||
[env:controllino]
|
||||
platform = atmelavr
|
||||
|
||||
Reference in New Issue
Block a user