MQTT subscribe fix, AnalogIn fix, first attempt to compile for NRF5

This commit is contained in:
2019-02-04 01:38:46 +03:00
parent 8d87f09e29
commit 064ef6f007
17 changed files with 151 additions and 38 deletions

Binary file not shown.

View File

@@ -1,5 +1,4 @@
{
"board": "esp8266:esp8266:d1",
"configuration": "CpuFrequency=80,FlashSize=4M1M,LwIPVariant=v2mss536,Debug=Disabled,DebugLevel=None____,UploadSpeed=921600",
"board": "arduino:sam:arduino_due_x",
"port": "/dev/cu.usbmodem1411"
}

View File

@@ -5,6 +5,8 @@
"name": "Mac",
"macFrameworkPath": [],
"includePath": [
"/Users/andrey/Library/Arduino15/packages/arduino/tools/**",
"/Users/andrey/Library/Arduino15/packages/arduino/hardware/sam/1.6.11/**",
"/Users/andrey/.platformio/packages/framework-arduinosam/cores/sam",
"/Users/andrey/.platformio/packages/framework-arduinosam/system/sam/libsam",
"/Users/andrey/.platformio/packages/framework-arduinosam/system/sam/CMSIS/CMSIS/Include",
@@ -31,12 +33,7 @@
"/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/Streaming_ID560",
"/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/Syslog/src",
"/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/aJson",
"/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/ArduinoJson_ID64/src",
"/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/AsyncMqttClient_ID346/src",
"/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/Bounce2_ID1106/src",
"/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/ESP Async WebServer_ID306/src",
"/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/Homie_ID555/src",
"/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/HttpClient_ID66",
"/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/Ethernet2_ID261/src",
"/Users/andrey/.platformio/packages/framework-arduinosam/libraries/__cores__/sam/HID/src",
"/Users/andrey/.platformio/packages/tool-unity",
"/Users/andrey/Documents/Arduino/lighthub/include",
@@ -73,12 +70,7 @@
"/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/Streaming_ID560",
"/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/Syslog/src",
"/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/aJson",
"/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/ArduinoJson_ID64/src",
"/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/AsyncMqttClient_ID346/src",
"/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/Bounce2_ID1106/src",
"/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/ESP Async WebServer_ID306/src",
"/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/Homie_ID555/src",
"/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/HttpClient_ID66",
"/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/Ethernet2_ID261/src",
"/Users/andrey/.platformio/packages/framework-arduinosam/libraries/__cores__/sam/HID/src",
"/Users/andrey/.platformio/packages/tool-unity",
"/Users/andrey/Documents/Arduino/lighthub/include",
@@ -87,7 +79,7 @@
]
},
"defines": [
"PLATFORMIO=30603",
"PLATFORMIO=40000",
"__SAM3X8E__",
"ARDUINO_ARCH_SAM",
"ARDUINO_SAM_DUE",
@@ -106,7 +98,10 @@
"intelliSenseMode": "clang-x64",
"cStandard": "c11",
"cppStandard": "c++11",
"compilerPath": "/Users/andrey/.platformio/packages/toolchain-gccarmnoneeabi@1.40804.0/bin/arm-none-eabi-gcc -mthumb -mcpu=cortex-m3"
"compilerPath": "/Users/andrey/.platformio/packages/toolchain-gccarmnoneeabi@1.40804.0/bin/arm-none-eabi-gcc -mthumb -mcpu=cortex-m3",
"forcedInclude": [
"/Users/andrey/Library/Arduino15/packages/arduino/hardware/sam/1.6.11/cores/arduino/Arduino.h"
]
}
],
"version": 4

View File

@@ -1,6 +1,6 @@
{
"terminal.integrated.env.osx": {
"PATH": "/Users/andrey/.platformio/penv/bin:/Users/andrey/.platformio/penv:/usr/local/opt/python@2/bin:/opt/local/sbin:/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Applications/Wireshark.app/Contents/MacOS",
"PATH": "/Users/andrey/.platformio/penv/bin:/Users/andrey/.platformio/penv:/usr/local/opt/ruby/bin:/usr/local/opt/python@2/bin:/opt/local/sbin:/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Applications/Wireshark.app/Contents/MacOS",
"PLATFORMIO_CALLER": "vscode"
}
}

View File

@@ -1,4 +1,5 @@
#! /bin/bash
export FLAGS="$FLAGS -DMODBUS_DISABLE"
CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_esp8266.sh
if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then
source $CUSTOM_BUILD_FLAGS_FILE

View File

@@ -0,0 +1,7 @@
#! /bin/bash
export FLAGS="$FLAGS -DWiz5500"
CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_nrf52840.sh
if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then
source $CUSTOM_BUILD_FLAGS_FILE
fi
echo $FLAGS

View File

@@ -6,7 +6,7 @@
# nano my_build_flags.sh
# and source it
# source my_build_flags.sh
#export FLAGS="-DMY_CONFIG_SERVER=lighthub.elistech.ru"
#export FLAGS="$FLAGS -DMY_CONFIG_SERVER=lighthub.elistech.ru"
#export FLAGS="$FLAGS -DWATCH_DOG_TICKER_DISABLE"
#export FLAGS="$FLAGS -DUSE_1W_PIN=12"
#export FLAGS="$FLAGS -DSD_CARD_INSERTED"

View File

@@ -3,7 +3,7 @@
# 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 -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"

View File

@@ -0,0 +1,31 @@
#! /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="$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:ff"
export FLAGS="$FLAGS -DDMX_DISABLE"
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 -DWIFI_MANAGER_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 -DSYSLOG_DISABLE"
export FLAGS="$FLAGS -std=gnu++11"
#export FLAGS="$FLAGS -DDEVICE_NAME=MYDEVICE"
export FLAGS="$FLAGS -DDHT_COUNTER_DISABLE"
#export FLAGS="$FLAGS -DWITH_PRINTEX_LIB"
export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short)
echo $FLAGS

View File

@@ -3,7 +3,7 @@
# 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 -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"

View File

@@ -332,9 +332,9 @@ void Input::contactPoll() {
WiringPinMode inputPinMode;
#endif
#if defined(__SAM3X8E__)||defined(ARDUINO_ARCH_AVR)||defined(ARDUINO_ARCH_ESP8266)||defined(ARDUINO_ARCH_ESP32)
uint32_t inputPinMode;
#endif
#endif
uint32_t inputPinMode;
uint8_t inputOnLevel;
if (inType & IN_ACTIVE_HIGH) {
inputOnLevel = HIGH;
@@ -375,10 +375,10 @@ void Input::analogPoll() {
#if defined(ARDUINO_ARCH_STM32F1)
WiringPinMode inputPinMode;
#endif
#if defined(__SAM3X8E__)||defined(ARDUINO_ARCH_AVR)||defined(ARDUINO_ARCH_ESP8266)||defined(ARDUINO_ARCH_ESP32)
uint32_t inputPinMode;
#endif
#if defined(__SAM3X8E__)||defined(ARDUINO_ARCH_AVR)||defined(ARDUINO_ARCH_ESP8266)||defined(ARDUINO_ARCH_ESP32)
#endif
uint32_t inputPinMode;
if (inType & IN_ACTIVE_HIGH) {
inputPinMode = INPUT;
} else {
@@ -389,24 +389,25 @@ void Input::analogPoll() {
// Mapping
if (inputMap && inputMap->type == aJson_Array)
{
int max;
if (aJson.getArraySize(inputMap)>=4)
mappedInputVal = map (mappedInputVal,
aJson.getArrayItem(inputMap, 0)->valueint,
aJson.getArrayItem(inputMap, 1)->valueint,
aJson.getArrayItem(inputMap, 2)->valueint,
aJson.getArrayItem(inputMap, 3)->valueint);
max=aJson.getArrayItem(inputMap, 3)->valueint);
if (aJson.getArraySize(inputMap)==5) Noize = aJson.getArrayItem(inputMap, 4)->valueint;
if (mappedInputVal>max) mappedInputVal=max;
if (aJson.getArraySize(inputMap)==2)
{
simple = 1;
if (mappedInputVal < aJson.getArrayItem(inputMap, 0)->valueint) mappedInputVal = 0;
else if (mappedInputVal > aJson.getArrayItem(inputMap, 1)->valueint) mappedInputVal = 1;
else mappedInputVal = -1;
else return;
}
}
if (simple) {
if (mappedInputVal!=-1 && mappedInputVal != store->currentValue)
if (mappedInputVal != store->currentValue)
{
onContactChanged(mappedInputVal);
store->currentValue = mappedInputVal;

View File

@@ -218,7 +218,7 @@ int Item::Ctrl(char * payload, boolean send){
case -1: //Not known command
case -2: //JSON input (not implemented yet
break;
#if not defined(ARDUINO_ARCH_ESP32) and not defined(ESP8266) and not defined(ARDUINO_ARCH_STM32F1)
#if not defined(ARDUINO_ARCH_ESP32) and not defined(ESP8266) and not defined(ARDUINO_ARCH_STM32F1) and not defined(DMX_DISABLE)
case -3: //RGB color in #RRGGBB notation
{
CRGB rgb;

View File

@@ -109,6 +109,12 @@ WiFiClient ethClient;
EthernetClient ethClient;
#endif
#ifdef NRF5
#include <NRFFlashStorage.h>
NRFFlashStorage EEPROM;
EthernetClient ethClient;
#endif
#ifdef SYSLOG_ENABLE
#include <Syslog.h>
EthernetUDP udpSyslogClient;
@@ -491,12 +497,13 @@ void ip_ready_config_loaded_connecting_to_broker() {
strncpy_P(buf, outprefix, sizeof(buf));
strncat(buf, "#", sizeof(buf));
mqttClient.subscribe(buf,MQTTQOS1);
mqttClient.subscribe(buf);
//Subscribing for command topics
strncpy_P(buf, inprefix, sizeof(buf));
strncat(buf, "#", sizeof(buf));
mqttClient.subscribe(buf,MQTTQOS1);
Serial.println(buf);
mqttClient.subscribe(buf);
//restoreState();
onMQTTConnect();
@@ -738,7 +745,7 @@ void cmdFunctionKill(int arg_cnt, char **args) {
void cmdFunctionReboot(int arg_cnt, char **args) {
debugSerial<<F("Soft rebooting...");
softRebootFunc();
//// softRebootFunc();
}
void applyConfig() {

View File

@@ -29,6 +29,12 @@
#define wdt_dis()
#endif
#if defined(NRF5)
#define wdt_res()
#define wdt_en()
#define wdt_dis()
#endif
//#if defined(ESP8266)
//#define wdt_res()
//#define wdt_en()
@@ -66,7 +72,7 @@
#include <ModbusMaster.h>
#endif
#ifndef ARDUINO_ARCH_STM32F1
#ifndef DMX_DISABLE
#include "FastLED.h"
#endif
@@ -108,7 +114,7 @@
#endif
#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__) || defined(ESP8266)
#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__) || defined(ESP8266) || defined(NRF5)
#ifdef Wiz5500
#include <Ethernet2.h>
#else

View File

@@ -66,7 +66,7 @@
#endif
#ifndef OUTTOPIC
#define OUTTOPIC "homie/s_out/"
#define OUTTOPIC "/myhome/s_out/"
#endif
#ifndef CMDTOPIC

View File

@@ -126,6 +126,23 @@ unsigned long freeRam() {
#endif
#if defined(NRF5)
extern char _end;
extern "C" char *sbrk(int i);
unsigned long freeRam() {
char *ramstart = (char *) 0x20070000;
char *ramend = (char *) 0x20088000;
char *heapend = sbrk(0);
register char *stack_ptr asm( "sp" );
//struct mallinfo mi = mallinfo();
return stack_ptr - heapend;// + mi.fordblks;
}
#endif
void parseBytes(const char *str, char separator, byte *bytes, int maxBytes, int base) {
for (int i = 0; i < maxBytes; i++) {
bytes[i] = strtoul(str, NULL, base); // Convert byte

View File

@@ -24,6 +24,46 @@ env_default = due-5500
;build_dir = /tmp/pioenvs
;libdeps_dir = /tmp/piolibdeps
[env:nrf52840_dk]
platform = nordinrf52
board = nrf52840_dk
;upload_protocol = mbed
;upload_port = /dev/cu.SLAB_USBtoUART
framework = arduino
build_flags = !bash check_custom_build_flags_nrf52840.sh
lib_ignore =
DmxSimple
DMXSerial
DmxDue
EEPROM
SD
SdFat
WifiManager
Ethernet
Ethernet3
httpClient
FastLED
ESPDMX
DueFlashStorage
PrintEx
; Adafruit_Sensor
lib_deps =
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
https://github.com/anklimov/DS2482_OneWire
Ethernet2
ESP8266HTTPClient
https://github.com/anklimov/aJson
https://github.com/anklimov/CmdArduino
https://github.com/anklimov/ModbusMaster
https://github.com/knolleary/pubsubclient.git
; https://github.com/anklimov/Artnet.git
; FastLED
Adafruit Unified Sensor
; DHT sensor library for ESPx
DHT sensor library
Streaming
https://github.com/anklimov/NRFFlashStorage
; https://github.com/livello/PrintEx#is-select-redecl
[env:esp32-evb]
@@ -44,6 +84,7 @@ lib_ignore =
Ethernet
Ethernet2
httpClient
NRFFlashStorage
lib_deps =
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
https://github.com/anklimov/DS2482_OneWire
@@ -59,7 +100,7 @@ lib_deps =
DHT sensor library for ESPx
DHT sensor library
Streaming
https://github.com/livello/PrintEx#is-select-redecl
; https://github.com/livello/PrintEx#is-select-redecl
[env:esp32]
@@ -80,6 +121,7 @@ lib_ignore =
Ethernet2
HTTPClient
httpClient
NRFFlashStorage
lib_deps =
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
https://github.com/anklimov/DS2482_OneWire
@@ -110,6 +152,7 @@ lib_ignore =
ESPDMX
WifiManager
Ethernet3
NRFFlashStorage
lib_deps =
https://github.com/sebnil/DueFlashStorage
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
@@ -144,6 +187,7 @@ lib_ignore =
WifiManager
Ethernet3
HTTPClient
NRFFlashStorage
lib_deps =
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
https://github.com/anklimov/DS2482_OneWire
@@ -177,6 +221,7 @@ lib_ignore =
SdFat
httpClient
Ethernet3
NRFFlashStorage
lib_deps =
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
https://github.com/anklimov/DS2482_OneWire
@@ -209,6 +254,7 @@ lib_ignore =
WifiManager
Ethernet3
Ethernet2
NRFFlashStorage
lib_deps =
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
https://github.com/anklimov/DS2482_OneWire
@@ -244,6 +290,7 @@ lib_ignore =
httpClient
Ethernet
Ethernet3
NRFFlashStorage
lib_deps =
https://github.com/sebnil/DueFlashStorage
@@ -279,6 +326,7 @@ lib_ignore =
WifiManager
Ethernet3
Ethernet2
NRFFlashStorage
lib_deps =
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
https://github.com/anklimov/DS2482_OneWire
@@ -322,6 +370,7 @@ lib_ignore =
Ethernet2
Artnet
Ethernet3
NRFFlashStorage
lib_deps =