mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 03:39:49 +03:00
Removed envs can be used with setting up build flags.
This commit is contained in:
@@ -1,4 +0,0 @@
|
|||||||
To avoid interrupt corflicts between DmxDue an USART1 need to copy patched file over DUE sys lib
|
|
||||||
|
|
||||||
Patch example for OSX:
|
|
||||||
/Users/andrey/Library/Arduino15/packages/arduino/hardware/sam/1.6.11/variants/arduino_due_x/variant.cpp
|
|
||||||
@@ -1,455 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2011 Arduino. All right reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Lesser General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2.1 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
See the GNU Lesser General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
|
||||||
License along with this library; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "variant.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* DUE Board pin | PORT | Label
|
|
||||||
* ----------------+--------+-------
|
|
||||||
* 0 | PA8 | "RX0"
|
|
||||||
* 1 | PA9 | "TX0"
|
|
||||||
* 2 TIOA0 | PB25 |
|
|
||||||
* 3 TIOA7 | PC28 |
|
|
||||||
* 4 NPCS1 | PA29 |
|
|
||||||
* TIOB6 | PC26 |
|
|
||||||
* 5 TIOA6 | PC25 |
|
|
||||||
* 6 PWML7 | PC24 |
|
|
||||||
* 7 PWML6 | PC23 |
|
|
||||||
* 8 PWML5 | PC22 |
|
|
||||||
* 9 PWML4 | PC21 |
|
|
||||||
* 10 NPCS0 | PA28 |
|
|
||||||
* TIOB7 | PC29 |
|
|
||||||
* 11 TIOA8 | PD7 |
|
|
||||||
* 12 TIOB8 | PD8 |
|
|
||||||
* 13 TIOB0 | PB27 | LED AMBER "L"
|
|
||||||
* 14 TXD3 | PD4 | "TX3"
|
|
||||||
* 15 RXD3 | PD5 | "RX3"
|
|
||||||
* 16 TXD1 | PA13 | "TX2"
|
|
||||||
* 17 RXD1 | PA12 | "RX2"
|
|
||||||
* 18 TXD0 | PA11 | "TX1"
|
|
||||||
* 19 RXD0 | PA10 | "RX1"
|
|
||||||
* 20 | PB12 | "SDA"
|
|
||||||
* 21 | PB13 | "SCL"
|
|
||||||
* 22 | PB26 |
|
|
||||||
* 23 | PA14 |
|
|
||||||
* 24 | PA15 |
|
|
||||||
* 25 | PD0 |
|
|
||||||
* 26 | PD1 |
|
|
||||||
* 27 | PD2 |
|
|
||||||
* 28 | PD3 |
|
|
||||||
* 29 | PD6 |
|
|
||||||
* 30 | PD9 |
|
|
||||||
* 31 | PA7 |
|
|
||||||
* 32 | PD10 |
|
|
||||||
* 33 | PC1 |
|
|
||||||
* 34 | PC2 |
|
|
||||||
* 35 | PC3 |
|
|
||||||
* 36 | PC4 |
|
|
||||||
* 37 | PC5 |
|
|
||||||
* 38 | PC6 |
|
|
||||||
* 39 | PC7 |
|
|
||||||
* 40 | PC8 |
|
|
||||||
* 41 | PC9 |
|
|
||||||
* 42 | PA19 |
|
|
||||||
* 43 | PA20 |
|
|
||||||
* 44 | PC19 |
|
|
||||||
* 45 | PC18 |
|
|
||||||
* 46 | PC17 |
|
|
||||||
* 47 | PC16 |
|
|
||||||
* 48 | PC15 |
|
|
||||||
* 49 | PC14 |
|
|
||||||
* 50 | PC13 |
|
|
||||||
* 51 | PC12 |
|
|
||||||
* 52 NPCS2 | PB21 |
|
|
||||||
* 53 | PB14 |
|
|
||||||
* 54 | PA16 | "A0"
|
|
||||||
* 55 | PA24 | "A1"
|
|
||||||
* 56 | PA23 | "A2"
|
|
||||||
* 57 | PA22 | "A3"
|
|
||||||
* 58 TIOB2 | PA6 | "A4"
|
|
||||||
* 69 | PA4 | "A5"
|
|
||||||
* 60 TIOB1 | PA3 | "A6"
|
|
||||||
* 61 TIOA1 | PA2 | "A7"
|
|
||||||
* 62 | PB17 | "A8"
|
|
||||||
* 63 | PB18 | "A9"
|
|
||||||
* 64 | PB19 | "A10"
|
|
||||||
* 65 | PB20 | "A11"
|
|
||||||
* 66 | PB15 | "DAC0"
|
|
||||||
* 67 | PB16 | "DAC1"
|
|
||||||
* 68 | PA1 | "CANRX"
|
|
||||||
* 69 | PA0 | "CANTX"
|
|
||||||
* 70 | PA17 | "SDA1"
|
|
||||||
* 71 | PA18 | "SCL1"
|
|
||||||
* 72 | PC30 | LED AMBER "RX"
|
|
||||||
* 73 | PA21 | LED AMBER "TX"
|
|
||||||
* 74 MISO | PA25 |
|
|
||||||
* 75 MOSI | PA26 |
|
|
||||||
* 76 SCLK | PA27 |
|
|
||||||
* 77 NPCS0 | PA28 |
|
|
||||||
* 78 NPCS3 | PB23 | unconnected!
|
|
||||||
*
|
|
||||||
* USB pin | PORT
|
|
||||||
* ----------------+--------
|
|
||||||
* ID | PB11
|
|
||||||
* VBOF | PB10
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Pins descriptions
|
|
||||||
*/
|
|
||||||
extern const PinDescription g_APinDescription[]=
|
|
||||||
{
|
|
||||||
// 0 .. 53 - Digital pins
|
|
||||||
// ----------------------
|
|
||||||
// 0/1 - UART (Serial)
|
|
||||||
{ PIOA, PIO_PA8A_URXD, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // URXD
|
|
||||||
{ PIOA, PIO_PA9A_UTXD, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // UTXD
|
|
||||||
|
|
||||||
// 2
|
|
||||||
{ PIOB, PIO_PB25B_TIOA0, ID_PIOB, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM, TC0_CHA0 }, // TIOA0
|
|
||||||
{ PIOC, PIO_PC28B_TIOA7, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM, TC2_CHA7 }, // TIOA7
|
|
||||||
{ PIOC, PIO_PC26B_TIOB6, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM, TC2_CHB6 }, // TIOB6
|
|
||||||
|
|
||||||
// 5
|
|
||||||
{ PIOC, PIO_PC25B_TIOA6, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM, TC2_CHA6 }, // TIOA6
|
|
||||||
{ PIOC, PIO_PC24B_PWML7, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), NO_ADC, NO_ADC, PWM_CH7, NOT_ON_TIMER }, // PWML7
|
|
||||||
{ PIOC, PIO_PC23B_PWML6, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), NO_ADC, NO_ADC, PWM_CH6, NOT_ON_TIMER }, // PWML6
|
|
||||||
{ PIOC, PIO_PC22B_PWML5, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), NO_ADC, NO_ADC, PWM_CH5, NOT_ON_TIMER }, // PWML5
|
|
||||||
{ PIOC, PIO_PC21B_PWML4, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), NO_ADC, NO_ADC, PWM_CH4, NOT_ON_TIMER }, // PWML4
|
|
||||||
// 10
|
|
||||||
{ PIOC, PIO_PC29B_TIOB7, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM, TC2_CHB7 }, // TIOB7
|
|
||||||
{ PIOD, PIO_PD7B_TIOA8, ID_PIOD, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM, TC2_CHA8 }, // TIOA8
|
|
||||||
{ PIOD, PIO_PD8B_TIOB8, ID_PIOD, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM, TC2_CHB8 }, // TIOB8
|
|
||||||
|
|
||||||
// 13 - AMBER LED
|
|
||||||
{ PIOB, PIO_PB27B_TIOB0, ID_PIOB, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM, TC0_CHB0 }, // TIOB0
|
|
||||||
|
|
||||||
// 14/15 - USART3 (Serial3)
|
|
||||||
{ PIOD, PIO_PD4B_TXD3, ID_PIOD, PIO_PERIPH_B, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // TXD3
|
|
||||||
{ PIOD, PIO_PD5B_RXD3, ID_PIOD, PIO_PERIPH_B, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // RXD3
|
|
||||||
|
|
||||||
// 16/17 - USART1 (Serial2)
|
|
||||||
{ PIOA, PIO_PA13A_TXD1, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // TXD1
|
|
||||||
{ PIOA, PIO_PA12A_RXD1, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // RXD1
|
|
||||||
|
|
||||||
// 18/19 - USART0 (Serial1)
|
|
||||||
{ PIOA, PIO_PA11A_TXD0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // TXD0
|
|
||||||
{ PIOA, PIO_PA10A_RXD0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // RXD0
|
|
||||||
|
|
||||||
// 20/21 - TWI1
|
|
||||||
{ PIOB, PIO_PB12A_TWD1, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // TWD1 - SDA0
|
|
||||||
{ PIOB, PIO_PB13A_TWCK1, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // TWCK1 - SCL0
|
|
||||||
|
|
||||||
// 22
|
|
||||||
{ PIOB, PIO_PB26, ID_PIOB, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 22
|
|
||||||
{ PIOA, PIO_PA14, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 23
|
|
||||||
{ PIOA, PIO_PA15, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 24
|
|
||||||
{ PIOD, PIO_PD0, ID_PIOD, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 25
|
|
||||||
|
|
||||||
// 26
|
|
||||||
{ PIOD, PIO_PD1, ID_PIOD, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 26
|
|
||||||
{ PIOD, PIO_PD2, ID_PIOD, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 27
|
|
||||||
{ PIOD, PIO_PD3, ID_PIOD, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 28
|
|
||||||
{ PIOD, PIO_PD6, ID_PIOD, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 29
|
|
||||||
|
|
||||||
// 30
|
|
||||||
{ PIOD, PIO_PD9, ID_PIOD, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 30
|
|
||||||
{ PIOA, PIO_PA7, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 31
|
|
||||||
{ PIOD, PIO_PD10, ID_PIOD, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 32
|
|
||||||
{ PIOC, PIO_PC1, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 33
|
|
||||||
|
|
||||||
// 34
|
|
||||||
{ PIOC, PIO_PC2, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 34
|
|
||||||
{ PIOC, PIO_PC3, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 35
|
|
||||||
{ PIOC, PIO_PC4, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 36
|
|
||||||
{ PIOC, PIO_PC5, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 37
|
|
||||||
|
|
||||||
// 38
|
|
||||||
{ PIOC, PIO_PC6, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 38
|
|
||||||
{ PIOC, PIO_PC7, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 39
|
|
||||||
{ PIOC, PIO_PC8, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 40
|
|
||||||
{ PIOC, PIO_PC9, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 41
|
|
||||||
|
|
||||||
// 42
|
|
||||||
{ PIOA, PIO_PA19, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 42
|
|
||||||
{ PIOA, PIO_PA20, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 43
|
|
||||||
{ PIOC, PIO_PC19, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 44
|
|
||||||
{ PIOC, PIO_PC18, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 45
|
|
||||||
|
|
||||||
// 46
|
|
||||||
{ PIOC, PIO_PC17, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 46
|
|
||||||
{ PIOC, PIO_PC16, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 47
|
|
||||||
{ PIOC, PIO_PC15, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 48
|
|
||||||
{ PIOC, PIO_PC14, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 49
|
|
||||||
|
|
||||||
// 50
|
|
||||||
{ PIOC, PIO_PC13, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 50
|
|
||||||
{ PIOC, PIO_PC12, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 51
|
|
||||||
{ PIOB, PIO_PB21, ID_PIOB, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 52
|
|
||||||
{ PIOB, PIO_PB14, ID_PIOB, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 53
|
|
||||||
|
|
||||||
|
|
||||||
// 54 .. 65 - Analog pins
|
|
||||||
// ----------------------
|
|
||||||
{ PIOA, PIO_PA16X1_AD7, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC0, ADC7, NOT_ON_PWM, NOT_ON_TIMER }, // AD0
|
|
||||||
{ PIOA, PIO_PA24X1_AD6, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC1, ADC6, NOT_ON_PWM, NOT_ON_TIMER }, // AD1
|
|
||||||
{ PIOA, PIO_PA23X1_AD5, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC2, ADC5, NOT_ON_PWM, NOT_ON_TIMER }, // AD2
|
|
||||||
{ PIOA, PIO_PA22X1_AD4, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC3, ADC4, NOT_ON_PWM, NOT_ON_TIMER }, // AD3
|
|
||||||
// 58
|
|
||||||
{ PIOA, PIO_PA6X1_AD3, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC4, ADC3, NOT_ON_PWM, TC0_CHB2 }, // AD4
|
|
||||||
{ PIOA, PIO_PA4X1_AD2, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC5, ADC2, NOT_ON_PWM, NOT_ON_TIMER }, // AD5
|
|
||||||
{ PIOA, PIO_PA3X1_AD1, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC6, ADC1, NOT_ON_PWM, TC0_CHB1 }, // AD6
|
|
||||||
{ PIOA, PIO_PA2X1_AD0, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC7, ADC0, NOT_ON_PWM, TC0_CHA1 }, // AD7
|
|
||||||
// 62
|
|
||||||
{ PIOB, PIO_PB17X1_AD10, ID_PIOB, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC8, ADC10, NOT_ON_PWM, NOT_ON_TIMER }, // AD8
|
|
||||||
{ PIOB, PIO_PB18X1_AD11, ID_PIOB, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC9, ADC11, NOT_ON_PWM, NOT_ON_TIMER }, // AD9
|
|
||||||
{ PIOB, PIO_PB19X1_AD12, ID_PIOB, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC10, ADC12, NOT_ON_PWM, NOT_ON_TIMER }, // AD10
|
|
||||||
{ PIOB, PIO_PB20X1_AD13, ID_PIOB, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC11, ADC13, NOT_ON_PWM, NOT_ON_TIMER }, // AD11
|
|
||||||
|
|
||||||
// 66/67 - DAC0/DAC1
|
|
||||||
{ PIOB, PIO_PB15X1_DAC0, ID_PIOB, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC12, DA0, NOT_ON_PWM, NOT_ON_TIMER }, // DAC0
|
|
||||||
{ PIOB, PIO_PB16X1_DAC1, ID_PIOB, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC13, DA1, NOT_ON_PWM, NOT_ON_TIMER }, // DAC1
|
|
||||||
|
|
||||||
// 68/69 - CANRX0/CANTX0
|
|
||||||
{ PIOA, PIO_PA1A_CANRX0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, ADC14, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // CANRX
|
|
||||||
{ PIOA, PIO_PA0A_CANTX0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, ADC15, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // CANTX
|
|
||||||
|
|
||||||
// 70/71 - TWI0
|
|
||||||
{ PIOA, PIO_PA17A_TWD0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // TWD0 - SDA1
|
|
||||||
{ PIOA, PIO_PA18A_TWCK0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // TWCK0 - SCL1
|
|
||||||
|
|
||||||
// 72/73 - LEDs
|
|
||||||
{ PIOC, PIO_PC30, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // LED AMBER RXL
|
|
||||||
{ PIOA, PIO_PA21, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // LED AMBER TXL
|
|
||||||
|
|
||||||
// 74/75/76 - SPI
|
|
||||||
{ PIOA, PIO_PA25A_SPI0_MISO,ID_PIOA,PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // MISO
|
|
||||||
{ PIOA, PIO_PA26A_SPI0_MOSI,ID_PIOA,PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // MOSI
|
|
||||||
{ PIOA, PIO_PA27A_SPI0_SPCK,ID_PIOA,PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // SPCK
|
|
||||||
|
|
||||||
// 77 - SPI CS0
|
|
||||||
{ PIOA, PIO_PA28A_SPI0_NPCS0,ID_PIOA,PIO_PERIPH_A,PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // NPCS0
|
|
||||||
|
|
||||||
// 78 - SPI CS3 (unconnected)
|
|
||||||
{ PIOB, PIO_PB23B_SPI0_NPCS3,ID_PIOB,PIO_PERIPH_B,PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // NPCS3
|
|
||||||
|
|
||||||
// 79 .. 84 - "All pins" masks
|
|
||||||
|
|
||||||
// 79 - TWI0 all pins
|
|
||||||
{ PIOA, PIO_PA17A_TWD0|PIO_PA18A_TWCK0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER },
|
|
||||||
// 80 - TWI1 all pins
|
|
||||||
{ PIOB, PIO_PB12A_TWD1|PIO_PB13A_TWCK1, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER },
|
|
||||||
// 81 - UART (Serial) all pins
|
|
||||||
{ PIOA, PIO_PA8A_URXD|PIO_PA9A_UTXD, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER },
|
|
||||||
// 82 - USART0 (Serial1) all pins
|
|
||||||
{ PIOA, PIO_PA11A_TXD0|PIO_PA10A_RXD0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER },
|
|
||||||
// 83 - USART1 (Serial2) all pins
|
|
||||||
{ PIOA, PIO_PA13A_TXD1|PIO_PA12A_RXD1, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER },
|
|
||||||
// 84 - USART3 (Serial3) all pins
|
|
||||||
{ PIOD, PIO_PD4B_TXD3|PIO_PD5B_RXD3, ID_PIOD, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER },
|
|
||||||
|
|
||||||
// 85 - USB
|
|
||||||
{ PIOB, PIO_PB11A_UOTGID|PIO_PB10A_UOTGVBOF, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL,NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // ID - VBOF
|
|
||||||
|
|
||||||
// 86 - SPI CS2
|
|
||||||
{ PIOB, PIO_PB21B_SPI0_NPCS2, ID_PIOB, PIO_PERIPH_B, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // NPCS2
|
|
||||||
|
|
||||||
// 87 - SPI CS1
|
|
||||||
{ PIOA, PIO_PA29A_SPI0_NPCS1, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // NPCS1
|
|
||||||
|
|
||||||
// 88/89 - CANRX1/CANTX1 (same physical pin for 66/53)
|
|
||||||
{ PIOB, PIO_PB15A_CANRX1, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // CANRX1
|
|
||||||
{ PIOB, PIO_PB14A_CANTX1, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // CANTX1
|
|
||||||
|
|
||||||
// 90 .. 91 - "All CAN pins" masks
|
|
||||||
// 90 - CAN0 all pins
|
|
||||||
{ PIOA, PIO_PA1A_CANRX0|PIO_PA0A_CANTX0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER },
|
|
||||||
// 91 - CAN1 all pins
|
|
||||||
{ PIOB, PIO_PB15A_CANRX1|PIO_PB14A_CANTX1, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER },
|
|
||||||
|
|
||||||
// END
|
|
||||||
{ NULL, 0, 0, PIO_NOT_A_PIN, PIO_DEFAULT, 0, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }
|
|
||||||
} ;
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t g_pinStatus[PINS_COUNT] = {0};
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* UART objects
|
|
||||||
*/
|
|
||||||
RingBuffer rx_buffer1;
|
|
||||||
RingBuffer tx_buffer1;
|
|
||||||
|
|
||||||
UARTClass Serial(UART, UART_IRQn, ID_UART, &rx_buffer1, &tx_buffer1);
|
|
||||||
void serialEvent() __attribute__((weak));
|
|
||||||
void serialEvent() { }
|
|
||||||
|
|
||||||
// IT handlers
|
|
||||||
void UART_Handler(void)
|
|
||||||
{
|
|
||||||
Serial.IrqHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
* USART objects
|
|
||||||
*/
|
|
||||||
RingBuffer rx_buffer2;
|
|
||||||
RingBuffer rx_buffer3;
|
|
||||||
RingBuffer rx_buffer4;
|
|
||||||
RingBuffer tx_buffer2;
|
|
||||||
RingBuffer tx_buffer3;
|
|
||||||
RingBuffer tx_buffer4;
|
|
||||||
|
|
||||||
///USARTClass Serial1(USART0, USART0_IRQn, ID_USART0, &rx_buffer2, &tx_buffer2);
|
|
||||||
void serialEvent1() __attribute__((weak));
|
|
||||||
void serialEvent1() { }
|
|
||||||
USARTClass Serial2(USART1, USART1_IRQn, ID_USART1, &rx_buffer3, &tx_buffer3);
|
|
||||||
void serialEvent2() __attribute__((weak));
|
|
||||||
void serialEvent2() { }
|
|
||||||
USARTClass Serial3(USART3, USART3_IRQn, ID_USART3, &rx_buffer4, &tx_buffer4);
|
|
||||||
void serialEvent3() __attribute__((weak));
|
|
||||||
void serialEvent3() { }
|
|
||||||
|
|
||||||
// IT handlers
|
|
||||||
|
|
||||||
///void USART0_Handler(void)
|
|
||||||
///{
|
|
||||||
/// Serial1.IrqHandler();
|
|
||||||
///}
|
|
||||||
|
|
||||||
void USART1_Handler(void)
|
|
||||||
{
|
|
||||||
Serial2.IrqHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
void USART3_Handler(void)
|
|
||||||
{
|
|
||||||
Serial3.IrqHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void serialEventRun(void)
|
|
||||||
{
|
|
||||||
if (Serial.available()) serialEvent();
|
|
||||||
/// if (Serial1.available()) serialEvent1();
|
|
||||||
if (Serial2.available()) serialEvent2();
|
|
||||||
if (Serial3.available()) serialEvent3();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void __libc_init_array(void);
|
|
||||||
|
|
||||||
void init( void )
|
|
||||||
{
|
|
||||||
SystemInit();
|
|
||||||
|
|
||||||
// Set Systick to 1ms interval, common to all SAM3 variants
|
|
||||||
if (SysTick_Config(SystemCoreClock / 1000))
|
|
||||||
{
|
|
||||||
// Capture error
|
|
||||||
while (true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize C library
|
|
||||||
__libc_init_array();
|
|
||||||
|
|
||||||
// Disable pull-up on every pin
|
|
||||||
for (unsigned i = 0; i < PINS_COUNT; i++)
|
|
||||||
digitalWrite(i, LOW);
|
|
||||||
|
|
||||||
// Enable parallel access on PIO output data registers
|
|
||||||
PIOA->PIO_OWER = 0xFFFFFFFF;
|
|
||||||
PIOB->PIO_OWER = 0xFFFFFFFF;
|
|
||||||
PIOC->PIO_OWER = 0xFFFFFFFF;
|
|
||||||
PIOD->PIO_OWER = 0xFFFFFFFF;
|
|
||||||
|
|
||||||
// Initialize Serial port U(S)ART pins
|
|
||||||
PIO_Configure(
|
|
||||||
g_APinDescription[PINS_UART].pPort,
|
|
||||||
g_APinDescription[PINS_UART].ulPinType,
|
|
||||||
g_APinDescription[PINS_UART].ulPin,
|
|
||||||
g_APinDescription[PINS_UART].ulPinConfiguration);
|
|
||||||
digitalWrite(0, HIGH); // Enable pullup for RX0
|
|
||||||
PIO_Configure(
|
|
||||||
g_APinDescription[PINS_USART0].pPort,
|
|
||||||
g_APinDescription[PINS_USART0].ulPinType,
|
|
||||||
g_APinDescription[PINS_USART0].ulPin,
|
|
||||||
g_APinDescription[PINS_USART0].ulPinConfiguration);
|
|
||||||
PIO_Configure(
|
|
||||||
g_APinDescription[PINS_USART1].pPort,
|
|
||||||
g_APinDescription[PINS_USART1].ulPinType,
|
|
||||||
g_APinDescription[PINS_USART1].ulPin,
|
|
||||||
g_APinDescription[PINS_USART1].ulPinConfiguration);
|
|
||||||
PIO_Configure(
|
|
||||||
g_APinDescription[PINS_USART3].pPort,
|
|
||||||
g_APinDescription[PINS_USART3].ulPinType,
|
|
||||||
g_APinDescription[PINS_USART3].ulPin,
|
|
||||||
g_APinDescription[PINS_USART3].ulPinConfiguration);
|
|
||||||
|
|
||||||
// Initialize USB pins
|
|
||||||
PIO_Configure(
|
|
||||||
g_APinDescription[PINS_USB].pPort,
|
|
||||||
g_APinDescription[PINS_USB].ulPinType,
|
|
||||||
g_APinDescription[PINS_USB].ulPin,
|
|
||||||
g_APinDescription[PINS_USB].ulPinConfiguration);
|
|
||||||
|
|
||||||
// Initialize CAN pins
|
|
||||||
PIO_Configure(
|
|
||||||
g_APinDescription[PINS_CAN0].pPort,
|
|
||||||
g_APinDescription[PINS_CAN0].ulPinType,
|
|
||||||
g_APinDescription[PINS_CAN0].ulPin,
|
|
||||||
g_APinDescription[PINS_CAN0].ulPinConfiguration);
|
|
||||||
PIO_Configure(
|
|
||||||
g_APinDescription[PINS_CAN1].pPort,
|
|
||||||
g_APinDescription[PINS_CAN1].ulPinType,
|
|
||||||
g_APinDescription[PINS_CAN1].ulPin,
|
|
||||||
g_APinDescription[PINS_CAN1].ulPinConfiguration);
|
|
||||||
|
|
||||||
// Initialize Analog Controller
|
|
||||||
pmc_enable_periph_clk(ID_ADC);
|
|
||||||
adc_init(ADC, SystemCoreClock, ADC_FREQ_MAX, ADC_STARTUP_FAST);
|
|
||||||
adc_configure_timing(ADC, 0, ADC_SETTLING_TIME_3, 1);
|
|
||||||
adc_configure_trigger(ADC, ADC_TRIG_SW, 0); // Disable hardware trigger.
|
|
||||||
adc_disable_interrupt(ADC, 0xFFFFFFFF); // Disable all ADC interrupts.
|
|
||||||
adc_disable_all_channel(ADC);
|
|
||||||
|
|
||||||
// Initialize analogOutput module
|
|
||||||
analogOutputInit();
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
74
README.md
74
README.md
@@ -1,34 +1,48 @@
|
|||||||
# LightHub
|
# LightHub
|
||||||
is Flexible, Arduino-Mega/Arduino DUE/ESP8266 based SmartHome controller. [RU](https://geektimes.ru/post/295109/)
|
is Flexible, Arduino-Mega/Arduino DUE/ESP8266 open-software and open-hardware SmartHome controller. [RU](https://geektimes.ru/post/295109/) [HOME-site RU](http://lazyhome.ru)
|
||||||
|
It may operate both:
|
||||||
It allows connecting together:
|
* On [especially designed hardware board](http://www.lazyhome.ru/index.php/featurerequest) with 16 optocoupled digital inputs, 16 ESD protected digital/analog Inputs/outputs, 8 open-collector outputs (up to 0.5A/50V), DMX IN/OUT, MODBUS RTU and hardware 1-wire support circuit.
|
||||||
|
* On plain Arduino MEGA 2560, Arduino DUE, ESP8266 and even on [Controllino](http://controllino.biz/)
|
||||||
|
(Controllino and ESP8266 is not tested enough and in experimental stage yet)
|
||||||
|
|
||||||
|
Lighthub 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)
|
||||||
* Standard nonexpensive Relay board with TTL inputs, (like this) to control AC powered lamps, floor heaters, boilers etc
|
* Standard nonexpensive Relay board with TTL inputs, [like this](https://aliexpress.com/item/16-Channel-20A-Relay-Control-Module-for-Arduino-UNO-MEGA2560-R3-Raspberry-Pi/32747887693.html) to control AC powered lamps, floor heaters, boilers etc
|
||||||
* Standard LED and AC DMX-512 dimmer boards
|
* [Standard nonexpensive LED dimmers](https://aliexpress.com/item/30-channel-27channel-Easy-DMX-LED-controller-dmx-decoder-driver-rgb-led-controller/2015743918.html) and [AC DMX-512 dimmers](https://aliexpress.com/item/DMX302-led-DMX-triac-dimmer-brightness-controller-AC90V-240V-Output-3channels-1A-CH-High-voltage-led/32822841266.html)
|
||||||
* Modbus RTU devices (Currently, are deployed two types of Modbus devices: AC Dimmer and Ventilation set (Based on Vacon 10 controller)
|
* Modbus RTU devices (Currently, are deployed two types of Modbus devices: AC Dimmer and Ventilation set (Based on [Vacon 10 controller](http://files.danfoss.com/download/Drives/Vacon-10-Quick-Guide-DPD00714F1-UK.pdf))
|
||||||
* Simple DMX wall sensor panel
|
* Simple DMX wall sensor panel [like this](https://aliexpress.com/item/New-Ltech-D8-LED-rgb-RGBW-touch-panel-controller-DMX512-controller-DC12-24V-4-zones-4/32800199589.html)
|
||||||
|
|
||||||
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.
|
Where is possible both, to configure local control/mapping between inputs and outputs (light, floor heating thermostats) and remote control from MQTT enabled software. At the moment, LightHub tested with following set of complementary free software:
|
||||||
|
* [Openhab or Openhab2 Smarthome software](http://www.openhab.org/)
|
||||||
|
Openhab provides own native mobile app both, for IoS and Android, and even allow you to use Apple's HomeKit to say "Siri, turn on light in bedroom" but requires some server to be installed (Raspberry PI with [Openhabian](https://docs.openhab.org/installation/openhabian) will good enough)
|
||||||
|
* [HomeRemote mobile client](http://thehomeremote.com/)
|
||||||
|
Home Remote mobile applicatios for IoS and Android requires just MQTT broker to be working. Any Cloud-based MQTT broker, like [CloudMQTT](https://www.cloudmqtt.com/) will enough to serve average household, even with free account.
|
||||||
|
* [Node-Red](https://nodered.org/) Possibly, the best solution to deploy event-based authomation and scripting on top of MQTT/LightHub. The easy to use universal and visual tool to wire many different devices in single system. Having own Dashbord which allow control from web/mobile web, even without mobile apps (but excelent co-working with OpenHab and HomeRemote)
|
||||||
|
|
||||||
[Prease refer to our Wiki for insructions.](https://github.com/anklimov/lighthub/wiki/Configuring)
|
Scalability of Lighthub 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/NodeRed/HomeRemote and propagate commands across network.
|
||||||
|
|
||||||
|
# [Please refer to our Wiki for insructions.](https://github.com/anklimov/lighthub/wiki/Configuring)
|
||||||
|
* [Compiling and flashing](https://github.com/anklimov/lighthub/wiki/Compiling-and-flashing)
|
||||||
|
* [Configuring](https://github.com/anklimov/lighthub/wiki/Configuring)
|
||||||
|
* [Channel commands](https://github.com/anklimov/lighthub/wiki/Channel-commands)
|
||||||
|
* [OpenHab integration](https://github.com/anklimov/lighthub/wiki/OpenHab--integration)
|
||||||
|
|
||||||
Finished portation of project 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/](https://github.com/anklimov/lighthub/tree/master/compiled) folder. Flash your Mega 2560
|
Compiled image has been added to [compiled/](https://github.com/anklimov/lighthub/tree/master/compiled) folder. Flash your Mega 2560
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
avrdude -v -V -patmega2560 -cwiring -b115200 -D -Uflash:w:lighthub.ino.hex:i
|
avrdude -v -V -patmega2560 -cwiring -b115200 -D -Uflash:w:firmware.hex:i
|
||||||
```
|
```
|
||||||
|
|
||||||
or flash your DUE (need to correct path and port, of course)
|
or flash your DUE (need to correct path and port, of course)
|
||||||
```bash
|
```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 firmware.bin -R
|
||||||
```
|
```
|
||||||
|
Note: binary images usually not up-to-date with recent code. The preferred way, to compile and upload firmware to your controller.
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
(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)
|
||||||
@@ -45,40 +59,41 @@ For patched libraries, appropriate GitHub repo URL provided:
|
|||||||
* 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
|
||||||
* CmdArduino https://github.com/anklimov/CmdArduino
|
* CmdArduino https://github.com/anklimov/CmdArduino
|
||||||
* EEPROM (standard for AVR) or DueFlashStorage for DUE
|
* EEPROM (standard for AVR) or DueFlashStorage for DUE: https://github.com/sebnil/DueFlashStorage
|
||||||
* ModbusMaster https://github.com/anklimov/ModbusMaster
|
* ModbusMaster https://github.com/anklimov/ModbusMaster
|
||||||
* pubsubclient-2.6
|
* pubsubclient-2.6
|
||||||
* DMXSerial-master (for AVR) https://github.com/anklimov/DMXSerial
|
* DMXSerial-master (for AVR) https://github.com/anklimov/DMXSerial
|
||||||
* Ethernet https://github.com/anklimov/Ethernet
|
* Ethernet https://github.com/anklimov/Ethernet
|
||||||
* SPI (standard)
|
* SPI (standard)
|
||||||
|
|
||||||
Portation from AVR Mega 2560 to SAM3X8E (Arduino DUE) done since v 0.96
|
Portation from AVR Mega 2560 to SAM3X8E (Arduino DUE) done since v 0.96 and tested against Wiznet 5100 Ethernet shield and Wiznet 5500 Ethernet module
|
||||||
|
|
||||||
# Platforms specific details:
|
# Platforms specific details:
|
||||||
|
|
||||||
AVR version is basic and has all functions
|
AVR version is basic, long tome in production and have all functions
|
||||||
*DMX-out is software (DMXSimple) on pin3
|
*DMX-out is software (DMXSimple) on pin3
|
||||||
|
|
||||||
**SAM3X8E**:
|
**SAM3X8E**: (Tested. Recomended hardware at current moment)
|
||||||
* 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
|
||||||
|
|
||||||
**ESP8266**:
|
**ESP8266**: (Developed but not tested in production)
|
||||||
* 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:
|
||||||
|
Mega and DUE:
|
||||||
|
Need to use compiler directive -D Wiz5500 and https://github.com/anklimov/Ethernet2 library to compile with Wiznet 5500 instead 5100
|
||||||
|
|
||||||
There is first attempt to use Wiznet 5500 (still not stable enough)
|
Prefered way to compile project is using platformio toolchain, suitable for Arduino Due, and Arduino Mega2560
|
||||||
Need to use compiler directive -D Wiz5500 and https://github.com/anklimov/Ethernet2 library
|
|
||||||
|
|
||||||
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 add USART0_Handler method definition like this
|
||||||
|
void USART0_Handler(void) __attribute__((weak));
|
||||||
|
|
||||||
void USART0_Handler(void) __attribute__((weak));
|
The normal path to find this file in platformio is:
|
||||||
|
.platformio/packages/framework-arduinosam/variants/arduino_due_x
|
||||||
|
|
||||||
# Platformio command line build instructions
|
# Platformio command line build instructions
|
||||||
[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/)
|
[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/)
|
||||||
@@ -128,6 +143,8 @@ platformio device monitor -b 115200
|
|||||||
* DMX_DISABLE //disable DMX support
|
* DMX_DISABLE //disable DMX support
|
||||||
* MODBUS_DISABLE // disable Modbus support
|
* MODBUS_DISABLE // disable Modbus support
|
||||||
* OWIRE_DISABLE // disable OneWire support
|
* OWIRE_DISABLE // disable OneWire support
|
||||||
|
* ARTNET_ENABLE //Enable Artnet protocol support
|
||||||
|
* CONTROLLINO //Change Modbus port, direction pins and Wiznet SS pins to be working on [Controllino](http://controllino.biz/)
|
||||||
|
|
||||||
|
|
||||||
# Default compilation behavior:
|
# Default compilation behavior:
|
||||||
@@ -142,4 +159,9 @@ platformio device monitor -b 115200
|
|||||||
* DMX support enabled
|
* DMX support enabled
|
||||||
* Modbus support enabled
|
* Modbus support enabled
|
||||||
* OneWire support enabled
|
* OneWire support enabled
|
||||||
|
* Artnet disabled
|
||||||
|
* Defailt MQTT input topic: /myhome/in
|
||||||
|
* Default MQTT topic to publish device status: /myhome/s_out
|
||||||
|
* Default Alarm output topic /alarm
|
||||||
|
|
||||||
|
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
|
||||||
|
|||||||
@@ -17,5 +17,7 @@
|
|||||||
export FLAGS="$FLAGS -DDMX_DISABLE"
|
export FLAGS="$FLAGS -DDMX_DISABLE"
|
||||||
export FLAGS="$FLAGS -DMODBUS_DISABLE"
|
export FLAGS="$FLAGS -DMODBUS_DISABLE"
|
||||||
export FLAGS="$FLAGS -DOWIRE_DISABLE"
|
export FLAGS="$FLAGS -DOWIRE_DISABLE"
|
||||||
|
export FLAGS="$FLAGS -DARTNET_ENABLE"
|
||||||
|
export FLAGS="$FLAGS -DCONTROLLINO"
|
||||||
export PLATFORMIO_BUILD_FLAGS="$FLAGS"
|
export PLATFORMIO_BUILD_FLAGS="$FLAGS"
|
||||||
unset FLAGS
|
unset FLAGS
|
||||||
BIN
compiled/DUE/Wiz5100/firmware.bin
Executable file
BIN
compiled/DUE/Wiz5100/firmware.bin
Executable file
Binary file not shown.
BIN
compiled/DUE/Wiz5500/firmware.bin
Executable file
BIN
compiled/DUE/Wiz5500/firmware.bin
Executable file
Binary file not shown.
Binary file not shown.
3617
compiled/Mega2560/Wiz5100/firmware.hex
Normal file
3617
compiled/Mega2560/Wiz5100/firmware.hex
Normal file
File diff suppressed because it is too large
Load Diff
3593
compiled/Mega2560/Wiz5500/firmware.hex
Normal file
3593
compiled/Mega2560/Wiz5500/firmware.hex
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
29
config/c4-3e-11-03-1b-1e.config.json
Normal file
29
config/c4-3e-11-03-1b-1e.config.json
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"mqtt":["garden","192.168.10.115",1883,"test","test"],
|
||||||
|
"ow":{
|
||||||
|
"28FFADCE601705A3":{"emit":"t_soil1","item":"h_relay6"},
|
||||||
|
"286164123FF96F55":{"emit":"t_soil2"},
|
||||||
|
"28FFEF6D60170335":{"emit":"t_soil3"}
|
||||||
|
},
|
||||||
|
"items":{
|
||||||
|
"h_relay1":[6,39,1,1],
|
||||||
|
"h_relay2":[6,38,1,1],
|
||||||
|
"h_relay3":[6,37,1,1],
|
||||||
|
"h_relay4":[6,36,1,1],
|
||||||
|
"h_relay5":[6,35,1,1],
|
||||||
|
"h_relay6":[5,34,23],
|
||||||
|
"h_relay7":[6,33,1,1],
|
||||||
|
"h_relay8":[6,32,1,1],
|
||||||
|
"h_auto":[6,29,1,1]
|
||||||
|
},
|
||||||
|
"in":{
|
||||||
|
"40":{"emit":"/garden/s_in/1"},
|
||||||
|
"41":{"emit":"/garden/s_in/2"},
|
||||||
|
"42":{"emit":"/garden/s_in/3"},
|
||||||
|
"43":{"emit":"/garden/s_in/4"},
|
||||||
|
"44":{"emit":"/garden/s_in/5"},
|
||||||
|
"45":{"emit":"/garden/s_in/6"},
|
||||||
|
"46":{"emit":"/garden/s_in/7"},
|
||||||
|
"47":{"emit":"/garden/s_in/8"}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
"fm_h":[8,"fm"]
|
"fm_h":[8,"fm"]
|
||||||
|
|
||||||
},
|
},
|
||||||
"mqtt":["public_test2","m21.cloudmqtt.com",12299,"bkyyvlha","RpHF-x6v4YWb"]
|
"mqtt":["public_test2","m2m.eclipse.org"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"mqtt":["public_test1","m21.cloudmqtt.com",12299,"bkyyvlha","RpHF-x6v4YWb"],
|
"mqtt":["public_test1","m2m.eclipse.org"],
|
||||||
"ow":{
|
"ow":{
|
||||||
"2807FFD503000036":{"emit":"t_balk1","item":"h_balk1"},
|
"2807FFD503000036":{"emit":"t_balk1","item":"h_balk1"},
|
||||||
"284811170400005B":{"emit":"t_entr"},
|
"284811170400005B":{"emit":"t_entr"},
|
||||||
|
|||||||
BIN
docs/LightHubAppDiagram.png
Normal file
BIN
docs/LightHubAppDiagram.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 178 KiB |
BIN
hardware/LightHub.pdf
Normal file
BIN
hardware/LightHub.pdf
Normal file
Binary file not shown.
101
lighthub/dmx.cpp
101
lighthub/dmx.cpp
@@ -49,18 +49,19 @@ extern aJsonObject *dmxArr;
|
|||||||
|
|
||||||
int itemCtrl2(char* name,int r,int g, int b, int w)
|
int itemCtrl2(char* name,int r,int g, int b, int w)
|
||||||
{
|
{
|
||||||
aJsonObject *itemArr= aJson.getObjectItem(items, name);
|
if (!items) return 0;
|
||||||
|
aJsonObject *itemArr= aJson.getObjectItem(items, name);
|
||||||
|
|
||||||
if (itemArr && (itemArr->type==aJson_Array))
|
if (itemArr && (itemArr->type==aJson_Array))
|
||||||
{
|
{
|
||||||
|
|
||||||
short itemtype = aJson.getArrayItem(itemArr,0)->valueint;
|
|
||||||
short itemaddr = aJson.getArrayItem(itemArr,1)->valueint;
|
|
||||||
switch (itemtype){
|
|
||||||
#ifdef _dmxout
|
|
||||||
case 0: //Dimmed light
|
|
||||||
|
|
||||||
DmxWrite(itemaddr, w);
|
short itemtype = aJson.getArrayItem(itemArr,0)->valueint;
|
||||||
|
short itemaddr = aJson.getArrayItem(itemArr,1)->valueint;
|
||||||
|
switch (itemtype){
|
||||||
|
#ifdef _dmxout
|
||||||
|
case 0: //Dimmed light
|
||||||
|
|
||||||
|
DmxWrite(itemaddr, w);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
@@ -69,15 +70,15 @@ int itemCtrl2(char* name,int r,int g, int b, int w)
|
|||||||
|
|
||||||
case 2: // RGB
|
case 2: // RGB
|
||||||
{
|
{
|
||||||
|
|
||||||
DmxWrite(itemaddr, r);
|
DmxWrite(itemaddr, r);
|
||||||
DmxWrite(itemaddr+1, g);
|
DmxWrite(itemaddr+1, g);
|
||||||
DmxWrite(itemaddr+2, b);
|
DmxWrite(itemaddr+2, b);
|
||||||
|
|
||||||
break; }
|
break; }
|
||||||
#endif
|
#endif
|
||||||
case 7: //Group
|
case 7: //Group
|
||||||
aJsonObject *groupArr= aJson.getArrayItem(itemArr, 1);
|
aJsonObject *groupArr= aJson.getArrayItem(itemArr, 1);
|
||||||
if (groupArr && (groupArr->type==aJson_Array))
|
if (groupArr && (groupArr->type==aJson_Array))
|
||||||
{ aJsonObject *i =groupArr->child;
|
{ aJsonObject *i =groupArr->child;
|
||||||
while (i)
|
while (i)
|
||||||
@@ -87,57 +88,62 @@ int itemCtrl2(char* name,int r,int g, int b, int w)
|
|||||||
}
|
}
|
||||||
} //itemtype
|
} //itemtype
|
||||||
// break;
|
// break;
|
||||||
} //if have correct array
|
} //if have correct array
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DMXImmediateUpdate(short tch,short r, short g, short b, short w) {
|
void DMXImmediateUpdate(short tch,short r, short g, short b, short w) {
|
||||||
//Here only safe re-interable code for quick passthrow between DMX IN and DMX OUT
|
//Here only safe re-interable code for quick passthrow between DMX IN and DMX OUT
|
||||||
if (dmxArr && (dmxArr->type==aJson_Array))
|
if (dmxArr && (dmxArr->type==aJson_Array))
|
||||||
|
|
||||||
{
|
{
|
||||||
char* itemname = aJson.getArrayItem(dmxArr,tch)->valuestring;
|
char* itemname = aJson.getArrayItem(dmxArr,tch)->valuestring;
|
||||||
itemCtrl2(itemname,r,g,b,w);
|
if (itemname) itemCtrl2(itemname,r,g,b,w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DMXSemiImmediateUpdate(short tch,short trh, int val)
|
void DMXSemiImmediateUpdate(short tch,short trh, int val)
|
||||||
{
|
{
|
||||||
//Here any code for passthrow between DMX IN and DMX OUT in idle state
|
//Here any code for passthrow between DMX IN and DMX OUT in idle state
|
||||||
}
|
}
|
||||||
|
|
||||||
void DMXput(void)
|
void DMXput(void)
|
||||||
{
|
{
|
||||||
int t;
|
int t;
|
||||||
for (short tch=0; tch<=3 ; tch++)
|
for (short tch=0; tch<=3 ; tch++)
|
||||||
{
|
{
|
||||||
short base = tch*4;
|
short base = tch*4;
|
||||||
DMXImmediateUpdate(tch,DMXin[base],DMXin[base+1],DMXin[base+2],DMXin[base+3]);
|
DMXImmediateUpdate(tch,DMXin[base],DMXin[base+1],DMXin[base+2],DMXin[base+3]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void DMXUpdate(void)
|
void DMXUpdate(void)
|
||||||
{
|
{
|
||||||
#if defined(_dmxin)
|
#if defined(_dmxin)
|
||||||
int t;
|
int t;
|
||||||
for (short tch=0; tch<=3 ; tch++)
|
if(!DMXin) return;
|
||||||
|
#if defined(__SAM3X8E__)
|
||||||
|
if (dmxin.getRxLength()<16) return;
|
||||||
|
#endif
|
||||||
|
for (short tch=0; tch<=3 ; tch++)
|
||||||
{
|
{
|
||||||
short base = tch*4;
|
short base = tch*4;
|
||||||
bool updated = 0;
|
bool updated = 0;
|
||||||
|
|
||||||
for (short trh=0; trh<4 ; trh++)
|
for (short trh=0; trh<4 ; trh++)
|
||||||
if ((t=dmxin.read(base+trh+1)) != DMXin[base+trh])
|
if ((t=dmxin.read(base+trh+1)) != DMXin[base+trh])
|
||||||
{
|
{
|
||||||
D_State |= (1<<tch);
|
D_State |= (1<<tch);
|
||||||
updated=1;
|
updated=1;
|
||||||
//Serial.print("Changed :"); Serial.print(DMXin[tch*4+trh]); Serial.print(" => "); Serial.print(t);Serial.println();
|
//Serial.print("Changed :"); Serial.print(DMXin[tch*4+trh]); Serial.print(" => "); Serial.print(t);Serial.println();
|
||||||
DMXin[base+trh]=t;
|
DMXin[base+trh]=t;
|
||||||
//DMXImmediateUpdate(tch,trh,t);
|
//DMXImmediateUpdate(tch,trh,t);
|
||||||
//break;
|
//break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updated)
|
if (updated)
|
||||||
{
|
{
|
||||||
DMXImmediateUpdate(tch,DMXin[base],DMXin[base+1],DMXin[base+2],DMXin[base+3]);
|
DMXImmediateUpdate(tch,DMXin[base],DMXin[base+1],DMXin[base+2],DMXin[base+3]);
|
||||||
D_checkT=millis()+D_CHECKT;
|
D_checkT=millis()+D_CHECKT;
|
||||||
@@ -153,19 +159,19 @@ for (short tch=0; tch<=3 ; tch++)
|
|||||||
// CHSV hsv;
|
// CHSV hsv;
|
||||||
// CRGB rgb;
|
// CRGB rgb;
|
||||||
#if defined(_dmxin)
|
#if defined(_dmxin)
|
||||||
|
|
||||||
short t,tch;
|
short t,tch;
|
||||||
//Here code for semi-immediate update
|
//Here code for semi-immediate update
|
||||||
for (t=1,tch=0; t<=8 ; t<<=1,tch++)
|
for (t=1,tch=0; t<=8 ; t<<=1,tch++)
|
||||||
if (D_State & t)
|
if (D_State & t)
|
||||||
{
|
{
|
||||||
// Serial.print(D_State,BIN);Serial.print(":");
|
// Serial.print(D_State,BIN);Serial.print(":");
|
||||||
D_State &= ~t;
|
D_State &= ~t;
|
||||||
for (short trh=0; trh<4 ; trh++)
|
for (short trh=0; trh<4 ; trh++)
|
||||||
DMXSemiImmediateUpdate(tch,trh,DMXin[tch*4+trh]);
|
DMXSemiImmediateUpdate(tch,trh,DMXin[tch*4+trh]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((millis()<D_checkT) || (D_checkT==0)) return;
|
if ((millis()<D_checkT) || (D_checkT==0)) return;
|
||||||
D_checkT=0;
|
D_checkT=0;
|
||||||
|
|
||||||
@@ -185,9 +191,9 @@ void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* d
|
|||||||
#ifdef _dmxout
|
#ifdef _dmxout
|
||||||
for (int i = 0 ; i < length && i<MAX_CHANNELS ; i++)
|
for (int i = 0 ; i < length && i<MAX_CHANNELS ; i++)
|
||||||
{
|
{
|
||||||
DmxWrite(i+1,data[i]);
|
DmxWrite(i+1,data[i]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void DMXinSetup(int channels)
|
void DMXinSetup(int channels)
|
||||||
@@ -196,10 +202,10 @@ void DMXinSetup(int channels)
|
|||||||
// //Use digital pin 3 for DMX output. Must be a PWM channel.
|
// //Use digital pin 3 for DMX output. Must be a PWM channel.
|
||||||
// DmxSimple.usePin(pin);
|
// DmxSimple.usePin(pin);
|
||||||
//DmxSimple.maxChannel(channels);
|
//DmxSimple.maxChannel(channels);
|
||||||
|
|
||||||
#if defined(_dmxin)
|
#if defined(_dmxin)
|
||||||
DMXin = new uint8_t [channels];
|
DMXin = new uint8_t [channels];
|
||||||
#if defined(__AVR__)
|
#if defined(__AVR__)
|
||||||
DMXSerial.init(DMXReceiver,0,channels);
|
DMXSerial.init(DMXReceiver,0,channels);
|
||||||
if (DMXSerial.getBuffer()) {Serial.print(F("Init in ch:"));Serial.println(channels);} else Serial.println(F("DMXin Buffer alloc err"));
|
if (DMXSerial.getBuffer()) {Serial.print(F("Init in ch:"));Serial.println(channels);} else Serial.println(F("DMXin Buffer alloc err"));
|
||||||
//DMXSerial.maxChannel(channels);
|
//DMXSerial.maxChannel(channels);
|
||||||
@@ -207,22 +213,21 @@ void DMXinSetup(int channels)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__)
|
||||||
|
dmxin.setRxEvent(DMXUpdate);
|
||||||
dmxin.begin();
|
dmxin.begin();
|
||||||
dmxin.setRxEvent(DMXUpdate);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _artnet
|
#ifdef _artnet
|
||||||
// this will be called for each packet received
|
// this will be called for each packet received
|
||||||
if (artnet) artnet->setArtDmxCallback(onDmxFrame);
|
if (artnet) artnet->setArtDmxCallback(onDmxFrame);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void DMXoutSetup(int channels,int pin)
|
void DMXoutSetup(int channels,int pin)
|
||||||
{
|
{
|
||||||
#ifdef _dmxout
|
#ifdef _dmxout
|
||||||
#if defined(__AVR__)
|
#if defined(__AVR__)
|
||||||
DmxSimple.usePin(pin);
|
DmxSimple.usePin(pin);
|
||||||
DmxSimple.maxChannel(channels);
|
DmxSimple.maxChannel(channels);
|
||||||
@@ -231,7 +236,7 @@ void DMXoutSetup(int channels,int pin)
|
|||||||
|
|
||||||
#if defined(__ESP__)
|
#if defined(__ESP__)
|
||||||
dmxout.init(channels);
|
dmxout.init(channels);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__)
|
||||||
dmxout.begin();
|
dmxout.begin();
|
||||||
|
|||||||
@@ -32,8 +32,6 @@ e-mail anklimov@gmail.com
|
|||||||
#include <ModbusMaster.h>
|
#include <ModbusMaster.h>
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
|
|
||||||
#define dimPar SERIAL_8E1
|
|
||||||
#define fmPar SERIAL_8N1
|
|
||||||
|
|
||||||
short modbusBusy = 0;
|
short modbusBusy = 0;
|
||||||
extern aJsonObject *pollingItem;
|
extern aJsonObject *pollingItem;
|
||||||
@@ -121,20 +119,22 @@ void Item::setCmd(uint8_t cmd) {
|
|||||||
int Item::getArg(short n) //Return arg int or first array element if Arg is array
|
int Item::getArg(short n) //Return arg int or first array element if Arg is array
|
||||||
{
|
{
|
||||||
if (!itemArg) return -1;
|
if (!itemArg) return -1;
|
||||||
if (itemArg->type == aJson_Int) return itemArg->valueint;
|
if (itemArg->type == aJson_Int){
|
||||||
else if (itemArg->type == aJson_Array) return aJson.getArrayItem(itemArg, n)->valueint;
|
if (!n) return itemArg->valueint; else return -1;
|
||||||
|
}
|
||||||
|
if ((itemArg->type == aJson_Array) && ( n < aJson.getArraySize(itemArg))) return aJson.getArrayItem(itemArg, n)->valueint;
|
||||||
else return -2;
|
else return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
int Item::getVal(short n) //Return Val from Value array
|
int Item::getVal(short n) //Return Val from Value array
|
||||||
{ if (!itemVal) return -1;
|
{ if (!itemVal) return -1;
|
||||||
else if (itemVal->type==aJson_Array)
|
else if (itemVal->type==aJson_Array)
|
||||||
{
|
{
|
||||||
aJsonObject *t = aJson.getArrayItem(itemVal,n);
|
aJsonObject *t = aJson.getArrayItem(itemVal,n);
|
||||||
if (t) return t->valueint;
|
if (t) return t->valueint;
|
||||||
else return -3;
|
else return -3;
|
||||||
}
|
}
|
||||||
else return -2;
|
else return -2;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
@@ -156,9 +156,9 @@ void Item::setVal(short n, int par) // Only store if VAL is array defined in c
|
|||||||
if (!itemVal || itemVal->type!=aJson_Array) return;
|
if (!itemVal || itemVal->type!=aJson_Array) return;
|
||||||
Serial.print(F(" Store p="));Serial.print(n);Serial.print(F(" Val="));Serial.println(par);
|
Serial.print(F(" Store p="));Serial.print(n);Serial.print(F(" Val="));Serial.println(par);
|
||||||
for (int i=aJson.getArraySize(itemVal);i<=n;i++) aJson.addItemToArray(itemVal,aJson.createItem(int(0))); //Enlarge array of Values
|
for (int i=aJson.getArraySize(itemVal);i<=n;i++) aJson.addItemToArray(itemVal,aJson.createItem(int(0))); //Enlarge array of Values
|
||||||
|
|
||||||
aJsonObject *t = aJson.getArrayItem(itemVal,n);
|
aJsonObject *t = aJson.getArrayItem(itemVal,n);
|
||||||
if (t) t->valueint=par;
|
if (t) t->valueint=par;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -182,7 +182,7 @@ boolean Item::isValid() {
|
|||||||
void Item::copyPar (aJsonObject *itemV)
|
void Item::copyPar (aJsonObject *itemV)
|
||||||
{ int n=aJson.getArraySize(itemV);
|
{ int n=aJson.getArraySize(itemV);
|
||||||
//for (int i=aJson.getArraySize(itemVal);i<n;i++) aJson.addItemToArray(itemVal,aJson.createItem(int(0))); //Enlarge array of Values
|
//for (int i=aJson.getArraySize(itemVal);i<n;i++) aJson.addItemToArray(itemVal,aJson.createItem(int(0))); //Enlarge array of Values
|
||||||
for (int i=0;i<n;i++) setPar(i,aJson.getArrayItem(itemV,i)->valueint);
|
for (int i=0;i<n;i++) setPar(i,aJson.getArrayItem(itemV,i)->valueint);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -201,11 +201,11 @@ boolean Item::getEnableCMD(int delta) {
|
|||||||
#define MAXCTRLPAR 3
|
#define MAXCTRLPAR 3
|
||||||
int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
|
int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
|
||||||
|
|
||||||
|
|
||||||
Serial.print(F("Cmd="));Serial.print(cmd);Serial.print(F(" MEM="));Serial.println(freeRam());
|
Serial.print(F("Cmd="));Serial.print(cmd);Serial.print(F(" MEM="));Serial.println(freeRam());
|
||||||
|
|
||||||
int Par[MAXCTRLPAR] = {0, 0, 0};
|
int Par[MAXCTRLPAR] = {0, 0, 0};
|
||||||
if (Parameters)
|
if (Parameters)
|
||||||
for (short i=0;i<n && i<MAXCTRLPAR;i++) Par[i] = Parameters[i];
|
for (short i=0;i<n && i<MAXCTRLPAR;i++) Par[i] = Parameters[i];
|
||||||
|
|
||||||
int iaddr = getArg();
|
int iaddr = getArg();
|
||||||
@@ -254,7 +254,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
|
|||||||
case CH_MODBUS:
|
case CH_MODBUS:
|
||||||
case CH_VCTEMP:
|
case CH_VCTEMP:
|
||||||
if (send) SendStatus(0, 1, Par,true); // Send back parameter for channel above this line
|
if (send) SendStatus(0, 1, Par,true); // Send back parameter for channel above this line
|
||||||
case CH_THERMO:
|
case CH_THERMO:
|
||||||
setVal(Par[0]); // Store value
|
setVal(Par[0]); // Store value
|
||||||
|
|
||||||
}//itemtype
|
}//itemtype
|
||||||
@@ -265,7 +265,23 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_ON:
|
case CMD_ON:
|
||||||
if (itemType!=CH_RGBW || getCmd() != CMD_ON) {
|
if (itemType==CH_RGBW && getCmd() == CMD_ON && getEnableCMD(500)) {
|
||||||
|
Serial.println(F("Force White"));
|
||||||
|
itemType = CH_WHITE;
|
||||||
|
Par[1] = 0; //Zero saturation
|
||||||
|
Par[2] = 100; //Full power
|
||||||
|
// Store
|
||||||
|
st.h = Par[0];
|
||||||
|
st.s = Par[1];
|
||||||
|
st.v = Par[2];
|
||||||
|
setVal(st.aslong);
|
||||||
|
//Send to OH
|
||||||
|
if (send) SendStatus(0, 3, Par);
|
||||||
|
break;
|
||||||
|
} // if forcewhite
|
||||||
|
|
||||||
|
// if (itemType!=CH_RGBW || getCmd() != CMD_ON) {
|
||||||
|
{
|
||||||
short params = 0;
|
short params = 0;
|
||||||
setCmd(cmd);
|
setCmd(cmd);
|
||||||
//retrive stored values
|
//retrive stored values
|
||||||
@@ -290,7 +306,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
|
|||||||
case CH_DIMMER: //Everywhere, in flat VAL
|
case CH_DIMMER: //Everywhere, in flat VAL
|
||||||
case CH_MODBUS:
|
case CH_MODBUS:
|
||||||
case CH_VC:
|
case CH_VC:
|
||||||
|
|
||||||
|
|
||||||
Par[0] = st.aslong;
|
Par[0] = st.aslong;
|
||||||
params = 1;
|
params = 1;
|
||||||
@@ -303,8 +319,8 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (send) SendStatus(cmd); // Just send ON
|
if (send) SendStatus(cmd); // Just send ON
|
||||||
}//itemtype
|
}//itemtype switch
|
||||||
else {// Default settings
|
else {// Default settings, values not stored yet
|
||||||
Serial.print(st.aslong);
|
Serial.print(st.aslong);
|
||||||
Serial.println(F(": No stored values - default"));
|
Serial.println(F(": No stored values - default"));
|
||||||
|
|
||||||
@@ -314,7 +330,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
|
|||||||
Par[0] = 20; //20 degrees celsium - safe temperature
|
Par[0] = 20; //20 degrees celsium - safe temperature
|
||||||
params = 1;
|
params = 1;
|
||||||
SendStatus(0, params, Par);
|
SendStatus(0, params, Par);
|
||||||
break;
|
break;
|
||||||
case CH_RGBW:
|
case CH_RGBW:
|
||||||
case CH_RGB:
|
case CH_RGB:
|
||||||
Par[0] = 100;
|
Par[0] = 100;
|
||||||
@@ -323,18 +339,24 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
|
|||||||
params = 3;
|
params = 3;
|
||||||
SendStatus(0, params, Par,true);
|
SendStatus(0, params, Par,true);
|
||||||
break;
|
break;
|
||||||
default:
|
case CH_RELAY:
|
||||||
|
Par[0] = 100;
|
||||||
|
params = 1;
|
||||||
|
if (send) SendStatus(CMD_ON);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
Par[0] = 100;
|
Par[0] = 100;
|
||||||
params = 1;
|
params = 1;
|
||||||
SendStatus(0, params, Par);
|
SendStatus(0, params, Par);
|
||||||
}
|
}
|
||||||
}
|
} // default handler
|
||||||
for (short i = 0; i < params; i++) {
|
for (short i = 0; i < params; i++) {
|
||||||
Serial.print(F("Restored: "));
|
Serial.print(F("Restored: "));
|
||||||
Serial.print(i);
|
Serial.print(i);
|
||||||
Serial.print(F("="));
|
Serial.print(F("="));
|
||||||
Serial.println(Par[i]);
|
Serial.println(Par[i]);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
} else { //Double ON - apply special preset - clean white full power
|
} else { //Double ON - apply special preset - clean white full power
|
||||||
if (getEnableCMD(500)) switch (itemType) {
|
if (getEnableCMD(500)) switch (itemType) {
|
||||||
case CH_RGBW:
|
case CH_RGBW:
|
||||||
@@ -354,10 +376,10 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
|
|||||||
break;
|
break;
|
||||||
} //itemtype
|
} //itemtype
|
||||||
} //else
|
} //else
|
||||||
|
*/
|
||||||
//Serial.print("Sa:");Serial.println(Par[1]);
|
//Serial.print("Sa:");Serial.println(Par[1]);
|
||||||
if ((itemType == CH_RGBW) && (Par[1] == 0)) itemType = CH_WHITE;
|
if ((itemType == CH_RGBW) && (Par[1] == 0)) itemType = CH_WHITE;
|
||||||
|
}
|
||||||
|
|
||||||
break; //CMD_ON
|
break; //CMD_ON
|
||||||
|
|
||||||
@@ -368,7 +390,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
|
|||||||
Par[1] = 0;
|
Par[1] = 0;
|
||||||
Par[2] = 0;
|
Par[2] = 0;
|
||||||
setCmd(cmd);
|
setCmd(cmd);
|
||||||
if (send) SendStatus(cmd);
|
if (send) SendStatus(cmd);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -434,13 +456,16 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
|
|||||||
|
|
||||||
#ifdef _modbus
|
#ifdef _modbus
|
||||||
case CH_MODBUS: {
|
case CH_MODBUS: {
|
||||||
|
short numpar=0;
|
||||||
if ((itemArg->type == aJson_Array) && (aJson.getArraySize(itemArg) == 3)) {
|
if ((itemArg->type == aJson_Array) && ((numpar = aJson.getArraySize(itemArg)) >= 2)) {
|
||||||
int _addr = aJson.getArrayItem(itemArg, 0)->valueint;
|
int _addr = aJson.getArrayItem(itemArg, 0)->valueint;
|
||||||
int _reg = aJson.getArrayItem(itemArg, 1)->valueint;
|
int _reg = aJson.getArrayItem(itemArg, 1)->valueint;
|
||||||
int _mask = aJson.getArrayItem(itemArg, 2)->valueint;
|
int _mask = -1;
|
||||||
|
if (numpar >= 3) _mask = aJson.getArrayItem(itemArg, 2)->valueint;
|
||||||
modbusDimmerSet(_addr, _reg, _mask, map(Par[0], 0, 100, 0, 0x3f));
|
int _maxval = 0x3f;
|
||||||
|
if (numpar >=4) _maxval = aJson.getArrayItem(itemArg, 3)->valueint;
|
||||||
|
if (_maxval) modbusDimmerSet(_addr, _reg, _mask, map(Par[0], 0, 100, 0, _maxval));
|
||||||
|
else modbusDimmerSet(_addr, _reg, _mask, Par[0]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -453,7 +478,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
|
|||||||
aJsonObject *i = itemArg->child;
|
aJsonObject *i = itemArg->child;
|
||||||
while (i) {
|
while (i) {
|
||||||
Item it(i->valuestring);
|
Item it(i->valuestring);
|
||||||
// it.copyPar(itemVal);
|
// it.copyPar(itemVal);
|
||||||
it.Ctrl(cmd, n, Par, send); //// was true
|
it.Ctrl(cmd, n, Par, send); //// was true
|
||||||
i = i->next;
|
i = i->next;
|
||||||
} //while
|
} //while
|
||||||
@@ -588,6 +613,7 @@ int Item::isActive() {
|
|||||||
case CH_THERMO:
|
case CH_THERMO:
|
||||||
case CH_VC:
|
case CH_VC:
|
||||||
case CH_VCTEMP:
|
case CH_VCTEMP:
|
||||||
|
case CH_PWM:
|
||||||
val = st.aslong;
|
val = st.aslong;
|
||||||
} //switch
|
} //switch
|
||||||
Serial.print(F(":="));
|
Serial.print(F(":="));
|
||||||
@@ -599,20 +625,20 @@ int Item::isActive() {
|
|||||||
|
|
||||||
short thermoSet(char * name, short cmd, short t)
|
short thermoSet(char * name, short cmd, short t)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (items)
|
if (items)
|
||||||
{
|
{
|
||||||
aJsonObject *item= aJson.getObjectItem(items, name);
|
aJsonObject *item= aJson.getObjectItem(items, name);
|
||||||
if (item && (item->type==aJson_Array) && (aJson.getArrayItem(item, I_TYPE)->valueint==CH_THERMO))
|
if (item && (item->type==aJson_Array) && (aJson.getArrayItem(item, I_TYPE)->valueint==CH_THERMO))
|
||||||
{
|
{
|
||||||
|
|
||||||
for (int i=aJson.getArraySize(item);i<4;i++) aJson.addItemToArray(item,aJson.createItem(int(0))); //Enlarge item to 4 elements
|
for (int i=aJson.getArraySize(item);i<4;i++) aJson.addItemToArray(item,aJson.createItem(int(0))); //Enlarge item to 4 elements
|
||||||
if (!cmd) aJson.getArrayItem(item, I_VAL)->valueint=t;
|
if (!cmd) aJson.getArrayItem(item, I_VAL)->valueint=t;
|
||||||
aJson.getArrayItem(item, I_CMD)->valueint=cmd;
|
aJson.getArrayItem(item, I_CMD)->valueint=cmd;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -622,8 +648,8 @@ if (PoolingInterval)
|
|||||||
{
|
{
|
||||||
Pool();
|
Pool();
|
||||||
next=millis()+PoolingInterval;
|
next=millis()+PoolingInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -634,31 +660,31 @@ addr 10d
|
|||||||
Снять аварию 42001 (2001=7d1) =>4
|
Снять аварию 42001 (2001=7d1) =>4
|
||||||
|
|
||||||
[22:20:33] Write task has completed successfully
|
[22:20:33] Write task has completed successfully
|
||||||
[22:20:33] <= Response: 0A 06 07 D0 00 04 89 FF
|
[22:20:33] <= Response: 0A 06 07 D0 00 04 89 FF
|
||||||
[22:20:32] => Poll: 0A 06 07 D0 00 04 89 FF
|
[22:20:32] => Poll: 0A 06 07 D0 00 04 89 FF
|
||||||
|
|
||||||
100%
|
100%
|
||||||
2003-> 10000
|
2003-> 10000
|
||||||
[22:24:05] Write task has completed successfully
|
[22:24:05] Write task has completed successfully
|
||||||
[22:24:05] <= Response: 0A 06 07 D2 27 10 33 C0
|
[22:24:05] <= Response: 0A 06 07 D2 27 10 33 C0
|
||||||
[22:24:05] => Poll: 0A 06 07 D2 27 10 33 C0
|
[22:24:05] => Poll: 0A 06 07 D2 27 10 33 C0
|
||||||
|
|
||||||
ON
|
ON
|
||||||
2001->1
|
2001->1
|
||||||
[22:24:50] Write task has completed successfully
|
[22:24:50] Write task has completed successfully
|
||||||
[22:24:50] <= Response: 0A 06 07 D0 00 01 49 FC
|
[22:24:50] <= Response: 0A 06 07 D0 00 01 49 FC
|
||||||
[22:24:50] => Poll: 0A 06 07 D0 00 01 49 FC
|
[22:24:50] => Poll: 0A 06 07 D0 00 01 49 FC
|
||||||
|
|
||||||
OFF
|
OFF
|
||||||
2001->0
|
2001->0
|
||||||
[22:25:35] Write task has completed successfully
|
[22:25:35] Write task has completed successfully
|
||||||
[22:25:35] <= Response: 0A 06 07 D0 00 00 88 3C
|
[22:25:35] <= Response: 0A 06 07 D0 00 00 88 3C
|
||||||
[22:25:34] => Poll: 0A 06 07 D0 00 00 88 3C
|
[22:25:34] => Poll: 0A 06 07 D0 00 00 88 3C
|
||||||
|
|
||||||
|
|
||||||
POLL 2101x10
|
POLL 2101x10
|
||||||
[22:27:29] <= Response: 0A 03 14 00 23 00 00 27 10 13 88 0B 9C 00 32 00 F8 00 F2 06 FA 01 3F AD D0
|
[22:27:29] <= Response: 0A 03 14 00 23 00 00 27 10 13 88 0B 9C 00 32 00 F8 00 F2 06 FA 01 3F AD D0
|
||||||
[22:27:29] => Poll: 0A 03 08 34 00 0A 87 18
|
[22:27:29] => Poll: 0A 03 08 34 00 0A 87 18
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -748,7 +774,7 @@ int Item::SendStatus(short cmd, short n, int *Par, boolean deffered) {
|
|||||||
if (deffered) {
|
if (deffered) {
|
||||||
setCmd(cmd | CMD_REPORT);
|
setCmd(cmd | CMD_REPORT);
|
||||||
Serial.println(F("Status deffered"));
|
Serial.println(F("Status deffered"));
|
||||||
// mqttClient.publish("/push", "1");
|
// mqttClient.publish("/push", "1");
|
||||||
return 0;
|
return 0;
|
||||||
// Todo: Parameters? Now expected that parameters already stored by setVal()
|
// Todo: Parameters? Now expected that parameters already stored by setVal()
|
||||||
}
|
}
|
||||||
@@ -758,7 +784,7 @@ int Item::SendStatus(short cmd, short n, int *Par, boolean deffered) {
|
|||||||
char valstr[16] = "";
|
char valstr[16] = "";
|
||||||
|
|
||||||
strcpy_P(addrstr, outprefix);
|
strcpy_P(addrstr, outprefix);
|
||||||
strncat(addrstr, itemArr->name, sizeof(addrstr));
|
strncat(addrstr, itemArr->name, sizeof(addrstr));
|
||||||
|
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
@@ -801,7 +827,7 @@ int Item::modbusDimmerSet(int addr, uint16_t _reg, int _mask, uint16_t value) {
|
|||||||
|
|
||||||
if (modbusBusy) {
|
if (modbusBusy) {
|
||||||
mb_fail(3, addr, value, 0);
|
mb_fail(3, addr, value, 0);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
};
|
};
|
||||||
modbusBusy = 1;
|
modbusBusy = 1;
|
||||||
@@ -810,10 +836,12 @@ int Item::modbusDimmerSet(int addr, uint16_t _reg, int _mask, uint16_t value) {
|
|||||||
node.begin(addr, modbusSerial);
|
node.begin(addr, modbusSerial);
|
||||||
|
|
||||||
|
|
||||||
if (_mask) {
|
switch (_mask) {
|
||||||
|
case 1:
|
||||||
value <<= 8;
|
value <<= 8;
|
||||||
value |= (0xff);
|
value |= (0xff);
|
||||||
} else {
|
break;
|
||||||
|
case 0:
|
||||||
value &= 0xff;
|
value &= 0xff;
|
||||||
value |= (0xff00);
|
value |= (0xff00);
|
||||||
}
|
}
|
||||||
@@ -875,13 +903,13 @@ int Item::checkFM() {
|
|||||||
// aJson.addNumberToObject(out,"U", (int) node.getResponseBuffer(8)/10.);
|
// aJson.addNumberToObject(out,"U", (int) node.getResponseBuffer(8)/10.);
|
||||||
// aJson.addNumberToObject(out,"Ui", (int) node.getResponseBuffer(9));
|
// aJson.addNumberToObject(out,"Ui", (int) node.getResponseBuffer(9));
|
||||||
aJson.addNumberToObject(out, "sw", (int) node.getResponseBuffer(0));
|
aJson.addNumberToObject(out, "sw", (int) node.getResponseBuffer(0));
|
||||||
|
|
||||||
if (RPM && itemArg->type == aJson_Array)
|
if (RPM && itemArg->type == aJson_Array)
|
||||||
{ aJsonObject *airGateObj = aJson.getArrayItem(itemArg, 1);
|
{ aJsonObject *airGateObj = aJson.getArrayItem(itemArg, 1);
|
||||||
if (airGateObj) {
|
if (airGateObj) {
|
||||||
int val = 100;
|
int val = 100;
|
||||||
Item item(airGateObj->valuestring);
|
Item item(airGateObj->valuestring);
|
||||||
if (item.isValid()) item.Ctrl(0,1,&val);
|
if (item.isValid()) item.Ctrl(0,1,&val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Serial.println();
|
Serial.println();
|
||||||
@@ -917,11 +945,11 @@ int Item::checkFM() {
|
|||||||
// aJson.addNumberToObject(out,"d", (int) node.getResponseBuffer(2)*a+b);
|
// aJson.addNumberToObject(out,"d", (int) node.getResponseBuffer(2)*a+b);
|
||||||
int pwr = node.getResponseBuffer(3);
|
int pwr = node.getResponseBuffer(3);
|
||||||
if (pwr > 0) aJson.addNumberToObject(out, "pwr", pwr / 10.); else aJson.addNumberToObject(out, "pwr", 0);
|
if (pwr > 0) aJson.addNumberToObject(out, "pwr", pwr / 10.); else aJson.addNumberToObject(out, "pwr", 0);
|
||||||
|
|
||||||
if (ftemp>fset+FM_OVERHEAT_CELSIUS && set)
|
if (ftemp>FM_OVERHEAT_CELSIUS && set)
|
||||||
{
|
{
|
||||||
mqttClient.publish("/alarm/ovrht", itemArr->name);
|
mqttClient.publish("/alarm/ovrht", itemArr->name);
|
||||||
Ctrl(CMD_OFF); //Shut down
|
Ctrl(CMD_OFF); //Shut down
|
||||||
}
|
}
|
||||||
Serial.println();
|
Serial.println();
|
||||||
} else {
|
} else {
|
||||||
@@ -941,12 +969,12 @@ int Item::checkFM() {
|
|||||||
boolean Item::checkModbusRetry() {
|
boolean Item::checkModbusRetry() {
|
||||||
int cmd = getCmd();
|
int cmd = getCmd();
|
||||||
if (cmd & CMD_RETRY) { // if last sending attempt of command was failed
|
if (cmd & CMD_RETRY) { // if last sending attempt of command was failed
|
||||||
int val = getVal();
|
int val = getVal();
|
||||||
Serial.println(F("Retrying CMD"));
|
Serial.println(F("Retrying CMD"));
|
||||||
cmd &= ~CMD_RETRY; // Clean retry flag
|
cmd &= ~CMD_RETRY; // Clean retry flag
|
||||||
Ctrl(cmd,1,&val); // Execute command again
|
Ctrl(cmd,1,&val); // Execute command again
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -999,10 +1027,17 @@ int Item::checkModbusDimmer() {
|
|||||||
|
|
||||||
int Item::checkModbusDimmer(int data) {
|
int Item::checkModbusDimmer(int data) {
|
||||||
short mask = getArg(2);
|
short mask = getArg(2);
|
||||||
|
if (mask < 0) return 0;
|
||||||
|
|
||||||
|
short maxVal = getArg(3);
|
||||||
|
if (maxVal<=0) maxVal = 0x3f;
|
||||||
|
|
||||||
int d = data;
|
int d = data;
|
||||||
if (mask) d >>= 8;
|
if (mask == 1) d >>= 8;
|
||||||
d &= 0xff;
|
if (mask == 0 || mask == 1) d &= 0xff;
|
||||||
d = map(d, 0, 0x3f, 0, 100);
|
|
||||||
|
if (maxVal) d = map(d, 0, maxVal, 0, 100);
|
||||||
|
|
||||||
int cmd = getCmd();
|
int cmd = getCmd();
|
||||||
//Serial.println(d);
|
//Serial.println(d);
|
||||||
if (getVal() != d || d && cmd == CMD_OFF || d && cmd == CMD_HALT) //volume changed or turned on manualy
|
if (getVal() != d || d && cmd == CMD_OFF || d && cmd == CMD_HALT) //volume changed or turned on manualy
|
||||||
@@ -1025,28 +1060,28 @@ int Item::Poll() {
|
|||||||
switch (itemType) {
|
switch (itemType) {
|
||||||
case CH_MODBUS:
|
case CH_MODBUS:
|
||||||
checkModbusDimmer();
|
checkModbusDimmer();
|
||||||
sendDelayedStatus();
|
sendDelayedStatus();
|
||||||
return INTERVAL_CHECK_MODBUS;
|
return INTERVAL_CHECK_MODBUS;
|
||||||
break;
|
break;
|
||||||
case CH_VC:
|
case CH_VC:
|
||||||
checkFM();
|
checkFM();
|
||||||
sendDelayedStatus();
|
sendDelayedStatus();
|
||||||
return INTERVAL_CHECK_MODBUS;
|
return INTERVAL_CHECK_MODBUS;
|
||||||
break;
|
break;
|
||||||
case CH_RGB: //All channels with slider generate too many updates
|
case CH_RGB: //All channels with slider generate too many updates
|
||||||
case CH_RGBW:
|
case CH_RGBW:
|
||||||
case CH_DIMMER:
|
case CH_DIMMER:
|
||||||
case CH_PWM:
|
case CH_PWM:
|
||||||
case CH_VCTEMP:
|
case CH_VCTEMP:
|
||||||
case CH_THERMO:
|
case CH_THERMO:
|
||||||
sendDelayedStatus();
|
sendDelayedStatus();
|
||||||
}
|
}
|
||||||
return INTERVAL_POLLING;
|
return INTERVAL_POLLING;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Item::sendDelayedStatus(){
|
void Item::sendDelayedStatus(){
|
||||||
HSVstore st;
|
HSVstore st;
|
||||||
int cmd=getCmd();
|
int cmd=getCmd();
|
||||||
short params = 0;
|
short params = 0;
|
||||||
int Par[3];
|
int Par[3];
|
||||||
if (cmd & CMD_REPORT)
|
if (cmd & CMD_REPORT)
|
||||||
@@ -1061,7 +1096,7 @@ void Item::sendDelayedStatus(){
|
|||||||
Par[1] = st.s;
|
Par[1] = st.s;
|
||||||
Par[2] = st.v;
|
Par[2] = st.v;
|
||||||
params = 3;
|
params = 3;
|
||||||
SendStatus(0, params, Par); // Send restored triplet.
|
SendStatus(0, params, Par); // Send restored triplet.
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CH_VCTEMP:
|
case CH_VCTEMP:
|
||||||
@@ -1070,17 +1105,16 @@ void Item::sendDelayedStatus(){
|
|||||||
case CH_MODBUS:
|
case CH_MODBUS:
|
||||||
case CH_VC:
|
case CH_VC:
|
||||||
case CH_THERMO:
|
case CH_THERMO:
|
||||||
|
|
||||||
|
|
||||||
Par[0] = st.aslong;
|
Par[0] = st.aslong;
|
||||||
params = 1;
|
params = 1;
|
||||||
SendStatus(0, params, Par); // Send restored parameter
|
SendStatus(0, params, Par); // Send restored parameter
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
SendStatus(cmd); // Just send CMD
|
SendStatus(cmd); // Just send CMD
|
||||||
}//itemtype
|
}//itemtype
|
||||||
cmd &= ~CMD_REPORT; // Clean report flag
|
cmd &= ~CMD_REPORT; // Clean report flag
|
||||||
setCmd(cmd);
|
setCmd(cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* Copyright © 2017-2018 Andrey Klimov. All rights reserved.
|
/* Copyright © 2017-2018 Andrey Klimov. All rights reserved.
|
||||||
*
|
*
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
@@ -45,9 +45,8 @@ Relay array channel
|
|||||||
Relay DMX array channel
|
Relay DMX array channel
|
||||||
Config URL & MQTT password commandline configuration
|
Config URL & MQTT password commandline configuration
|
||||||
1-wire Update refactoring (save memory)
|
1-wire Update refactoring (save memory)
|
||||||
Static IP
|
|
||||||
Topic configuration
|
Topic configuration
|
||||||
Timer
|
Timer
|
||||||
Modbus response check
|
Modbus response check
|
||||||
control/debug (Commandline) over MQTT
|
control/debug (Commandline) over MQTT
|
||||||
more Modbus dimmers
|
more Modbus dimmers
|
||||||
@@ -66,7 +65,7 @@ PWM Out
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
|
||||||
@@ -81,6 +80,8 @@ EthernetClient ethClient;
|
|||||||
|
|
||||||
const char outprefix[] PROGMEM = OUTTOPIC;
|
const char outprefix[] PROGMEM = OUTTOPIC;
|
||||||
const char inprefix[] PROGMEM = INTOPIC;
|
const char inprefix[] PROGMEM = INTOPIC;
|
||||||
|
const char configServerPrecompiled[] PROGMEM = CONFIG_SERVER;
|
||||||
|
|
||||||
|
|
||||||
aJsonObject *root = NULL;
|
aJsonObject *root = NULL;
|
||||||
aJsonObject *items = NULL;
|
aJsonObject *items = NULL;
|
||||||
@@ -99,6 +100,7 @@ unsigned long nextThermostatCheck = 0;
|
|||||||
aJsonObject *pollingItem = NULL;
|
aJsonObject *pollingItem = NULL;
|
||||||
|
|
||||||
bool owReady = false;
|
bool owReady = false;
|
||||||
|
bool configOk = false;
|
||||||
int lanStatus = 0;
|
int lanStatus = 0;
|
||||||
|
|
||||||
#ifdef _modbus
|
#ifdef _modbus
|
||||||
@@ -113,15 +115,17 @@ PubSubClient mqttClient(ethClient);
|
|||||||
|
|
||||||
void watchdogSetup(void) {} //Do not remove - strong re-definition WDT Init for DUE
|
void watchdogSetup(void) {} //Do not remove - strong re-definition WDT Init for DUE
|
||||||
|
|
||||||
|
|
||||||
// MQTT Callback routine
|
// MQTT Callback routine
|
||||||
#define MQTT_SUBJECT_LENGTH 20
|
|
||||||
#define MQTT_TOPIC_LENGTH 20
|
|
||||||
|
|
||||||
void mqttCallback(char *topic, byte *payload, unsigned int length) {
|
void mqttCallback(char *topic, byte *payload, unsigned int length) {
|
||||||
payload[length] = 0;
|
|
||||||
Serial.print(F("\n["));
|
Serial.print(F("\n["));
|
||||||
Serial.print(topic);
|
Serial.print(topic);
|
||||||
Serial.print(F("] "));
|
Serial.print(F("] "));
|
||||||
|
if (!payload) return;
|
||||||
|
payload[length] = 0;
|
||||||
|
|
||||||
int fr = freeRam();
|
int fr = freeRam();
|
||||||
if (fr < 250) {
|
if (fr < 250) {
|
||||||
@@ -134,7 +138,7 @@ void mqttCallback(char *topic, byte *payload, unsigned int length) {
|
|||||||
}
|
}
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
|
||||||
boolean retaining = (lanStatus == 4); //Todo - named constant
|
boolean retaining = (lanStatus == 4); //Todo - named constant
|
||||||
//Check if topic = Command topic
|
//Check if topic = Command topic
|
||||||
short intopic = 0;
|
short intopic = 0;
|
||||||
{
|
{
|
||||||
@@ -261,15 +265,35 @@ int lanLoop() {
|
|||||||
switch (lanStatus) {
|
switch (lanStatus) {
|
||||||
//Initial state
|
//Initial state
|
||||||
case 0: //Ethernet.begin(mac,ip);
|
case 0: //Ethernet.begin(mac,ip);
|
||||||
|
{
|
||||||
#ifdef __ESP__
|
#ifdef __ESP__
|
||||||
//WiFi.mode(WIFI_STA);
|
//WiFi.mode(WIFI_STA);
|
||||||
//wifiMulti.addAP("Smartbox", "");
|
//wifiMulti.addAP("Smartbox", "");
|
||||||
if((wifiMulti.run() == WL_CONNECTED)) lanStatus=1;
|
if((wifiMulti.run() == WL_CONNECTED)) lanStatus=1;
|
||||||
#else
|
#else
|
||||||
|
IPAddress ip;
|
||||||
|
IPAddress dns;
|
||||||
|
IPAddress gw;
|
||||||
|
IPAddress mask;
|
||||||
|
int res = 1;
|
||||||
Serial.println(F("Starting lan"));
|
Serial.println(F("Starting lan"));
|
||||||
wdt_dis();
|
if (loadIPAddressFromFlash(OFFSET_IP, ip))
|
||||||
if (Ethernet.begin(mac, 12000) == 0) {
|
if (loadIPAddressFromFlash(OFFSET_DNS, dns))
|
||||||
|
if (loadIPAddressFromFlash(OFFSET_GW, gw))
|
||||||
|
if (loadIPAddressFromFlash(OFFSET_MASK, mask)) Ethernet.begin(mac,ip,dns,gw,mask);
|
||||||
|
else Ethernet.begin(mac,ip,dns,gw);
|
||||||
|
else Ethernet.begin(mac,ip,dns);
|
||||||
|
else Ethernet.begin(mac,ip);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wdt_dis();
|
||||||
|
res = Ethernet.begin(mac, 12000);
|
||||||
|
wdt_en();
|
||||||
|
wdt_res();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (res == 0) {
|
||||||
Serial.println(F("Failed to configure Ethernet using DHCP"));
|
Serial.println(F("Failed to configure Ethernet using DHCP"));
|
||||||
lanStatus = -10;
|
lanStatus = -10;
|
||||||
lanCheck = millis() + 60000;
|
lanCheck = millis() + 60000;
|
||||||
@@ -277,14 +301,16 @@ if((wifiMulti.run() == WL_CONNECTED)) lanStatus=1;
|
|||||||
printIPAddress();
|
printIPAddress();
|
||||||
lanStatus = 1;
|
lanStatus = 1;
|
||||||
}
|
}
|
||||||
wdt_en();
|
|
||||||
wdt_res();
|
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
//Have IP address
|
//Have IP address
|
||||||
case 1:
|
case 1:
|
||||||
|
if (!configOk)
|
||||||
lanStatus = getConfig(0, NULL); //got config from server or load from NVRAM
|
lanStatus = getConfig(0, NULL); //got config from server or load from NVRAM
|
||||||
|
else lanStatus = 2;
|
||||||
#ifdef _artnet
|
#ifdef _artnet
|
||||||
if (artnet) artnet->begin();
|
if (artnet) artnet->begin();
|
||||||
#endif
|
#endif
|
||||||
@@ -297,17 +323,23 @@ if((wifiMulti.run() == WL_CONNECTED)) lanStatus=1;
|
|||||||
int port = 1883;
|
int port = 1883;
|
||||||
char empty = 0;
|
char empty = 0;
|
||||||
char *user = ∅
|
char *user = ∅
|
||||||
char *password = ∅
|
char passwordBuf[16]="";
|
||||||
|
char *password = passwordBuf;
|
||||||
|
|
||||||
|
|
||||||
if (!mqttClient.connected() && mqttArr && ((n = aJson.getArraySize(mqttArr)) > 1)) {
|
if (!mqttClient.connected() && mqttArr && ((n = aJson.getArraySize(mqttArr)) > 1)) {
|
||||||
char *client_id = aJson.getArrayItem(mqttArr, 0)->valuestring;
|
char *client_id = aJson.getArrayItem(mqttArr, 0)->valuestring;
|
||||||
char *servername = aJson.getArrayItem(mqttArr, 1)->valuestring;
|
char *servername = aJson.getArrayItem(mqttArr, 1)->valuestring;
|
||||||
if (n >= 3) port = aJson.getArrayItem(mqttArr, 2)->valueint;
|
if (n >= 3) port = aJson.getArrayItem(mqttArr, 2)->valueint;
|
||||||
|
|
||||||
if (n >= 4) user = aJson.getArrayItem(mqttArr, 3)->valuestring;
|
if (n >= 4) user = aJson.getArrayItem(mqttArr, 3)->valuestring;
|
||||||
if (n >= 5) password = aJson.getArrayItem(mqttArr, 4)->valuestring;
|
if (!loadStringFromFlash(OFFSET_MQTT_PWD, passwordBuf, sizeof(passwordBuf)) && (n >= 5))
|
||||||
|
{
|
||||||
|
password = aJson.getArrayItem(mqttArr, 4)->valuestring;
|
||||||
|
Serial.println(F("Using MQTT password from config"));
|
||||||
|
}
|
||||||
|
|
||||||
mqttClient.setServer(servername, port);
|
mqttClient.setServer(servername, port);
|
||||||
|
mqttClient.setCallback(mqttCallback);
|
||||||
|
|
||||||
Serial.print(F("Attempting MQTT connection to "));
|
Serial.print(F("Attempting MQTT connection to "));
|
||||||
Serial.print(servername);
|
Serial.print(servername);
|
||||||
@@ -317,11 +349,12 @@ if((wifiMulti.run() == WL_CONNECTED)) lanStatus=1;
|
|||||||
Serial.print(user);
|
Serial.print(user);
|
||||||
Serial.print(F(" ..."));
|
Serial.print(F(" ..."));
|
||||||
|
|
||||||
|
wdt_dis(); //potential unsafe for ethernetIdle(), but needed to avoid cyclic reboot if mosquitto out of order
|
||||||
if (mqttClient.connect(client_id, user, password)) {
|
if (mqttClient.connect(client_id, user, password)) {
|
||||||
Serial.print(F("connected as "));
|
Serial.print(F("connected as "));
|
||||||
Serial.println(client_id);
|
Serial.println(client_id);
|
||||||
|
wdt_en();
|
||||||
|
configOk=true;
|
||||||
// ... Temporary subscribe to status topic
|
// ... Temporary subscribe to status topic
|
||||||
char buf[MQTT_TOPIC_LENGTH];
|
char buf[MQTT_TOPIC_LENGTH];
|
||||||
|
|
||||||
@@ -344,13 +377,13 @@ if((wifiMulti.run() == WL_CONNECTED)) lanStatus=1;
|
|||||||
Serial.print(mqttClient.state());
|
Serial.print(mqttClient.state());
|
||||||
Serial.println(F(" try again in 5 seconds"));
|
Serial.println(F(" try again in 5 seconds"));
|
||||||
lanCheck = millis() + 5000;
|
lanCheck = millis() + 5000;
|
||||||
lanStatus = -12;
|
lanStatus = 12;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 4: //retaining ... Collecting
|
case 4: //retaining ... Collecting
|
||||||
if (millis() > lanCheck) {
|
if (millis() > lanCheck) {
|
||||||
char buf[MQTT_TOPIC_LENGTH];
|
char buf[MQTT_TOPIC_LENGTH];
|
||||||
|
|
||||||
@@ -374,7 +407,7 @@ if((wifiMulti.run() == WL_CONNECTED)) lanStatus=1;
|
|||||||
lanStatus = 0;
|
lanStatus = 0;
|
||||||
break;
|
break;
|
||||||
//Reconnect
|
//Reconnect
|
||||||
case -12:
|
case 12:
|
||||||
if (millis() > lanCheck)
|
if (millis() > lanCheck)
|
||||||
|
|
||||||
lanStatus = 2;
|
lanStatus = 2;
|
||||||
@@ -398,9 +431,15 @@ if((wifiMulti.run() == WL_CONNECTED)) lanStatus=1;
|
|||||||
wdt_dis();
|
wdt_dis();
|
||||||
if (lanStatus > 0)
|
if (lanStatus > 0)
|
||||||
switch (Ethernet.maintain()) {
|
switch (Ethernet.maintain()) {
|
||||||
|
case NO_LINK:
|
||||||
|
Serial.println(F("No link"));
|
||||||
|
if (mqttClient.connected()) mqttClient.disconnect();
|
||||||
|
lanStatus = -10;
|
||||||
|
break;
|
||||||
case DHCP_CHECK_RENEW_FAIL:
|
case DHCP_CHECK_RENEW_FAIL:
|
||||||
//renewed fail
|
//renewed fail
|
||||||
Serial.println(F("Error: renewed fail"));
|
Serial.println(F("Error: renewed fail"));
|
||||||
|
if (mqttClient.connected()) mqttClient.disconnect();
|
||||||
lanStatus = -10;
|
lanStatus = -10;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -411,6 +450,7 @@ if((wifiMulti.run() == WL_CONNECTED)) lanStatus=1;
|
|||||||
|
|
||||||
case DHCP_CHECK_REBIND_FAIL:
|
case DHCP_CHECK_REBIND_FAIL:
|
||||||
Serial.println(F("Error: rebind fail"));
|
Serial.println(F("Error: rebind fail"));
|
||||||
|
if (mqttClient.connected()) mqttClient.disconnect();
|
||||||
lanStatus = -10;
|
lanStatus = -10;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -501,7 +541,7 @@ void Changed(int i, DeviceAddress addr, int val) {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((val == -127) || (val == 85)) {
|
if ((val == -127) || (val == 85) || (val == 0)) { //ToDo: 1-w short circuit mapped to "0" celsium
|
||||||
// Serial.print("Temp err ");Serial.println(t);
|
// Serial.print("Temp err ");Serial.println(t);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -525,21 +565,24 @@ void cmdFunctionHelp(int arg_cnt, char **args)
|
|||||||
{
|
{
|
||||||
printFirmwareVersionAndBuildOptions();
|
printFirmwareVersionAndBuildOptions();
|
||||||
Serial.println(F("Use the commands: 'help' - this text\n"
|
Serial.println(F("Use the commands: 'help' - this text\n"
|
||||||
"'set de:ad:be:ef:fe:00' set and store MAC-address in EEPROM\n"
|
"'mac de:ad:be:ef:fe:00' set and store MAC-address in EEPROM\n"
|
||||||
|
"'ip [ip[,dns[,gw[,subnet]]]]' - set static IP\n"
|
||||||
"'save' - save config in NVRAM\n"
|
"'save' - save config in NVRAM\n"
|
||||||
"'get' - get config from pre-configured URL\n"
|
"'get' [config addr]' - get config from pre-configured URL and store addr\n"
|
||||||
"'load' - load config from NVRAM\n"
|
"'load' - load config from NVRAM\n"
|
||||||
|
"'pwd' - define MQTT password\n"
|
||||||
"'kill' - test watchdog"));
|
"'kill' - test watchdog"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmdFunctionKill(int arg_cnt, char **args) {
|
void cmdFunctionKill(int arg_cnt, char **args) {
|
||||||
for (short i = 17; i > 0; i--) {
|
for (short i = 1; i < 20; i++) {
|
||||||
delay(1000);
|
delay(1000);
|
||||||
Serial.println(i);
|
Serial.println(i);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void applyConfig() {
|
void applyConfig() {
|
||||||
|
if (!root) return;
|
||||||
#ifdef _dmxout
|
#ifdef _dmxout
|
||||||
int maxChannels;
|
int maxChannels;
|
||||||
aJsonObject *dmxoutArr = aJson.getObjectItem(root, "dmx");
|
aJsonObject *dmxoutArr = aJson.getObjectItem(root, "dmx");
|
||||||
@@ -550,7 +593,6 @@ void applyConfig() {
|
|||||||
Serial.println(maxChannels);
|
Serial.println(maxChannels);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _dmxin
|
#ifdef _dmxin
|
||||||
int itemsCount;
|
int itemsCount;
|
||||||
dmxArr = aJson.getObjectItem(root, "dmxin");
|
dmxArr = aJson.getObjectItem(root, "dmxin");
|
||||||
@@ -560,7 +602,6 @@ void applyConfig() {
|
|||||||
Serial.println(itemsCount * 4);
|
Serial.println(itemsCount * 4);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _modbus
|
#ifdef _modbus
|
||||||
modbusArr = aJson.getObjectItem(root, "modbus");
|
modbusArr = aJson.getObjectItem(root, "modbus");
|
||||||
#endif
|
#endif
|
||||||
@@ -574,7 +615,7 @@ void applyConfig() {
|
|||||||
aJsonObject *item = owArr->child;
|
aJsonObject *item = owArr->child;
|
||||||
owReady = owSetup(&Changed);
|
owReady = owSetup(&Changed);
|
||||||
t_count = 0;
|
t_count = 0;
|
||||||
while (item) {
|
while (item && owReady) {
|
||||||
if ((item->type == aJson_Object)) {
|
if ((item->type == aJson_Object)) {
|
||||||
DeviceAddress addr;
|
DeviceAddress addr;
|
||||||
//Serial.print(F("Add:")),Serial.println(item->name);
|
//Serial.print(F("Add:")),Serial.println(item->name);
|
||||||
@@ -586,7 +627,37 @@ void applyConfig() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
items = aJson.getObjectItem(root, "items");
|
items = aJson.getObjectItem(root, "items");
|
||||||
|
|
||||||
|
// Digital output related Items initialization
|
||||||
|
pollingItem=NULL;
|
||||||
|
if (items) {
|
||||||
|
aJsonObject * item = items->child;
|
||||||
|
while (items && item)
|
||||||
|
if (item->type == aJson_Array && aJson.getArraySize(item)>1) {
|
||||||
|
Item it(item);
|
||||||
|
if (it.isValid()) {
|
||||||
|
int pin=it.getArg();
|
||||||
|
int cmd = it.getCmd();
|
||||||
|
switch (it.itemType) {
|
||||||
|
case CH_THERMO:
|
||||||
|
if (cmd<1) it.setCmd(CMD_OFF);
|
||||||
|
case CH_RELAY:
|
||||||
|
{
|
||||||
|
int k;
|
||||||
|
pinMode(pin, OUTPUT);
|
||||||
|
digitalWrite(pin, k = ((cmd == CMD_ON) ? HIGH : LOW));
|
||||||
|
Serial.print(F("Pin:"));
|
||||||
|
Serial.print(pin);
|
||||||
|
Serial.print(F("="));
|
||||||
|
Serial.println(k);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
} //switch
|
||||||
|
} //isValid
|
||||||
|
item = item->next;
|
||||||
|
} //if
|
||||||
pollingItem = items->child;
|
pollingItem = items->child;
|
||||||
|
}
|
||||||
inputs = aJson.getObjectItem(root, "in");
|
inputs = aJson.getObjectItem(root, "in");
|
||||||
mqttArr = aJson.getObjectItem(root, "mqtt");
|
mqttArr = aJson.getObjectItem(root, "mqtt");
|
||||||
printConfigSummary();
|
printConfigSummary();
|
||||||
@@ -629,6 +700,7 @@ int loadConfigFromEEPROM(int arg_cnt, char **args)
|
|||||||
}
|
}
|
||||||
Serial.println(F("Loaded"));
|
Serial.println(F("Loaded"));
|
||||||
applyConfig();
|
applyConfig();
|
||||||
|
ethClient.stop(); //Refresh MQTT connect to get retained info
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
Serial.println(F("No stored config"));
|
Serial.println(F("No stored config"));
|
||||||
@@ -688,6 +760,35 @@ void cmdFunctionSave(int arg_cnt, char **args)
|
|||||||
Serial.println(F("Saved to EEPROM"));
|
Serial.println(F("Saved to EEPROM"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmdFunctionIp(int arg_cnt, char **args)
|
||||||
|
//(char* tokens)
|
||||||
|
{ IPAddress ip0 (0,0,0,0);
|
||||||
|
IPAddress ip;
|
||||||
|
DNSClient dns;
|
||||||
|
switch (arg_cnt) {
|
||||||
|
case 5: if (dns.inet_aton(args[4],ip)) saveIPAddressToFlash(OFFSET_MASK, ip); else
|
||||||
|
saveIPAddressToFlash(OFFSET_MASK, ip0);
|
||||||
|
case 4: if (dns.inet_aton(args[3],ip)) saveIPAddressToFlash(OFFSET_GW, ip); else
|
||||||
|
saveIPAddressToFlash(OFFSET_GW, ip0);
|
||||||
|
case 3: if (dns.inet_aton(args[2],ip)) saveIPAddressToFlash(OFFSET_DNS, ip); else
|
||||||
|
saveIPAddressToFlash(OFFSET_DNS, ip0);
|
||||||
|
case 2: if (dns.inet_aton(args[1],ip)) saveIPAddressToFlash(OFFSET_IP, ip); else
|
||||||
|
saveIPAddressToFlash(OFFSET_IP, ip0);
|
||||||
|
break;
|
||||||
|
case 1: //dynamic IP
|
||||||
|
saveIPAddressToFlash(OFFSET_IP, ip0);
|
||||||
|
}
|
||||||
|
Serial.println(F("Saved"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmdFunctionPwd(int arg_cnt, char **args)
|
||||||
|
//(char* tokens)
|
||||||
|
{ char empty[]="";
|
||||||
|
if (arg_cnt)
|
||||||
|
saveStringToFlash(OFFSET_MQTT_PWD, args[1]);
|
||||||
|
else saveStringToFlash(OFFSET_MQTT_PWD, empty);
|
||||||
|
Serial.println(F("Password updated"));
|
||||||
|
}
|
||||||
|
|
||||||
void cmdFunctionSetMac(int arg_cnt, char **args) {
|
void cmdFunctionSetMac(int arg_cnt, char **args) {
|
||||||
|
|
||||||
@@ -710,22 +811,40 @@ void cmdFunctionSetMac(int arg_cnt, char **args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cmdFunctionGet(int arg_cnt, char **args) {
|
void cmdFunctionGet(int arg_cnt, char **args) {
|
||||||
getConfig(arg_cnt, args);
|
lanStatus=getConfig(arg_cnt, args);
|
||||||
restoreState();
|
ethClient.stop(); //Refresh MQTT connect to get retained info
|
||||||
|
//restoreState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void printBool(bool arg) { (arg) ? Serial.println(F("on")) : Serial.println(F("off")); }
|
void printBool(bool arg) { (arg) ? Serial.println(F("on")) : Serial.println(F("off")); }
|
||||||
|
|
||||||
|
|
||||||
void saveFlash(short n, char *str) {}
|
void saveStringToFlash(short n, char *str) {
|
||||||
|
short i;
|
||||||
|
short len=strlen(str);
|
||||||
|
if (len>31) len=31;
|
||||||
|
for(int i=0;i<len;i++) EEPROM.write(n+i,str[i]);
|
||||||
|
EEPROM.write(n+len,0);
|
||||||
|
}
|
||||||
|
|
||||||
void loadFlash(short n, char *str) {}
|
int loadStringFromFlash(short offset, char *str, short numBytes) {
|
||||||
|
short i;
|
||||||
|
uint8_t ch = EEPROM.read(offset);
|
||||||
|
if (!ch || (ch == 0xff)) return 0;
|
||||||
|
for (i=0;i<numBytes-1 && (str[i] = EEPROM.read(offset++));i++);
|
||||||
|
str[i]=0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef MY_CONFIG_SERVER
|
void saveIPAddressToFlash(short n, IPAddress &ip) {
|
||||||
#define CONFIG_SERVER "lazyhome.ru"
|
for(int i=0;i<4;i++) EEPROM.write(n++,ip[i]);
|
||||||
#else
|
}
|
||||||
#define CONFIG_SERVER QUOTE(MY_CONFIG_SERVER)
|
|
||||||
#endif
|
int loadIPAddressFromFlash(short n, IPAddress &ip) {
|
||||||
|
for(int i=0;i<4;i++) ip[i]=EEPROM.read(n++);
|
||||||
|
if (ip[0] && (ip[0] != 0xff)) return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int getConfig(int arg_cnt, char **args)
|
int getConfig(int arg_cnt, char **args)
|
||||||
//(char *tokens)
|
//(char *tokens)
|
||||||
@@ -734,12 +853,13 @@ int getConfig(int arg_cnt, char **args)
|
|||||||
|
|
||||||
int responseStatusCode = 0;
|
int responseStatusCode = 0;
|
||||||
char ch;
|
char ch;
|
||||||
char URI[40];
|
char URI[CONFIG_URI_LENGTH];
|
||||||
char configServer[32] = CONFIG_SERVER;
|
char configServer[CONFIG_SERVER_ADDRESS_LENGTH]="";
|
||||||
if (arg_cnt > 0) {
|
if (arg_cnt > 1) {
|
||||||
strncpy(configServer, args[1], sizeof(configServer) - 1);
|
strncpy(configServer, args[1], sizeof(configServer) - 1);
|
||||||
saveFlash(0, configServer);
|
saveStringToFlash(OFFSET_CONFIGSERVER, configServer);
|
||||||
} else loadFlash(0, configServer);
|
} else if (!loadStringFromFlash(OFFSET_CONFIGSERVER, configServer))
|
||||||
|
strncpy_P(configServer,configServerPrecompiled,sizeof(configServer));
|
||||||
|
|
||||||
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), "/%02x-%02x-%02x-%02x-%02x-%02x.config.json", mac[0], mac[1], mac[2], mac[3], mac[4],
|
||||||
mac[5]);
|
mac[5]);
|
||||||
@@ -749,22 +869,24 @@ int getConfig(int arg_cnt, char **args)
|
|||||||
|
|
||||||
#if defined(__AVR__)
|
#if defined(__AVR__)
|
||||||
FILE *result;
|
FILE *result;
|
||||||
//byte hserver[] = { 192,168,88,2 };
|
|
||||||
wdt_dis();
|
wdt_dis();
|
||||||
HTTPClient hclient(configServer, 80);
|
|
||||||
|
|
||||||
|
|
||||||
|
HTTPClient hclient(configServer, CONFIG_SERVER_PORT);
|
||||||
// FILE is the return STREAM type of the HTTPClient
|
// FILE is the return STREAM type of the HTTPClient
|
||||||
result = hclient.getURI(URI);
|
result = hclient.getURI(URI);
|
||||||
responseStatusCode = hclient.getLastReturnCode();
|
responseStatusCode = hclient.getLastReturnCode();
|
||||||
wdt_en();
|
wdt_en();
|
||||||
|
|
||||||
if (result != NULL) {
|
if (result != NULL) {
|
||||||
if (responseStatusCode == 200) {
|
if (responseStatusCode == 200) {
|
||||||
|
|
||||||
Serial.println(F("got Config"));
|
Serial.println(F("got Config"));
|
||||||
aJsonFileStream as = aJsonFileStream(result);
|
aJsonFileStream as = aJsonFileStream(result);
|
||||||
|
noInterrupts();
|
||||||
aJson.deleteItem(root);
|
aJson.deleteItem(root);
|
||||||
root = aJson.parse(&as);
|
root = aJson.parse(&as);
|
||||||
|
interrupts();
|
||||||
|
// Serial.println(F("Parsed."));
|
||||||
hclient.closeStream(result); // this is very important -- be sure to close the STREAM
|
hclient.closeStream(result); // this is very important -- be sure to close the STREAM
|
||||||
|
|
||||||
if (!root) {
|
if (!root) {
|
||||||
@@ -775,7 +897,7 @@ int getConfig(int arg_cnt, char **args)
|
|||||||
// char *outstr = aJson.print(root);
|
// char *outstr = aJson.print(root);
|
||||||
// Serial.println(outstr);
|
// Serial.println(outstr);
|
||||||
// free(outstr);
|
// free(outstr);
|
||||||
|
Serial.println(F("Applying."));
|
||||||
applyConfig();
|
applyConfig();
|
||||||
|
|
||||||
|
|
||||||
@@ -798,11 +920,12 @@ int getConfig(int arg_cnt, char **args)
|
|||||||
#else
|
#else
|
||||||
//Non AVR code
|
//Non AVR code
|
||||||
String response;
|
String response;
|
||||||
|
EthernetClient configEthClient;
|
||||||
HttpClient htclient = HttpClient(ethClient, configServer, 80);
|
HttpClient htclient = HttpClient(configEthClient, configServer, CONFIG_SERVER_PORT);
|
||||||
htclient.setHttpResponseTimeout(4000);
|
//htclient.stop(); //_socket =MAX
|
||||||
|
htclient.setHttpResponseTimeout(CONFIG_SERVER_RESPONSE_TIMEOUT);
|
||||||
wdt_res();
|
wdt_res();
|
||||||
//Serial.println("making GET request");
|
//Serial.println("making GET request");get
|
||||||
htclient.beginRequest();
|
htclient.beginRequest();
|
||||||
htclient.get(URI);
|
htclient.get(URI);
|
||||||
htclient.endRequest();
|
htclient.endRequest();
|
||||||
@@ -848,14 +971,22 @@ int getConfig(int arg_cnt, char **args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void preTransmission() {
|
void preTransmission() {
|
||||||
|
#ifdef CONTROLLINO
|
||||||
|
// set DE and RE on HIGH
|
||||||
|
PORTJ |= B01100000;
|
||||||
|
#else
|
||||||
digitalWrite(TXEnablePin, 1);
|
digitalWrite(TXEnablePin, 1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void postTransmission() {
|
void postTransmission() {
|
||||||
//modbusSerial.flush();
|
#ifdef CONTROLLINO
|
||||||
|
// set DE and RE on LOW
|
||||||
|
PORTJ &= B10011111;
|
||||||
|
#else
|
||||||
digitalWrite(TXEnablePin, 0);
|
digitalWrite(TXEnablePin, 0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
//#define PIO_SRC_REV commit 8034a6b765229d94a94d90fd08dd9588acf5f3da Author: livello <livello@bk.ru> Date: Wed Mar 28 02:35:50 2018 +0300 refactoring
|
|
||||||
|
|
||||||
void setup_main() {
|
void setup_main() {
|
||||||
setupCmdArduino();
|
setupCmdArduino();
|
||||||
@@ -874,7 +1005,14 @@ void setup_main() {
|
|||||||
loadConfigFromEEPROM(0, NULL);
|
loadConfigFromEEPROM(0, NULL);
|
||||||
|
|
||||||
#ifdef _modbus
|
#ifdef _modbus
|
||||||
pinMode(TXEnablePin, OUTPUT);
|
#ifdef CONTROLLINO
|
||||||
|
//set PORTJ pin 5,6 direction (RE,DE)
|
||||||
|
DDRJ |= B01100000;
|
||||||
|
//set RE,DE on LOW
|
||||||
|
PORTJ &= B10011111;
|
||||||
|
#else
|
||||||
|
pinMode(TXEnablePin, OUTPUT);
|
||||||
|
#endif
|
||||||
modbusSerial.begin(MODBUS_SERIAL_BAUD);
|
modbusSerial.begin(MODBUS_SERIAL_BAUD);
|
||||||
node.idle(&modbusIdle);
|
node.idle(&modbusIdle);
|
||||||
// Callbacks allow us to configure the RS485 transceiver correctly
|
// Callbacks allow us to configure the RS485 transceiver correctly
|
||||||
@@ -894,7 +1032,11 @@ void setup_main() {
|
|||||||
#ifdef _artnet
|
#ifdef _artnet
|
||||||
ArtnetSetup();
|
ArtnetSetup();
|
||||||
#endif
|
#endif
|
||||||
|
/*
|
||||||
|
SPI.begin();
|
||||||
|
while (Ethernet.maintain() == NO_LINK && millis()<3000UL) {delay(500);Serial.print(F("."));}
|
||||||
|
*/
|
||||||
|
//delay(1000); //Wiz5500
|
||||||
//TODO: checkForRemoteSketchUpdate();
|
//TODO: checkForRemoteSketchUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -982,9 +1124,11 @@ void setupCmdArduino() {
|
|||||||
cmdAdd("save", cmdFunctionSave);
|
cmdAdd("save", cmdFunctionSave);
|
||||||
cmdAdd("load", cmdFunctionLoad);
|
cmdAdd("load", cmdFunctionLoad);
|
||||||
cmdAdd("get", cmdFunctionGet);
|
cmdAdd("get", cmdFunctionGet);
|
||||||
cmdAdd("set", cmdFunctionSetMac);
|
cmdAdd("mac", cmdFunctionSetMac);
|
||||||
cmdAdd("kill", cmdFunctionKill);
|
cmdAdd("kill", cmdFunctionKill);
|
||||||
cmdAdd("req", cmdFunctionReq);
|
cmdAdd("req", cmdFunctionReq);
|
||||||
|
cmdAdd("ip", cmdFunctionIp);
|
||||||
|
cmdAdd("pwd", cmdFunctionPwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop_main() {
|
void loop_main() {
|
||||||
@@ -1015,7 +1159,7 @@ void loop_main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (inputs) inputLoop();
|
inputLoop();
|
||||||
|
|
||||||
#if defined (_espdmx)
|
#if defined (_espdmx)
|
||||||
dmxout.update();
|
dmxout.update();
|
||||||
@@ -1041,6 +1185,11 @@ void owIdle(void) {
|
|||||||
dmxout.update();
|
dmxout.update();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
void ethernetIdle(void){
|
||||||
|
wdt_res();
|
||||||
|
inputLoop();
|
||||||
|
// Serial.print(".");
|
||||||
|
};
|
||||||
|
|
||||||
void modbusIdle(void) {
|
void modbusIdle(void) {
|
||||||
wdt_res();
|
wdt_res();
|
||||||
@@ -1049,8 +1198,10 @@ void modbusIdle(void) {
|
|||||||
#ifdef _artnet
|
#ifdef _artnet
|
||||||
if (artnet) artnet->read();
|
if (artnet) artnet->read();
|
||||||
#endif
|
#endif
|
||||||
|
inputLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef _dmxin
|
#ifdef _dmxin
|
||||||
DMXCheck();
|
DMXCheck();
|
||||||
#endif
|
#endif
|
||||||
@@ -1061,6 +1212,7 @@ void modbusIdle(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void inputLoop(void) {
|
void inputLoop(void) {
|
||||||
|
if (!inputs) return;
|
||||||
if (millis() > nextInputCheck) {
|
if (millis() > nextInputCheck) {
|
||||||
aJsonObject *input = inputs->child;
|
aJsonObject *input = inputs->child;
|
||||||
while (input) {
|
while (input) {
|
||||||
@@ -1121,7 +1273,7 @@ void thermoLoop(void) {
|
|||||||
mqttClient.publish("/alarm/snsr", item->name);
|
mqttClient.publish("/alarm/snsr", item->name);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (curtemp > itemTempSetting + THERMO_OVERHEAT_CELSIUS) mqttClient.publish("/alarm/ovrht", item->name);
|
if (curtemp > THERMO_OVERHEAT_CELSIUS) mqttClient.publish("/alarm/ovrht", item->name);
|
||||||
|
|
||||||
thermostatCheckPrinted = true;
|
thermostatCheckPrinted = true;
|
||||||
Serial.print(item->name);
|
Serial.print(item->name);
|
||||||
|
|||||||
@@ -40,8 +40,8 @@
|
|||||||
#include "stdarg.h"
|
#include "stdarg.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "inputs.h"
|
#include "inputs.h"
|
||||||
#include "Dhcp.h"
|
|
||||||
#include "FastLED.h"
|
#include "FastLED.h"
|
||||||
|
#include "Dns.h"
|
||||||
//#include "hsv2rgb.h"
|
//#include "hsv2rgb.h"
|
||||||
|
|
||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__)
|
||||||
@@ -81,9 +81,7 @@
|
|||||||
#ifdef Wiz5500
|
#ifdef Wiz5500
|
||||||
#include <Ethernet2.h>
|
#include <Ethernet2.h>
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include <Ethernet.h>
|
#include <Ethernet.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _artnet
|
#ifdef _artnet
|
||||||
@@ -92,13 +90,17 @@
|
|||||||
|
|
||||||
#ifdef SD_CARD_INSERTED
|
#ifdef SD_CARD_INSERTED
|
||||||
#include "sd_card_w5100.h"
|
#include "sd_card_w5100.h"
|
||||||
#endif
|
#endif //SD_CARD_INSERTED
|
||||||
|
|
||||||
|
#ifdef DHT_ENABLE
|
||||||
|
#include <DHT.h>
|
||||||
|
#endif //DHT_ENABLE/**/
|
||||||
|
|
||||||
#ifdef _artnet
|
#ifdef _artnet
|
||||||
extern Artnet *artnet;
|
extern Artnet *artnet;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void watchdogSetup(void);
|
//void watchdogSetup(void);
|
||||||
|
|
||||||
void mqttCallback(char *topic, byte *payload, unsigned int length);
|
void mqttCallback(char *topic, byte *payload, unsigned int length);
|
||||||
|
|
||||||
@@ -142,11 +144,15 @@ void cmdFunctionGet(int arg_cnt, char **args);
|
|||||||
|
|
||||||
void printBool(bool arg);
|
void printBool(bool arg);
|
||||||
|
|
||||||
void saveFlash(short n, char *str);
|
void saveStringToFlash(short n, char *str);
|
||||||
|
|
||||||
void loadFlash(short n, char *str);
|
int loadStringFromFlash(short offset, char *str, short numBytes = 32);
|
||||||
|
|
||||||
int getConfig(int arg_cnt, char **args);
|
void saveIPAddressToFlash(short n, IPAddress &ip);
|
||||||
|
|
||||||
|
int loadIPAddressFromFlash(short n, IPAddress &ip);
|
||||||
|
|
||||||
|
int getConfig(int arg_cnt=0, char **args=NULL);
|
||||||
|
|
||||||
void preTransmission();
|
void preTransmission();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Configuration of drivers enabled
|
// Configuration of drivers enabled
|
||||||
#ifndef PIO_SRC_REV
|
#ifndef PIO_SRC_REV
|
||||||
#define PIO_SRC_REV v0.994
|
#define PIO_SRC_REV v0.999
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TXEnablePin 13
|
#define TXEnablePin 13
|
||||||
@@ -9,22 +9,47 @@
|
|||||||
#define IET_TEMP 0
|
#define IET_TEMP 0
|
||||||
#define IET_ATTEMPTS 1
|
#define IET_ATTEMPTS 1
|
||||||
|
|
||||||
|
#define MQTT_SUBJECT_LENGTH 20
|
||||||
|
#define MQTT_TOPIC_LENGTH 20
|
||||||
|
|
||||||
#define THERMO_GIST_CELSIUS 2
|
#define THERMO_GIST_CELSIUS 2
|
||||||
#define THERMO_OVERHEAT_CELSIUS 5
|
#define THERMO_OVERHEAT_CELSIUS 38
|
||||||
#define FM_OVERHEAT_CELSIUS 5.
|
#define FM_OVERHEAT_CELSIUS 40.
|
||||||
|
|
||||||
#define EEPROM_offset 32+6
|
|
||||||
|
|
||||||
#define INTERVAL_CHECK_INPUT 50
|
#define OFFSET_MAC 0
|
||||||
|
#define OFFSET_IP OFFSET_MAC+6
|
||||||
|
#define OFFSET_DNS OFFSET_IP+4
|
||||||
|
#define OFFSET_GW OFFSET_DNS+4
|
||||||
|
#define OFFSET_MASK OFFSET_GW+4
|
||||||
|
#define OFFSET_CONFIGSERVER OFFSET_MASK+4
|
||||||
|
#define OFFSET_MQTT_PWD OFFSET_CONFIGSERVER+32
|
||||||
|
#define EEPROM_offset OFFSET_MQTT_PWD+16
|
||||||
|
|
||||||
|
#define INTERVAL_CHECK_INPUT 50
|
||||||
#define INTERVAL_CHECK_MODBUS 2000
|
#define INTERVAL_CHECK_MODBUS 2000
|
||||||
#define INTERVAL_POLLING 100
|
#define INTERVAL_POLLING 100
|
||||||
#define THERMOSTAT_CHECK_PERIOD 5000
|
#define THERMOSTAT_CHECK_PERIOD 5000
|
||||||
|
|
||||||
|
#define CONFIG_SERVER_ADDRESS_LENGTH 32
|
||||||
|
#define CONFIG_URI_LENGTH 40
|
||||||
|
#define CONFIG_SERVER_RESPONSE_TIMEOUT 4000
|
||||||
|
#define CONFIG_SERVER_PORT 80
|
||||||
|
|
||||||
|
#ifndef MY_CONFIG_SERVER
|
||||||
|
#define CONFIG_SERVER "lazyhome.ru"
|
||||||
|
#else
|
||||||
|
#define CONFIG_SERVER QUOTE(MY_CONFIG_SERVER)
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef MODBUS_SERIAL_BAUD
|
#ifndef MODBUS_SERIAL_BAUD
|
||||||
#define MODBUS_SERIAL_BAUD 9600
|
#define MODBUS_SERIAL_BAUD 9600
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef SERIAL_BAUD
|
#define dimPar SERIAL_8E1
|
||||||
|
#define fmPar SERIAL_8N1
|
||||||
|
|
||||||
|
#ifndef SERIAL_BAUD
|
||||||
#define SERIAL_BAUD 115200
|
#define SERIAL_BAUD 115200
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -32,6 +57,11 @@
|
|||||||
#define DEFAULT_FIRMWARE_MAC {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0}
|
#define DEFAULT_FIRMWARE_MAC {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef MY_CONFIG_SERVER
|
||||||
|
#define CONFIG_SERVER "lazyhome.ru"
|
||||||
|
#else
|
||||||
|
#define CONFIG_SERVER QUOTE(MY_CONFIG_SERVER)
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef OUTTOPIC
|
#ifndef OUTTOPIC
|
||||||
#define OUTTOPIC "/myhome/s_out/"
|
#define OUTTOPIC "/myhome/s_out/"
|
||||||
@@ -41,6 +71,9 @@
|
|||||||
#define INTOPIC "/myhome/in/"
|
#define INTOPIC "/myhome/in/"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define MQTT_SUBJECT_LENGTH 20
|
||||||
|
#define MQTT_TOPIC_LENGTH 20
|
||||||
|
|
||||||
#ifndef DMX_DISABLE
|
#ifndef DMX_DISABLE
|
||||||
#define _dmxin
|
#define _dmxin
|
||||||
#define _dmxout
|
#define _dmxout
|
||||||
@@ -64,14 +97,18 @@
|
|||||||
|
|
||||||
#if defined(__AVR__)
|
#if defined(__AVR__)
|
||||||
//All options available
|
//All options available
|
||||||
|
#ifdef CONTROLLINO
|
||||||
|
#define modbusSerial Serial3
|
||||||
|
#else
|
||||||
#define modbusSerial Serial2
|
#define modbusSerial Serial2
|
||||||
|
#endif
|
||||||
#define dmxin DMXSerial
|
#define dmxin DMXSerial
|
||||||
#define dmxout DmxSimple
|
#define dmxout DmxSimple
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__)
|
||||||
#define modbusSerial Serial2
|
#define modbusSerial Serial2
|
||||||
#define dmxout DmxDue1
|
#define dmxout DmxDue1
|
||||||
#define dmxin DmxDue1
|
#define dmxin DmxDue1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ e-mail anklimov@gmail.com
|
|||||||
|
|
||||||
|
|
||||||
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;
|
||||||
@@ -98,7 +98,7 @@ 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];
|
||||||
@@ -131,7 +131,7 @@ net = new OneWire (USE_1W_PIN);
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Serial.println(F("\tDS2482 error"));
|
||||||
return false;
|
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
|
// 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
|
||||||
|
|
||||||
@@ -199,5 +199,3 @@ void owAdd(DeviceAddress addr) {
|
|||||||
}
|
}
|
||||||
t_count++;
|
t_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
[platformio]
|
[platformio]
|
||||||
src_dir = lighthub
|
src_dir = lighthub
|
||||||
env_default =
|
env_default =
|
||||||
; megaatmega2560
|
; megaatmega2560
|
||||||
due
|
due
|
||||||
; esp8266
|
; esp8266
|
||||||
|
|
||||||
[env:due]
|
[env:due]
|
||||||
@@ -25,17 +25,21 @@ lib_deps =
|
|||||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
||||||
https://github.com/anklimov/DS2482_OneWire
|
https://github.com/anklimov/DS2482_OneWire
|
||||||
https://github.com/anklimov/DmxDue
|
https://github.com/anklimov/DmxDue
|
||||||
https://github.com/arduino-libraries/ArduinoHttpClient
|
https://github.com/anklimov/ArduinoHttpClient
|
||||||
https://github.com/anklimov/aJson
|
https://github.com/anklimov/aJson
|
||||||
https://github.com/anklimov/CmdArduino
|
https://github.com/anklimov/CmdArduino
|
||||||
https://github.com/anklimov/ModbusMaster
|
https://github.com/anklimov/ModbusMaster
|
||||||
https://github.com/anklimov/Ethernet
|
https://github.com/anklimov/Ethernet
|
||||||
|
https://github.com/anklimov/Ethernet2
|
||||||
; https://github.com/PaulStoffregen/SPI.git
|
; https://github.com/PaulStoffregen/SPI.git
|
||||||
https://github.com/knolleary/pubsubclient.git
|
https://github.com/knolleary/pubsubclient.git
|
||||||
https://github.com/anklimov/Artnet.git
|
https://github.com/anklimov/Artnet.git
|
||||||
FastLED
|
FastLED
|
||||||
161
|
SD
|
||||||
322
|
SdFat
|
||||||
|
https://github.com/adafruit/Adafruit_Sensor.git
|
||||||
|
; DHT sensor library@1.3.0
|
||||||
|
https://github.com/adafruit/DHT-sensor-library
|
||||||
|
|
||||||
|
|
||||||
[env:megaatmega2560]
|
[env:megaatmega2560]
|
||||||
@@ -54,58 +58,23 @@ lib_deps =
|
|||||||
https://github.com/anklimov/ModbusMaster
|
https://github.com/anklimov/ModbusMaster
|
||||||
https://github.com/anklimov/DMXSerial
|
https://github.com/anklimov/DMXSerial
|
||||||
https://github.com/anklimov/Ethernet
|
https://github.com/anklimov/Ethernet
|
||||||
https://github.com/PaulStoffregen/SPI.git
|
|
||||||
https://github.com/knolleary/pubsubclient.git
|
|
||||||
https://github.com/anklimov/Artnet.git
|
|
||||||
FastLED
|
|
||||||
161
|
|
||||||
322
|
|
||||||
|
|
||||||
[env:due-5500]
|
|
||||||
platform = atmelsam
|
|
||||||
framework = arduino
|
|
||||||
board = due
|
|
||||||
build_flags = -D Wiz5500
|
|
||||||
lib_deps =
|
|
||||||
https://github.com/sebnil/DueFlashStorage
|
|
||||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
|
||||||
https://github.com/anklimov/DS2482_OneWire
|
|
||||||
https://github.com/anklimov/DmxDue
|
|
||||||
https://github.com/arduino-libraries/ArduinoHttpClient
|
|
||||||
https://github.com/anklimov/aJson
|
|
||||||
https://github.com/anklimov/CmdArduino
|
|
||||||
https://github.com/anklimov/ModbusMaster
|
|
||||||
https://github.com/anklimov/Ethernet2
|
|
||||||
; https://github.com/PaulStoffregen/SPI.git
|
|
||||||
https://github.com/knolleary/pubsubclient.git
|
|
||||||
https://github.com/anklimov/Artnet.git
|
|
||||||
FastLED
|
|
||||||
|
|
||||||
[env:megaatmega2560-5500]
|
|
||||||
platform = atmelavr
|
|
||||||
board = megaatmega2560
|
|
||||||
framework = arduino
|
|
||||||
lib_ldf_mode = chain+
|
|
||||||
build_flags = -D Wiz5500
|
|
||||||
lib_deps =
|
|
||||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
|
||||||
https://github.com/anklimov/DS2482_OneWire
|
|
||||||
https://github.com/anklimov/DmxSimple
|
|
||||||
https://github.com/anklimov/httpClient
|
|
||||||
https://github.com/anklimov/aJson
|
|
||||||
https://github.com/anklimov/CmdArduino
|
|
||||||
https://github.com/anklimov/ModbusMaster
|
|
||||||
https://github.com/anklimov/DMXSerial
|
|
||||||
https://github.com/anklimov/Ethernet2
|
https://github.com/anklimov/Ethernet2
|
||||||
https://github.com/PaulStoffregen/SPI.git
|
https://github.com/PaulStoffregen/SPI.git
|
||||||
https://github.com/knolleary/pubsubclient.git
|
https://github.com/knolleary/pubsubclient.git
|
||||||
https://github.com/anklimov/Artnet.git
|
https://github.com/anklimov/Artnet.git
|
||||||
FastLED
|
FastLED
|
||||||
|
EEPROM
|
||||||
|
SD
|
||||||
|
SdFat
|
||||||
|
https://github.com/adafruit/Adafruit_Sensor.git
|
||||||
|
; DHT sensor library@1.3.0
|
||||||
|
https://github.com/adafruit/DHT-sensor-library
|
||||||
|
|
||||||
[env:esp8266]
|
[env:esp8266]
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
framework = arduino
|
framework = arduino
|
||||||
board = nodemcuv2
|
board = nodemcuv2
|
||||||
|
build_flags = !echo -n "-DPIO_SRC_REV="$(git rev-parse --short HEAD)
|
||||||
lib_ldf_mode = chain+
|
lib_ldf_mode = chain+
|
||||||
lib_deps =
|
lib_deps =
|
||||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
||||||
@@ -118,4 +87,4 @@ lib_deps =
|
|||||||
https://github.com/anklimov/DMXSerial
|
https://github.com/anklimov/DMXSerial
|
||||||
https://github.com/knolleary/pubsubclient.git
|
https://github.com/knolleary/pubsubclient.git
|
||||||
https://github.com/anklimov/Artnet.git
|
https://github.com/anklimov/Artnet.git
|
||||||
FastLED
|
FastLED
|
||||||
106
platformio.txt
106
platformio.txt
@@ -1,106 +0,0 @@
|
|||||||
; PlatformIO Project Configuration File (for copy and paste)
|
|
||||||
;
|
|
||||||
; Build options: build flags, source filter
|
|
||||||
; Upload options: custom upload port, speed and extra flags
|
|
||||||
; Library options: dependencies, extra library storages
|
|
||||||
; Advanced options: extra scripting
|
|
||||||
;
|
|
||||||
; Please visit documentation for the other options and examples
|
|
||||||
; http://docs.platformio.org/page/projectconf.html
|
|
||||||
[platformio]
|
|
||||||
src_dir = lighthub
|
|
||||||
|
|
||||||
[env:due]
|
|
||||||
platform = atmelsam
|
|
||||||
framework = arduino
|
|
||||||
board = due
|
|
||||||
lib_deps =
|
|
||||||
https://github.com/sebnil/DueFlashStorage
|
|
||||||
; https://github.com/livello/Arduino-Temperature-Control-Library.git#1306c49
|
|
||||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
|
||||||
https://github.com/anklimov/DS2482_OneWire
|
|
||||||
https://github.com/anklimov/DmxDue
|
|
||||||
https://github.com/arduino-libraries/ArduinoHttpClient
|
|
||||||
https://github.com/anklimov/aJson
|
|
||||||
https://github.com/anklimov/CmdArduino
|
|
||||||
https://github.com/anklimov/ModbusMaster
|
|
||||||
https://github.com/anklimov/Ethernet
|
|
||||||
https://github.com/PaulStoffregen/SPI.git
|
|
||||||
https://github.com/knolleary/pubsubclient.git
|
|
||||||
https://github.com/anklimov/Artnet.git
|
|
||||||
FastLED
|
|
||||||
|
|
||||||
[env:due-5500]
|
|
||||||
platform = atmelsam
|
|
||||||
framework = arduino
|
|
||||||
board = due
|
|
||||||
build_flags = -D Wiz5500
|
|
||||||
lib_deps =
|
|
||||||
https://github.com/sebnil/DueFlashStorage
|
|
||||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
|
||||||
https://github.com/anklimov/DS2482_OneWire
|
|
||||||
https://github.com/anklimov/DmxDue
|
|
||||||
https://github.com/arduino-libraries/ArduinoHttpClient
|
|
||||||
https://github.com/anklimov/aJson
|
|
||||||
https://github.com/anklimov/CmdArduino
|
|
||||||
https://github.com/anklimov/ModbusMaster
|
|
||||||
https://github.com/anklimov/Ethernet2
|
|
||||||
https://github.com/PaulStoffregen/SPI.git
|
|
||||||
https://github.com/knolleary/pubsubclient.git
|
|
||||||
https://github.com/anklimov/Artnet.git
|
|
||||||
|
|
||||||
[env:megaatmega2560]
|
|
||||||
platform = atmelavr
|
|
||||||
board = megaatmega2560
|
|
||||||
framework = arduino
|
|
||||||
lib_deps =
|
|
||||||
; https://github.com/livello/Arduino-Temperature-Control-Library.git#1306c49
|
|
||||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
|
||||||
https://github.com/anklimov/DS2482_OneWire
|
|
||||||
https://github.com/anklimov/DmxSimple
|
|
||||||
https://github.com/anklimov/httpClient
|
|
||||||
https://github.com/anklimov/aJson
|
|
||||||
https://github.com/anklimov/CmdArduino
|
|
||||||
https://github.com/anklimov/ModbusMaster
|
|
||||||
https://github.com/anklimov/DMXSerial
|
|
||||||
https://github.com/anklimov/Ethernet
|
|
||||||
https://github.com/PaulStoffregen/SPI.git
|
|
||||||
https://github.com/knolleary/pubsubclient.git
|
|
||||||
https://github.com/anklimov/Artnet.git
|
|
||||||
FastLED
|
|
||||||
|
|
||||||
[env:megaatmega2560-5500]
|
|
||||||
platform = atmelavr
|
|
||||||
board = megaatmega2560
|
|
||||||
framework = arduino
|
|
||||||
build_flags = -D Wiz5500
|
|
||||||
lib_deps =
|
|
||||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
|
||||||
https://github.com/anklimov/DS2482_OneWire
|
|
||||||
https://github.com/anklimov/DmxSimple
|
|
||||||
https://github.com/anklimov/httpClient
|
|
||||||
https://github.com/anklimov/aJson
|
|
||||||
https://github.com/anklimov/CmdArduino
|
|
||||||
https://github.com/anklimov/ModbusMaster
|
|
||||||
https://github.com/anklimov/DMXSerial
|
|
||||||
https://github.com/anklimov/Ethernet2
|
|
||||||
https://github.com/PaulStoffregen/SPI.git
|
|
||||||
https://github.com/knolleary/pubsubclient.git
|
|
||||||
https://github.com/anklimov/Artnet.git
|
|
||||||
|
|
||||||
[env:espressif8266]
|
|
||||||
platform = espressif8266
|
|
||||||
framework = arduino
|
|
||||||
board = nodemcuv2
|
|
||||||
lib_deps =
|
|
||||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
|
||||||
https://github.com/anklimov/DS2482_OneWire
|
|
||||||
https://github.com/anklimov/ESP-Dmx
|
|
||||||
https://github.com/arduino-libraries/ArduinoHttpClient
|
|
||||||
https://github.com/anklimov/aJson
|
|
||||||
https://github.com/anklimov/CmdArduino
|
|
||||||
https://github.com/anklimov/ModbusMaster
|
|
||||||
https://github.com/anklimov/DMXSerial
|
|
||||||
https://github.com/knolleary/pubsubclient.git
|
|
||||||
https://github.com/anklimov/Artnet.git
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user