mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
Merge pull request #10 from livello/patch
refactoring. help cmd improved. Removed newline from freeMem periodic…
This commit is contained in:
111
README.md
111
README.md
@@ -1,7 +1,7 @@
|
|||||||
# LightHub
|
# LightHub
|
||||||
is Flexible, Arduino-Mega/Arduino DUE/ESP8266 based SmartHome controller
|
is Flexible, Arduino-Mega/Arduino DUE/ESP8266 based SmartHome controller. [RU](https://geektimes.ru/post/295109/)
|
||||||
|
|
||||||
It allow to connect together:
|
It allows connecting together:
|
||||||
|
|
||||||
* Contact sensors (switches, buttons etc)
|
* Contact sensors (switches, buttons etc)
|
||||||
* 1-Wire temperature sensors (up to 20 on single bus)
|
* 1-Wire temperature sensors (up to 20 on single bus)
|
||||||
@@ -12,24 +12,25 @@ It allow to connect together:
|
|||||||
|
|
||||||
Where is possible both, to configure local control/mapping between inputs and outputs (light, floor heating thermostats) and remote control from Openhab or Openhab2 Smarthome software
|
Where is possible both, to configure local control/mapping between inputs and outputs (light, floor heating thermostats) and remote control from Openhab or Openhab2 Smarthome software
|
||||||
|
|
||||||
Scalability is virtually unlimited: Setup so many controllers you needed in most convenient places of your house - MQTT broker will allow controllers communicate each other and with Openhab and propagate commands across network
|
Scalability is virtually unlimited: Setup so many controllers you needed in most convenient places of your house - MQTT broker will allow controllers communicate each other and with Openhab and propagate commands across network.
|
||||||
|
|
||||||
Prease refer our Wiki for insructions.
|
[Prease refer to our Wiki for insructions.](https://github.com/anklimov/lighthub/wiki/Configuring)
|
||||||
|
|
||||||
Finished portation of proejct to Arduino DUE and ESP8266 (ESP32 not tested)
|
Finished portation of project to Arduino DUE and ESP8266 (ESP32 not tested).
|
||||||
|
|
||||||
Compiled image has been added to compiled/ folder
|
Compiled image has been added to [compiled/](https://github.com/anklimov/lighthub/tree/master/compiled) folder. Flash your Mega 2560
|
||||||
use
|
|
||||||
|
```bash
|
||||||
avrdude -v -V -patmega2560 -cwiring -b115200 -D -Uflash:w:lighthub.ino.hex:i
|
avrdude -v -V -patmega2560 -cwiring -b115200 -D -Uflash:w:lighthub.ino.hex:i
|
||||||
to flash your Mega 2560
|
```
|
||||||
|
|
||||||
or
|
or flash your DUE (need to correct path and port, of course)
|
||||||
|
```bash
|
||||||
|
/Users/<user>/Library/Arduino15/packages/arduino/tools/bossac/1.6.1-arduino/bossac -i -d --port=cu.usbmodem1451 -U false -e -w -v -b lighthub.ino.bin -R
|
||||||
|
```
|
||||||
|
|
||||||
/Users/<user>/Library/Arduino15/packages/arduino/tools/bossac/1.6.1-arduino/bossac -i -d --port=cu.usbmodem1451 -U false -e -w -v -b lighthub.ino.bin -R
|
|
||||||
to flash your DUE
|
|
||||||
|
|
||||||
(need to correct path and port, of course)
|
# Dependencies
|
||||||
# Dependences
|
|
||||||
(quite big number of libs required. Use git clone to have your local copy in your Arduino libs folder)
|
(quite big number of libs required. Use git clone to have your local copy in your Arduino libs folder)
|
||||||
Please check updates for all dependences.
|
Please check updates for all dependences.
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ For patched libraries, appropriate GitHub repo URL provided:
|
|||||||
* DS2482_OneWire https://github.com/anklimov/DS2482_OneWire
|
* DS2482_OneWire https://github.com/anklimov/DS2482_OneWire
|
||||||
* FastLED
|
* FastLED
|
||||||
* Wire (standard)
|
* Wire (standard)
|
||||||
* Artnet https://github.com/anklimov/Artnet.git
|
* Artnet https://github.com/anklimov/Artnet.git
|
||||||
* DmxSimple https://github.com/anklimov/DmxSimple (for AVR) or https://github.com/anklimov/ESP-Dmx (for ESP) or https://github.com/anklimov/DmxDue (for DUE)
|
* DmxSimple https://github.com/anklimov/DmxSimple (for AVR) or https://github.com/anklimov/ESP-Dmx (for ESP) or https://github.com/anklimov/DmxDue (for DUE)
|
||||||
* HTTPClient (for AVR) https://github.com/anklimov/HTTPClient or https://github.com/arduino-libraries/ArduinoHttpClient for other platforms
|
* HTTPClient (for AVR) https://github.com/anklimov/HTTPClient or https://github.com/arduino-libraries/ArduinoHttpClient for other platforms
|
||||||
* aJson https://github.com/anklimov/aJson
|
* aJson https://github.com/anklimov/aJson
|
||||||
@@ -55,24 +56,24 @@ Portation from AVR Mega 2560 to SAM3X8E (Arduino DUE) done since v 0.96
|
|||||||
|
|
||||||
# Platforms specific details:
|
# Platforms specific details:
|
||||||
|
|
||||||
AVR version is basic and have all functions
|
AVR version is basic and has all functions
|
||||||
*DMX-out is software (DMXSimple) on pin3
|
*DMX-out is software (DMXSimple) on pin3
|
||||||
|
|
||||||
SAM3X8E:
|
**SAM3X8E**:
|
||||||
*default PWM frequency
|
* default PWM frequency
|
||||||
*both, DMX-in and DMX-out are hardware USART based. Use USART1 (pins 18 and 19) for DMX-out and DMX-in
|
* both, DMX-in and DMX-out are hardware USART based. Use USART1 (pins 18 and 19) for DMX-out and DMX-in
|
||||||
|
|
||||||
ESP:
|
**ESP8266**:
|
||||||
*DMX-OUT on USART1 TX
|
* DMX-OUT on USART1 TX
|
||||||
*DMX-IN - not possible to deploy in ESP8266
|
* DMX-IN - not possible to deploy in ESP8266
|
||||||
*Modbus - disabled. Might be configured in future on USART0 instead CLI/DEBUG
|
* Modbus - disabled. Might be configured in future on USART0 instead CLI/DEBUG
|
||||||
|
|
||||||
since v. 0.97:
|
since v. 0.97:
|
||||||
|
|
||||||
There is first attempt to use Wiznet 5500 (still not stable enough)
|
There is first attempt to use Wiznet 5500 (still not stable enough)
|
||||||
Need to use compiler directive -D Wiz5500 and https://github.com/anklimov/Ethernet2 library
|
Need to use compiler directive -D Wiz5500 and https://github.com/anklimov/Ethernet2 library
|
||||||
|
|
||||||
First attempt to use platformio toolchain for compiling (work not completed yet)
|
Prefered way to compile project is using platformio toolchain, suitable for Arduino Due, and Arduino Mega2560, but work is still in progress.
|
||||||
|
|
||||||
# Due compilation issue "USART0_Handler redefinition"
|
# Due compilation issue "USART0_Handler redefinition"
|
||||||
Please, open /variants/arduino_due_x/variant.cpp file, then edit USART0_Handler method definition like this
|
Please, open /variants/arduino_due_x/variant.cpp file, then edit USART0_Handler method definition like this
|
||||||
@@ -80,31 +81,60 @@ Please, open /variants/arduino_due_x/variant.cpp file, then edit USART0_Handler
|
|||||||
void USART0_Handler(void) __attribute__((weak));
|
void USART0_Handler(void) __attribute__((weak));
|
||||||
|
|
||||||
# Platformio command line build instructions
|
# Platformio command line build instructions
|
||||||
First of all install platformio framework. http://docs.platformio.org/en/latest/installation.html
|
[First of all install platformio framework.]( http://docs.platformio.org/en/latest/installation.html) [Good tutorial for fast start in RUSSIAN.](https://geektimes.ru/post/273852/)
|
||||||
|
|
||||||
https://geektimes.ru/post/273852/ // Good tutorial for fast start in RUSSIAN
|
In linux\macOS you can open terminal, navigate to your programming directory, then
|
||||||
|
|
||||||
In linux you can open terminal, navigate to your programming directory, then
|
```bash
|
||||||
|
git clone https://github.com/anklimov/lighthub.git
|
||||||
* git clone https://github.com/anklimov/lighthub.git
|
cd lighthub
|
||||||
* cd lighthub
|
```
|
||||||
* pio init --ide clion // use your IDE, others here: http://docs.platformio.org/en/latest/ide.html
|
now prepare project files for your IDE
|
||||||
* pio run -e due // this will build firmware for arduino due board
|
```bash
|
||||||
* rm -Rf .piolibdeps // this will clean libraries folder. Try it if you have compilation problem
|
pio init --ide [atom|clion|codeblocks|eclipse|emacs|netbeans|qtcreator|sublimetext|vim|visualstudio|vscode]
|
||||||
* pio run -e megaatmega2560 //build for arduino mega
|
```
|
||||||
* pio run -e due -t upload //build and upload firmware to arduino due
|
Set custom build flags. first make your own copy of template
|
||||||
|
```bash
|
||||||
|
cp build_flags_template.sh my_build_flags.sh
|
||||||
|
```
|
||||||
|
then edit, change or comment unnecessary sections and source it
|
||||||
|
```bash
|
||||||
|
nano my_build_flags.sh
|
||||||
|
source my_build_flags.sh
|
||||||
|
```
|
||||||
|
build and upload firmware for due|megaatmega2560|esp8266 board
|
||||||
|
```bash
|
||||||
|
pio run -e due|megaatmega2560|esp8266 -t upload
|
||||||
|
```
|
||||||
|
Clean pio libraries folder. Try it if you have compilation problem:
|
||||||
|
```bash
|
||||||
|
rm -Rf .piolibdeps
|
||||||
|
```
|
||||||
|
open COM-port monitor with specified baud rate
|
||||||
|
```bash
|
||||||
|
platformio device monitor -b 115200
|
||||||
|
```
|
||||||
|
|
||||||
# Custom build flags
|
# Custom build flags
|
||||||
|
|
||||||
* MY_CONFIG_SERVER=192.168.1.1 // address of external JSON-config http://192.168.1.1/de-ad-be-ef-fe-00.config.json
|
* MY_CONFIG_SERVER=192.168.1.1 // address of external JSON-config http://192.168.1.1/de-ad-be-ef-fe-00.config.json
|
||||||
* WATCH_DOG_TICKER_DISABLE=1 //disable wdt feature
|
* WATCH_DOG_TICKER_DISABLE //disable wdt feature
|
||||||
* USE_1W_PIN=49 // use direct connection to 1W devices, no I2C bridge DS2482-100
|
* USE_1W_PIN=49 // use direct connection to 1W devices on 49 pin, no I2C bridge DS2482-100
|
||||||
* SD_CARD_INSERTED=1 // enable sd-card support and fix lan starting
|
* SD_CARD_INSERTED // enable sd-card support and fix lan starting
|
||||||
* SERIAL_BAUD=115200 // set baud rate for console on Serial0
|
* SERIAL_BAUD=115200 // set baud rate for console on Serial0
|
||||||
* Wiz5500 //Use Wiznet 5500 library instead Wiznet 5100
|
* Wiz5500 //Use Wiznet 5500 library instead Wiznet 5100
|
||||||
|
* DISABLE_FREERAM_PRINT // disable printing free Ram in bytes
|
||||||
|
* CUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:00 //set firmware macaddress
|
||||||
|
* DMX_DISABLE //disable DMX support
|
||||||
|
* MODBUS_DISABLE // disable Modbus support
|
||||||
|
* OWIRE_DISABLE // disable OneWire support
|
||||||
|
|
||||||
|
Look at build_flags_template.sh for customizing.
|
||||||
|
=======
|
||||||
|
|
||||||
export PLATFORMIO_BUILD_FLAGS="-DMY_CONFIG_SERVER=192.168.1.1 -DWATCH_DOG_TICKER_DISABLE=1 -DUSE_1W_PIN=49 -DSERIAL_BAUD=115200 -DSD_CARD_INSERTED=1"
|
export PLATFORMIO_BUILD_FLAGS="-DMY_CONFIG_SERVER=192.168.1.1 -DWATCH_DOG_TICKER_DISABLE=1 -DUSE_1W_PIN=49 -DSERIAL_BAUD=115200 -DSD_CARD_INSERTED=1"
|
||||||
|
|
||||||
|
|
||||||
# Default compilation behavior:
|
# Default compilation behavior:
|
||||||
* Config server: lazyhome.ru
|
* Config server: lazyhome.ru
|
||||||
* Watchdog enabled
|
* Watchdog enabled
|
||||||
@@ -112,3 +142,10 @@ export PLATFORMIO_BUILD_FLAGS="-DMY_CONFIG_SERVER=192.168.1.1 -DWATCH_DOG_TICKER
|
|||||||
* No SD
|
* No SD
|
||||||
* Serial speed 115200
|
* Serial speed 115200
|
||||||
* Wiznet 5100 (for MEGA & DUE)
|
* Wiznet 5100 (for MEGA & DUE)
|
||||||
|
* Free Ram printing enabled
|
||||||
|
* de:ad:be:ef:fe:00
|
||||||
|
* DMX support enabled
|
||||||
|
* Modbus support enabled
|
||||||
|
* OneWire support enabled
|
||||||
|
=======
|
||||||
|
|
||||||
|
|||||||
21
build_flags_template.sh
Normal file
21
build_flags_template.sh
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
# usage:
|
||||||
|
# first make your own copy of template
|
||||||
|
# cp build_flags_template.sh my_build_flags.sh
|
||||||
|
# then edit, change or comment something
|
||||||
|
# nano my_build_flags.sh
|
||||||
|
# and source it
|
||||||
|
# source my_build_flags.sh
|
||||||
|
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:00"
|
||||||
|
export FLAGS="$FLAGS -DDMX_DISABLE"
|
||||||
|
export FLAGS="$FLAGS -DMODBUS_DISABLE"
|
||||||
|
export FLAGS="$FLAGS -DOWIRE_DISABLE"
|
||||||
|
export PLATFORMIO_BUILD_FLAGS="$FLAGS"
|
||||||
|
unset FLAGS
|
||||||
@@ -23,7 +23,7 @@ e-mail anklimov@gmail.com
|
|||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
|
|
||||||
extern PubSubClient client;
|
extern PubSubClient mqttClient;
|
||||||
|
|
||||||
Input::Input(char * name) //Constructor
|
Input::Input(char * name) //Constructor
|
||||||
{
|
{
|
||||||
@@ -80,7 +80,7 @@ void Input::Parse()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Input::Pool ()
|
int Input::Poll()
|
||||||
{
|
{
|
||||||
boolean v;
|
boolean v;
|
||||||
if (!isValid()) return -1;
|
if (!isValid()) return -1;
|
||||||
@@ -121,11 +121,11 @@ void Input::Changed (int val)
|
|||||||
|
|
||||||
if (val)
|
if (val)
|
||||||
{ //send set command
|
{ //send set command
|
||||||
if (!scmd) client.publish(emit->valuestring,"ON"); else if (strlen(scmd->valuestring)) client.publish(emit->valuestring,scmd->valuestring);
|
if (!scmd) mqttClient.publish(emit->valuestring,"ON"); else if (strlen(scmd->valuestring)) mqttClient.publish(emit->valuestring,scmd->valuestring);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ //send reset command
|
{ //send reset command
|
||||||
if (!rcmd) client.publish(emit->valuestring,"OFF"); else if (strlen(rcmd->valuestring)) client.publish(emit->valuestring,rcmd->valuestring);
|
if (!rcmd) mqttClient.publish(emit->valuestring,"OFF"); else if (strlen(rcmd->valuestring)) mqttClient.publish(emit->valuestring,rcmd->valuestring);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class Input
|
|||||||
boolean isValid ();
|
boolean isValid ();
|
||||||
void Changed (int val);
|
void Changed (int val);
|
||||||
|
|
||||||
int Pool ();
|
int Poll();
|
||||||
protected:
|
protected:
|
||||||
void Parse();
|
void Parse();
|
||||||
};
|
};
|
||||||
|
|||||||
1470
lighthub/item.cpp
1470
lighthub/item.cpp
File diff suppressed because it is too large
Load Diff
@@ -47,7 +47,7 @@ e-mail anklimov@gmail.com
|
|||||||
|
|
||||||
#include "aJSON.h"
|
#include "aJSON.h"
|
||||||
|
|
||||||
extern aJsonObject *items;
|
extern aJsonObject *items;
|
||||||
|
|
||||||
int txt2cmd (char * payload);
|
int txt2cmd (char * payload);
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ class Item
|
|||||||
inline int On (){Ctrl(CMD_ON);};
|
inline int On (){Ctrl(CMD_ON);};
|
||||||
inline int Off(){Ctrl(CMD_OFF);};
|
inline int Off(){Ctrl(CMD_OFF);};
|
||||||
inline int Toggle(){Ctrl(CMD_TOGGLE);};
|
inline int Toggle(){Ctrl(CMD_TOGGLE);};
|
||||||
int Pool ();
|
int Poll();
|
||||||
int SendCmd(short cmd,short n=0, int * Par=NULL);
|
int SendCmd(short cmd,short n=0, int * Par=NULL);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -5,11 +5,16 @@
|
|||||||
#ifndef LIGHTHUB_MAIN_H
|
#ifndef LIGHTHUB_MAIN_H
|
||||||
#define LIGHTHUB_MAIN_H
|
#define LIGHTHUB_MAIN_H
|
||||||
|
|
||||||
|
#define TXEnablePin 13
|
||||||
|
|
||||||
#ifndef SERIAL_BAUD
|
#ifndef SERIAL_BAUD
|
||||||
#define SERIAL_BAUD 115200
|
#define SERIAL_BAUD 115200
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef CUSTOM_FIRMWARE_MAC
|
||||||
|
#define FIRMWARE_MAC {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0}
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "DallasTemperature.h"
|
#include "DallasTemperature.h"
|
||||||
|
|
||||||
@@ -25,14 +30,14 @@ void Changed (int i, DeviceAddress addr, int val);
|
|||||||
void modbusIdle(void);
|
void modbusIdle(void);
|
||||||
void _handleHelp(int arg_cnt, char **args);
|
void _handleHelp(int arg_cnt, char **args);
|
||||||
void _kill(int arg_cnt, char **args);
|
void _kill(int arg_cnt, char **args);
|
||||||
void parseConfig();
|
void applyConfig();
|
||||||
void _loadConfig (int arg_cnt, char **args);
|
void _loadConfig (int arg_cnt, char **args);
|
||||||
int loadConfig (int arg_cnt, char **args);
|
int loadConfigFromEEPROM(int arg_cnt, char **args);
|
||||||
void _mqttConfigReq (int arg_cnt, char **args);
|
void _mqttConfigRequest(int arg_cnt, char **args);
|
||||||
int mqttConfigReq (int arg_cnt, char **args);
|
int mqttConfigRequest(int arg_cnt, char **args);
|
||||||
int mqttConfigResp (char * as);
|
int mqttConfigResp (char * as);
|
||||||
void _saveConfig(int arg_cnt, char **args);
|
void _saveConfigToEEPROM(int arg_cnt, char **args);
|
||||||
void _setConfig(int arg_cnt, char **args);
|
void _setMacAddress(int arg_cnt, char **args);
|
||||||
void _getConfig(int arg_cnt, char **args);
|
void _getConfig(int arg_cnt, char **args);
|
||||||
void printBool (bool arg);
|
void printBool (bool arg);
|
||||||
void saveFlash(short n, char* str);
|
void saveFlash(short n, char* str);
|
||||||
|
|||||||
@@ -1,8 +1,17 @@
|
|||||||
// Configuration of drivers enabled
|
// Configuration of drivers enabled
|
||||||
|
#ifndef DMX_DISABLE
|
||||||
#define _dmxin
|
#define _dmxin
|
||||||
#define _dmxout
|
#define _dmxout
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef OWIRE_DISABLE
|
||||||
#define _owire
|
#define _owire
|
||||||
#define _modbus
|
#endif
|
||||||
|
|
||||||
|
#ifndef MODBUS_DISABLE
|
||||||
|
#define _modbus
|
||||||
|
#endif
|
||||||
|
|
||||||
#define _artnet
|
#define _artnet
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
|
|||||||
@@ -22,67 +22,74 @@ e-mail anklimov@gmail.com
|
|||||||
#include "owTerm.h"
|
#include "owTerm.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
OneWire *net = NULL;
|
OneWire *net = NULL;
|
||||||
// Pass our oneWire reference to Dallas Temperature.
|
// Pass our oneWire reference to Dallas Temperature.
|
||||||
//DallasTemperature sensors(&net);
|
//DallasTemperature sensors(&net);
|
||||||
|
|
||||||
DeviceAddress *term = NULL;
|
DeviceAddress *term = NULL;
|
||||||
//int *regs = NULL;
|
//int *regs = NULL;
|
||||||
uint16_t *wstat = NULL;
|
uint16_t *wstat = NULL;
|
||||||
DallasTemperature *sensors = NULL;
|
DallasTemperature *sensors = NULL;
|
||||||
|
|
||||||
short si=0;
|
short si = 0;
|
||||||
int t_count = 0;
|
int t_count = 0;
|
||||||
unsigned long owTimer=0;
|
unsigned long owTimer = 0;
|
||||||
|
|
||||||
owChangedType owChanged;
|
owChangedType owChanged;
|
||||||
|
|
||||||
int owUpdate()
|
int owUpdate() {
|
||||||
{
|
unsigned long finish = millis() + 5000;
|
||||||
unsigned long finish = millis() + 5000;
|
short sr;
|
||||||
short sr;
|
|
||||||
|
|
||||||
//net.setStrongPullup();
|
|
||||||
Serial.println(F("Searching"));
|
|
||||||
if (net) net->reset_search();
|
|
||||||
for (short i=0;i<t_count;i++) wstat[i]&=~SW_FIND; //absent
|
|
||||||
|
|
||||||
while (net && net->wireSearch(term[t_count])>0 && (t_count<t_max) && finish > millis ())
|
//net.setStrongPullup();
|
||||||
{ short ifind=-1;
|
Serial.println(F("Searching"));
|
||||||
if (net->crc8(term[t_count], 7) == term[t_count][7])
|
if (net) net->reset_search();
|
||||||
{
|
for (short i = 0; i < t_count; i++) wstat[i] &= ~SW_FIND; //absent
|
||||||
for (short i=0;i<t_count;i++) 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"));
|
while (net && net->wireSearch(term[t_count]) > 0 && (t_count < t_max) && finish > millis()) {
|
||||||
break;}; //alive
|
short ifind = -1;
|
||||||
if (ifind<0 && sensors)
|
if (net->crc8(term[t_count], 7) == term[t_count][7]) {
|
||||||
{
|
for (short i = 0; i < t_count; i++)
|
||||||
wstat[t_count]=SW_FIND; //Newly detected
|
if (!memcmp(term[i], term[t_count], 8)) {
|
||||||
Serial.print(F("dev#"));Serial.print(t_count);Serial.print(F(" Addr:"));PrintBytes(term[t_count],8);
|
ifind = i;
|
||||||
Serial.println();
|
wstat[i] |= SW_FIND;
|
||||||
if (term[t_count][0]==0x28)
|
Serial.print(F(" Node:"));
|
||||||
{
|
PrintBytes(term[t_count], 8);
|
||||||
|
Serial.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();
|
||||||
|
if (term[t_count][0] == 0x28) {
|
||||||
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
|
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
|
||||||
net->setStrongPullup();
|
net->setStrongPullup();
|
||||||
// sensors.requestTemperaturesByAddress(term[t_count]);
|
// sensors.requestTemperaturesByAddress(term[t_count]);
|
||||||
}
|
}
|
||||||
t_count++;}
|
t_count++;
|
||||||
}//if
|
}
|
||||||
} //while
|
}//if
|
||||||
|
} //while
|
||||||
|
|
||||||
Serial.print(F("1-wire count: "));
|
Serial.print(F("1-wire count: "));
|
||||||
Serial.println(t_count);
|
Serial.println(t_count);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int owSetup(owChangedType owCh) {
|
int owSetup(owChangedType owCh) {
|
||||||
//// todo - move memory allocation to here
|
//// todo - move memory allocation to here
|
||||||
|
|
||||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||||
Serial.println(F("DS2482_100_I2C_TO_1W_BRIDGE init"));
|
Serial.println(F("DS2482_100_I2C_TO_1W_BRIDGE init"));
|
||||||
net = new OneWire;
|
net = new OneWire;
|
||||||
#else
|
#else
|
||||||
Serial.print(F("One wire setup on PIN:"));
|
Serial.print(F("One wire setup on PIN:"));
|
||||||
Serial.println(QUOTE(USE_1W_PIN));
|
Serial.println(QUOTE(USE_1W_PIN));
|
||||||
@@ -92,110 +99,104 @@ net = new OneWire (USE_1W_PIN);
|
|||||||
|
|
||||||
|
|
||||||
// Pass our oneWire reference to Dallas Temperature.
|
// Pass our oneWire reference to Dallas Temperature.
|
||||||
sensors = new DallasTemperature (net);
|
sensors = new DallasTemperature(net);
|
||||||
|
|
||||||
term = new DeviceAddress[t_max];
|
term = new DeviceAddress[t_max];
|
||||||
//regs = new int [t_max];
|
//regs = new int [t_max];
|
||||||
wstat = new uint16_t [t_max];
|
wstat = new uint16_t[t_max];
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
Wire.begin();
|
||||||
Wire.begin();
|
if (net->checkPresence()) {
|
||||||
if (net->checkPresence())
|
Serial.println(F("DS2482-100 present"));
|
||||||
{
|
net->deviceReset();
|
||||||
Serial.println(F("DS2482-100 present"));
|
#ifdef APU_OFF
|
||||||
net->deviceReset();
|
Serial.println(F("APU off"));
|
||||||
#ifdef APU_OFF
|
#else
|
||||||
Serial.println(F("APU off"));
|
net->setActivePullup();
|
||||||
#else
|
#endif
|
||||||
net->setActivePullup();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Serial.println(F("\tChecking for 1-Wire devices..."));
|
|
||||||
if (net->wireReset())
|
|
||||||
Serial.println(F("\tReset done"));
|
|
||||||
|
|
||||||
sensors->begin();
|
|
||||||
owChanged=owCh;
|
|
||||||
//owUpdate();
|
|
||||||
//Serial.println(F("\t1-w Updated"));
|
|
||||||
sensors->setWaitForConversion(false);
|
|
||||||
|
|
||||||
|
Serial.println(F("\tChecking for 1-Wire devices..."));
|
||||||
return true;
|
if (net->wireReset())
|
||||||
}
|
Serial.println(F("\tReset done"));
|
||||||
#endif
|
|
||||||
|
sensors->begin();
|
||||||
return false;
|
owChanged = owCh;
|
||||||
// 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
|
//owUpdate();
|
||||||
|
//Serial.println(F("\t1-w Updated"));
|
||||||
|
sensors->setWaitForConversion(false);
|
||||||
delay(500);
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
delay(500);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int sensors_loop(void)
|
int sensors_loop(void) {
|
||||||
{
|
if (!sensors) return -1;
|
||||||
if (!sensors) return -1;
|
if (si >= t_count) {
|
||||||
if (si>=t_count)
|
owUpdate(); //every check circle - scan for new devices
|
||||||
{
|
si = 0;
|
||||||
owUpdate(); //every check circle - scan for new devices
|
return 8000;
|
||||||
si=0;
|
}
|
||||||
return 8000;
|
|
||||||
}
|
int t;
|
||||||
|
switch (term[si][0]) {
|
||||||
|
|
||||||
|
case 0x28: // Thermomerer
|
||||||
|
t = sensors->getTempC(term[si]);//*10.0;
|
||||||
|
//Serial.println("o");
|
||||||
|
if (owChanged) owChanged(si, term[si], t);
|
||||||
|
sensors->requestTemperaturesByAddress(term[si]);
|
||||||
|
si++;
|
||||||
|
return 2500;
|
||||||
|
|
||||||
|
// default
|
||||||
|
// return sensors_ext();
|
||||||
|
} //switch
|
||||||
|
|
||||||
|
|
||||||
|
si++;
|
||||||
|
return check_circle;
|
||||||
|
|
||||||
int t;
|
|
||||||
switch (term[si][0]){
|
|
||||||
|
|
||||||
case 0x28: // Thermomerer
|
|
||||||
t=sensors->getTempC(term[si]);//*10.0;
|
|
||||||
//Serial.println("o");
|
|
||||||
if (owChanged) owChanged(si,term[si],t);
|
|
||||||
sensors->requestTemperaturesByAddress(term[si]);
|
|
||||||
si++;
|
|
||||||
return 2500;
|
|
||||||
|
|
||||||
// default
|
|
||||||
// return sensors_ext();
|
|
||||||
} //switch
|
|
||||||
|
|
||||||
|
|
||||||
si++;
|
|
||||||
return check_circle;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void owLoop()
|
void owLoop() {
|
||||||
|
if (millis() >= owTimer) owTimer = millis() + sensors_loop();
|
||||||
{
|
|
||||||
if (millis() >=owTimer) owTimer=millis()+sensors_loop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int owFind(DeviceAddress addr)
|
int owFind(DeviceAddress addr) {
|
||||||
{
|
for (short i = 0; i < t_count; i++) if (!memcmp(term[i], addr, 8)) return i;//find
|
||||||
for (short i=0;i<t_count;i++) if (!memcmp(term[i],addr,8)) return i;//find
|
return -1;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void owAdd (DeviceAddress addr)
|
void owAdd(DeviceAddress addr) {
|
||||||
{
|
wstat[t_count] = SW_FIND; //Newly detected
|
||||||
wstat[t_count]=SW_FIND; //Newly detected
|
memcpy(term[t_count], addr, 8);
|
||||||
memcpy (term[t_count],addr,8);
|
//term[t_count]=addr;
|
||||||
//term[t_count]=addr;
|
|
||||||
|
Serial.print(F("dev#"));
|
||||||
Serial.print(F("dev#"));Serial.print(t_count);Serial.print(F(" Addr:"));PrintBytes(term[t_count],8);
|
Serial.print(t_count);
|
||||||
Serial.println();
|
Serial.print(F(" Addr:"));
|
||||||
if (term[t_count][0]==0x28)
|
PrintBytes(term[t_count], 8);
|
||||||
{
|
Serial.println();
|
||||||
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
|
if (term[t_count][0] == 0x28) {
|
||||||
net->setStrongPullup();
|
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
|
||||||
// sensors.requestTemperaturesByAddress(term[t_count]);
|
net->setStrongPullup();
|
||||||
}
|
// sensors.requestTemperaturesByAddress(term[t_count]);
|
||||||
t_count++;
|
}
|
||||||
|
t_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ e-mail anklimov@gmail.com
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__)
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -29,63 +30,62 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void PrintBytes(uint8_t* addr, uint8_t count, bool newline) {
|
void PrintBytes(uint8_t *addr, uint8_t count, bool newline) {
|
||||||
for (uint8_t i = 0; i < count; i++) {
|
for (uint8_t i = 0; i < count; i++) {
|
||||||
Serial.print(addr[i]>>4, HEX);
|
Serial.print(addr[i] >> 4, HEX);
|
||||||
Serial.print(addr[i]&0x0f, HEX);
|
Serial.print(addr[i] & 0x0f, HEX);
|
||||||
}
|
}
|
||||||
if (newline)
|
if (newline)
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char HEXSTR[]="0123456789ABCDEF";
|
const char HEXSTR[] = "0123456789ABCDEF";
|
||||||
|
|
||||||
|
void SetBytes(uint8_t *addr, uint8_t count, char *out) {
|
||||||
|
// Serial.println("SB:");
|
||||||
|
for (uint8_t i = 0; i < count; i++) {
|
||||||
|
*(out++) = HEXSTR[(addr[i] >> 4)];
|
||||||
|
*(out++) = HEXSTR[(addr[i] & 0x0f)];
|
||||||
|
}
|
||||||
|
*out = 0;
|
||||||
|
|
||||||
void SetBytes(uint8_t* addr, uint8_t count, char * out) {
|
|
||||||
// Serial.println("SB:");
|
|
||||||
for (uint8_t i = 0; i < count; i++) {
|
|
||||||
*(out++)=HEXSTR[(addr[i]>>4)];
|
|
||||||
*(out++)=HEXSTR[(addr[i]&0x0f)];
|
|
||||||
}
|
|
||||||
*out=0;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
byte HEX2DEC(char i)
|
byte HEX2DEC(char i) {
|
||||||
{ byte v;
|
byte v;
|
||||||
if ('a' <= i && i <='f') { v=i-97+10; }
|
if ('a' <= i && i <= 'f') { v = i - 97 + 10; }
|
||||||
else if ('A' <= i && i <='F') { v=i-65+10; }
|
else if ('A' <= i && i <= 'F') { v = i - 65 + 10; }
|
||||||
else if ('0' <= i && i <='9') { v=i-48; }
|
else if ('0' <= i && i <= '9') { v = i - 48; }
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetAddr(char * out, uint8_t* addr) {
|
void SetAddr(char *out, uint8_t *addr) {
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 8; i++) {
|
for (uint8_t i = 0; i < 8; i++) {
|
||||||
*addr=HEX2DEC(*out++)<<4;
|
*addr = HEX2DEC(*out++) << 4;
|
||||||
*addr++|=HEX2DEC(*out++);
|
*addr++ |= HEX2DEC(*out++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int getInt(char ** chan)
|
int getInt(char **chan) {
|
||||||
{
|
int ch = atoi(*chan);
|
||||||
int ch = atoi(*chan);
|
*chan = strchr(*chan, ',');
|
||||||
*chan=strchr(*chan,',');
|
|
||||||
|
if (*chan) *chan += 1;
|
||||||
if (*chan) *chan+=1;
|
//Serial.print(F("Par:")); Serial.println(ch);
|
||||||
//Serial.print(F("Par:")); Serial.println(ch);
|
return ch;
|
||||||
return ch;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
unsigned long freeRam ()
|
unsigned long freeRam ()
|
||||||
{return system_get_free_heap_size();}
|
{return system_get_free_heap_size();}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__AVR__)
|
#if defined(__AVR__)
|
||||||
unsigned long freeRam ()
|
unsigned long freeRam ()
|
||||||
{
|
{
|
||||||
extern int __heap_start, *__brkval;
|
extern int __heap_start, *__brkval;
|
||||||
@@ -98,14 +98,25 @@ unsigned long freeRam ()
|
|||||||
extern char _end;
|
extern char _end;
|
||||||
extern "C" char *sbrk(int i);
|
extern "C" char *sbrk(int i);
|
||||||
|
|
||||||
unsigned long freeRam()
|
unsigned long freeRam() {
|
||||||
{
|
char *ramstart = (char *) 0x20070000;
|
||||||
char *ramstart = (char *) 0x20070000;
|
char *ramend = (char *) 0x20088000;
|
||||||
char *ramend = (char *) 0x20088000;
|
char *heapend = sbrk(0);
|
||||||
char *heapend = sbrk(0);
|
register char *stack_ptr asm( "sp" );
|
||||||
register char * stack_ptr asm( "sp" );
|
struct mallinfo mi = mallinfo();
|
||||||
struct mallinfo mi = mallinfo();
|
|
||||||
|
return stack_ptr - heapend + mi.fordblks;
|
||||||
return stack_ptr - heapend + mi.fordblks;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
#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
|
||||||
|
str = strchr(str, separator); // Find next separator
|
||||||
|
if (str == NULL || *str == '\0') {
|
||||||
|
break; // No more separators, exit
|
||||||
|
}
|
||||||
|
str++; // Point to next character after separator
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,3 +25,4 @@ void SetAddr(char * out, uint8_t* addr);
|
|||||||
uint8_t HEX2DEC(char i);
|
uint8_t HEX2DEC(char i);
|
||||||
int getInt(char ** chan);
|
int getInt(char ** chan);
|
||||||
unsigned long freeRam ();
|
unsigned long freeRam ();
|
||||||
|
void parseBytes(const char* str, char separator, byte* bytes, int maxBytes, int base);
|
||||||
@@ -11,7 +11,8 @@
|
|||||||
src_dir = lighthub
|
src_dir = lighthub
|
||||||
env_default =
|
env_default =
|
||||||
; megaatmega2560
|
; megaatmega2560
|
||||||
due
|
due
|
||||||
|
; esp8266
|
||||||
|
|
||||||
[env:due]
|
[env:due]
|
||||||
platform = atmelsam
|
platform = atmelsam
|
||||||
@@ -101,7 +102,7 @@ lib_deps =
|
|||||||
https://github.com/anklimov/Artnet.git
|
https://github.com/anklimov/Artnet.git
|
||||||
FastLED
|
FastLED
|
||||||
|
|
||||||
[env:espressif8266]
|
[env:esp8266]
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
framework = arduino
|
framework = arduino
|
||||||
board = nodemcuv2
|
board = nodemcuv2
|
||||||
|
|||||||
Reference in New Issue
Block a user