Инструменты пользователя

Инструменты сайта


Boot sequence:

  • Trying to load JSON config from NVRAM. If config is valid JSON structure - start to operating (to avoid dependance from network and allow local control)
  • Trying to retrieve MAC address, stored in NVRAM. If ok - using retrieved MAC. If not - using CUSTOM_FIRMWARE_MAC (see compilers directives). If not configured - using hardcoded DEFAULT_FIRMWARE_MAC = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0}
  • Starting LAN with DHCP or with static ip if configured
  • Trying to load JSON config from address «http://MY_CONFIG_SERVER/12-12-12-12-12-12.config.json», where «12-12….12» is controller's MAC address and MY_CONFIG_SERVER - compiler's directive. If not configured = lazyhome.ru used
  • After parsing of loaded config, performing re-initialization of objects, except number of DMX channels. There is possible to store loaded config in NVRAM after some testing using «save» cli command.
  • Connecting to MQTT server according stored or retrieved config.
  • Subscribing to OUTTOPIC (/myhome/s_out/# by default) for 5 sec. Retrieving and executing all persistent topic (restore recent values)
  • Unsubscribe from OUTTOPIC, Subscribe for INTOPIC (/myhome/in/# by default) and start processing normal incoming event flow


During normal operation, controller:

  • Accepting incoming MQTT message flow and retrieving item name from topic name. For example, /myhome/in/item1 will control «item1»
  • Controlling items.
  • Most commands, accepted on INTOPIC passed throw to OUTTOPIC after interpretation. Interpretation is converting of high level commands like ON OFF HALT REST to low-level commands with real values. OUTTOPIC publishing uses «persistent» flag to allow retrieving recent status from MQTT broker after restart of controller
  • Polling: Normally, Modbus devices and 1-wire thermometers are polled with reasonable interval. Retrieved values are publishing to OUTTOPIC

Useful CLI commands:

  • mac 11:22:33:44:55:66 - writing custom MAC address to NVRAM
  • save - writing currently loaded config from RAM to NVRAM
  • get <servername> - retrieve config from server and store servername to NVRAM (default servername: lazyhome.ru)
  • ip [ip[ dns[ gw[ subnet]]]] - configure and save to NVRAM static ip. if no parameters - DHCP will be used
  • load - load config from NVRAM
  • kill - test watchdog timer (normally, causes reboot)

CLI commands must be send via serial port with 115200 baud rate / 8N1 params: 8 data bits, no parity bit, 1 stop bit.

Example via shell:

> stty -f /dev/cu.usbmodem146101 ispeed 115200 ospeed 115200 -parenb cs8 cstopb
> echo "ip" > /dev/cu.usbmodem146101
> cat /dev/cu.usbmodem146101

Same can be done via GUI e.g. from Arduino IDE (serial monitor). Serial port must be configured (MacOSX config file ~/Library/Arduino15/preferences.txt)


The example of config files you can find in config folder Note: in real configs comments are not allowed Below is brief explanation of basic configuration values:

  "mqtt":["mqtt_id","host",port,"user","pass"], //ip address/name and client id of mqtt broker. Port, user, pass - are optional 

// 1-Wire configuration chapter. "device#":{"emit":"mqtt topic suffix to report temp. measurements", "item":"local ite$
                 "284811170400005B":{"emit":"t_entr"},  //reports temp to mqtt /myhome/s_out/t_entr

Every Lighthub's object are «item»: lamp, dimmer, termostat, relay, led etc item is accessible via mqtt bus as /myhome/in/itemname

#define I_TYPE 0 //Type of item
#define I_ARG  1 //Chanel-type depended argument or array of arguments (pin, address etc)
#define I_VAL  2 //Latest preset (int or array of presets)
#define I_CMD  3 //Latest CMD received
#define I_EXT  4 //Chanell-depended extension - array

There are two mandatory elements in item's array: type and address 1-st element of array is item type

# Item types:

# of type ID Note Parameters
0 DIMMERDMX out 1 ch
1 RGBW DMX out 4 ch
2 RGB DMX out 3 ch
3 PWM PWM output directly to PIN
4 MODBUSModbus AC Dimmer
5 THERMOSimple ON/OFF thermostat
6 RELAY ON_OFF relay output
7 GROUP Group pseudochannel
8 VCTEMPVacom PID thermo - regulator (Ventilation set)
9 VC Vacom modbus motor regulator
10AC 10Air Conditioner Haier
12MOTOR Motorized air gateway
13PID PID regulator
14MBUS Universal Modbus channel
18MULTIVENT Multiroom ventilation set

Address is channel depended. Pin# for relay, DMX address for DMX-512 channel, array for Modbus channel. In case of DMX item note that addressees are continuous numbering between decoders and start address of each decoders configurable by jumpers. E.g. if you have two 24-ch decoders and want to control all 48 channels then you must set address «1» on the first decoder and «25» on the second.

// Example of array

// Examples of Thermostate items  [type,pin,temperatureC]
        "h_entr" :[5,35,32],
// Examples of relay items [type, pin, preset, default command]
        "h_boil1":[6,23],             // simple relay on pin 23
        "h_boil2":[6,28,1,1],         // relay, turned on by default (after reboot)

Inputs configuration chapter

// "in" syntax
// "pin": { "T":type, "emit":"out_emit", item:"out_item", "scmd": "ON,OFF,TOGGLE,INCREASE,DECREASE", "rcmd": "ON,OFF,TO$

//Switch/Restore all
//"pin": { "T":1, "emit":"/myhome/in/all", item:"local_all", "scmd": "OFF", "rcmd": "RESTORE"}

//Normal (not button) Switch (toggled mode)
//"pin": { "T":1, "emit":"/light1", item:"light1", "scmd": "TOGGLE", "rcmd": "TOGGLE"} //not deployed yet

//Normal (not button) Switch
//"pin": { "T":0, "emit":"/light1", item:"light1", "scmd": "ON", "rcmd": "OFF"}
// or
// "pin": { "T":0, "emit":"/light1", item:"light1"}
// "pin": { "emit":"/light1", item:"light1"}

//1-Button dimmer //not deployed yet
//"pin": { "T":1, "emit":"/light1", item:"light1", "scmd": "ON", srcmd:"INCREASE",rrcmd:"DECREASE",  "rcmd": "OFF"}

//2-Buttons dimmer
//"pin1": { "T":0, "emit":"/light1", item:"light1", "scmd": "ON", repcmd:"INCREASE"}
//"pin2": { "T":0, "emit":"/light1", item:"light1", "scmd": "OFF", repcmd:"INCREASE"}

          "41":{"T":0,"emit":"/myhome/in/all","scmd":"HALT","rcmd":"REST"}, //Emits HALT on close contact, REST on open
          "37":{"item":"spots_en","scmd":"TOGGLE","rcmd":"TOGGLE"}, //Toggle on/off local spots every changing state of PIN
          "38":{"emit":"/myhome/in/light","scmd":"TOGGLE","rcmd":"TOGGLE"}, //Toggle remote light on local switch
          "40":{"T":1,"emit":"/myhome/out/all","scmd":"HALT","rcmd":"REST"}, ////not deployed yet

Modbus channel

Currently, Lighthub working with Vacom 10 frequency driver (from Danfos) via Modbus RTU and allows control frequency (item type = 9) and internal PID controller (item type = 8 - used for Temperature control) Additionally, performing polling parameters from Vacom and publishing in JSON format to status MQTT Topic

If you just need to write some Modbus register on MQTT command & poll it back with simple scaling - you can use item type #4 (Modbus dimmer)

Config example (refer https://github.com/anklimov/lighthub/wiki/Configuring):

  "items": {

Note: this config example available at URL http://lazyhome.ru/de-ad-be-ef-fe-07.config.json - so just set mac address of device by command “mac de:ad:be:ef:fe:07” for test.

Item notation:

  • 4 - Modbus dimmer item type
  • Param1: = 96 - Decimal address of modbus device
  • Param2: = 0 - Modbus register to write (and read while polling)
  • Param3: = 0 - mask (optional. Default value “-1” - see below for explanations)
  • Param4:= 255 - Maximum Value for scaling MQTT input value = 100 to register value (Optional. Default MaxValue 0x3f. It is equivalent of “100« on input. If value == 0 - no scaling)

Mask: if mask == 1 - Value comes to most significant byte of 16 bit register word, another byte = 0xff if mask == 0 - Value comes to least significant byte of 16 bit register word, another byte = 0xff any other mask - put Value as 16 bit word without any modification if mask == -1 (or parameter omitted) - no register polling

Note: Serial line parameters for itemtype 4 is 9600:8N1 (look for “dimPar» and “MODBUS_SERIAL_BAUD” definitions in config.h if you need to change it)

конфигурирование.txt · Последнее изменение: 2022/06/28 21:38 — prizzrak14