diff --git a/README.md b/README.md index c526281..27ec0aa 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # LightHub -is Flexible, Arduino-Mega based SmartHome controller +is Flexible, Arduino-Mega/Arduino DUE/ESP8266 based SmartHome controller It allow to connect together: @@ -16,7 +16,7 @@ Scalability is virtually unlimited: Setup so many controllers you needed in most Prease refer our Wiki for insructions. -Just started preparation to porting firmware to AVR based Arduino DUE and ESP8266/ESP32 +Finished portation of proejct to Arduino DUE and ESP8266 (ESP32 not tested) Compiled image has been added to compiled/ folder use @@ -39,7 +39,7 @@ For patched libraries, appropriate GitHub repo URL provided: * DS2482_OneWire https://github.com/anklimov/DS2482_OneWire * FastLED * Wire (standard) -* Artnet +* Artnet https://github.com/anklimov/Artnet.git * DmxSimple https://github.com/anklimov/DmxSimple (for AVR) or https://github.com/anklimov/ESP-Dmx (for ESP) or https://github.com/anklimov/DmxDue (for DUE) * HTTPClient (for AVR) https://github.com/anklimov/HTTPClient or https://github.com/arduino-libraries/ArduinoHttpClient for other platforms * aJson https://github.com/anklimov/aJson @@ -51,8 +51,7 @@ For patched libraries, appropriate GitHub repo URL provided: * Ethernet https://github.com/anklimov/Ethernet * SPI (standard) -Portation from AVR Mega 2560 to SAM3X8E (Arduino DUE) is done since v 0.96 -Next step ESP portation +Portation from AVR Mega 2560 to SAM3X8E (Arduino DUE) done since v 0.96 #Platforms specific details: @@ -64,5 +63,14 @@ SAM3X8E: *both, DMX-in and DMX-out are hardware USART based. Use USART1 (pins 18 and 19) for DMX-out and DMX-in ESP: -*Wifi instead Ether not implemented yet -*DMX-IN not possible to deploy +*DMX-OUT on USART1 TX +*DMX-IN - not possible to deploy in ESP8266 +*Modbus - disabled. Might be configured in future on USART0 instead CLI/DEBUG + +since v. 0.97: + +There is first attempt to use Wiznet 5500 (still not stable enough) +Need to use compiler directive -D Wiz5500 and https://github.com/anklimov/Ethernet2 library + +First attempt to use platformio toolchain for compiling (work not completed yet) + diff --git a/lib/readme.txt b/lib/readme.txt new file mode 100644 index 0000000..dbadc3d --- /dev/null +++ b/lib/readme.txt @@ -0,0 +1,36 @@ + +This directory is intended for the project specific (private) libraries. +PlatformIO will compile them to static libraries and link to executable file. + +The source code of each library should be placed in separate directory, like +"lib/private_lib/[here are source files]". + +For example, see how can be organized `Foo` and `Bar` libraries: + +|--lib +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| |--Foo +| | |- Foo.c +| | |- Foo.h +| |- readme.txt --> THIS FILE +|- platformio.ini +|--src + |- main.c + +Then in `src/main.c` you should use: + +#include +#include + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +More information about PlatformIO Library Dependency Finder +- http://docs.platformio.org/page/librarymanager/ldf.html diff --git a/lighthub/dmx.cpp b/lighthub/dmx.cpp index e8826f6..7c44313 100644 --- a/lighthub/dmx.cpp +++ b/lighthub/dmx.cpp @@ -180,7 +180,7 @@ for (int i=1; i<17; i++) {Serial.print(dmxin.read(i));Serial.print(";");} } -void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data) +void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data, IPAddress remoteIP) { #ifdef _dmxout for (int i = 0 ; i < length && i +//needed for library +#include +#include +#include //https://github.com/tzapu/WiFiManager +#include + +extern ESP8266WiFiMulti wifiMulti; +extern WiFiClient ethClient; +//WiFiManager wifiManager; + +//define your default values here, if there are different values in config.json, they are overwritten. +//length should be max size + 1 +extern char mqtt_password[16]; + +//default custom static IP +//char static_ip[16] = "10.0.1.56"; +//char static_gw[16] = "10.0.1.1"; +//char static_sn[16] = "255.255.255.0"; + +//flag for saving data +extern bool shouldSaveConfig; + +void espSetup (); diff --git a/lighthub/lighthub.ino b/lighthub/lighthub.ino index dc0fffe..036288e 100644 --- a/lighthub/lighthub.ino +++ b/lighthub/lighthub.ino @@ -18,9 +18,9 @@ e-mail anklimov@gmail.com - * - * - * Done: + * + * + * Done: * MQMT/openhab * 1-wire * DMX - out @@ -33,7 +33,7 @@ e-mail anklimov@gmail.com * PWM Out 7,8,9 * 1-w relay out * Termostat out - + Todo === A/C control/Dimmer ? @@ -91,9 +91,9 @@ Config webserver DueFlashStorage EEPROM; #include #define wdt_res() watchdogReset() -#define wdt_en() -#define wdt_dis() - +#define wdt_en() +#define wdt_dis() + #else #include #endif @@ -101,12 +101,18 @@ Config webserver #if defined(__ESP__) #include "esp.h" #define wdt_res() -#define wdt_en() +#define wdt_en() #define wdt_dis() - + #else + +#ifdef Wiz5500 #include +#else +#include +#endif + EthernetClient ethClient; #endif @@ -128,7 +134,7 @@ extern Artnet *artnet; // Hardcoded definitions //Thermostate histeresys -#define GIST 2 +#define GIST 2 //#define serverip "192.168.88.2" //IPAddress server(192, 168, 88, 2); //TODO - configure it //char* inprefix=("/myhome/in/"); @@ -153,9 +159,9 @@ unsigned long incheck =0; unsigned long lanCheck =0; unsigned long thermocheck=0; -aJsonObject * modbusitem= NULL; +aJsonObject * modbusitem= NULL; -bool owReady = false; +bool owReady = false; int lanStatus = 0; #ifdef _modbus @@ -170,7 +176,7 @@ PubSubClient client(ethClient); void watchdogSetup(void){} //Do not remove - strong re-definition WDT Init for DUE -// MQTT Callback routine +// MQTT Callback routine void callback(char* topic, byte* payload, unsigned int length) { payload[length]=0; Serial.print(F("[")); @@ -183,7 +189,7 @@ void callback(char* topic, byte* payload, unsigned int length) { #define sublen 20 char subtopic[sublen]=""; int cmd = 0; - + for (int i=0;ibegin(); #endif - - break; + + break; case 2: // IP Ready, config loaded, Connecting broker & subscribe //Arming Watchdog - wdt_res(); + wdt_res(); { short n=0; int port=1883; char empty=0; char * user = ∅ char * pass = ∅ - + if (!client.connected() && mqttArr && ((n=aJson.getArraySize(mqttArr))>1)) { char *c=aJson.getArrayItem(mqttArr,0)->valuestring; char *servername=aJson.getArrayItem(mqttArr,1)->valuestring; if (n>=3) port=aJson.getArrayItem(mqttArr,2)->valueint; - + if (n>=4) user=aJson.getArrayItem(mqttArr,3)->valuestring; if (n>=5) pass=aJson.getArrayItem(mqttArr,4)->valuestring; - + client.setServer(servername,port); - - Serial.print(F("Attempting MQTT connection to ")); - Serial.print(servername); + + Serial.print(F("Attempting MQTT connection to ")); + Serial.print(servername); Serial.print(F(":")); Serial.print(port); Serial.print(F(" user:")); Serial.print(user); Serial.print(F(" ...")); - + if (client.connect(c,user,pass)) { Serial.print(F("connected as "));Serial.println(c); - - + + // ... and resubscribe client.subscribe(subprefix); - - + + restoreState(); - // if (_once) {DMXput(); _once=0;} + // if (_once) {DMXput(); _once=0;} lanStatus=3; } else { Serial.print(F("failed, rc=")); @@ -377,27 +384,29 @@ break; case 3: //operation if (!client.connected()) lanStatus=2; break; - + //Awaiting address -case -10: if (millis()>lanCheck) +case -10: if (millis()>lanCheck) lanStatus=0; -break; -//Reconnect -case -12: if (millis()>lanCheck) - +break; +//Reconnect +case -12: if (millis()>lanCheck) + lanStatus=2; break; - // read or Re-read config - case -11: + // read or Re-read config + case -11: if (loadConfig(0,NULL)) lanStatus=2; else {lanCheck=millis()+5000;lanStatus=-10;} break; case -14: ; - // do notghing with net -} + // do notghing with net +} + { +#ifndef __ESP__ wdt_dis(); if (lanStatus>0) switch (Ethernet.maintain()) @@ -437,7 +446,7 @@ if (lanStatus>0) } wdt_en(); - +#endif } return lanStatus; @@ -452,23 +461,23 @@ void Changed (int i, DeviceAddress addr, int val) char valstr[16]="NIL"; char *owEmit = NULL; char *owItem = NULL; - + //PrintBytes(addr,8); // Serial.print("Emit: "); SetBytes(addr,8,addrbuf);addrbuf[17]=0; - + //Serial.println(addrbuf); aJsonObject *owObj = aJson.getObjectItem(owArr, addrbuf); - if (owObj) + if (owObj) { owEmit = aJson.getObjectItem(owObj, "emit")->valuestring; - if (owEmit) + if (owEmit) { strncpy(addrbuf,owEmit,sizeof(addrbuf)); Serial.print(owEmit);Serial.print("=");Serial.println(val); } - owItem = aJson.getObjectItem(owObj, "item")->valuestring; + owItem = aJson.getObjectItem(owObj, "item")->valuestring; } else Serial.println(F("Not find")); @@ -477,7 +486,7 @@ void Changed (int i, DeviceAddress addr, int val) case 0x29: // DS2408 snprintf(addrstr,sizeof(addrstr),"%sS0%s",outprefix,addrbuf); // Serial.println(addrstr); - client.publish(addrstr, (val & SW_STAT0)?"ON":"OFF"); + client.publish(addrstr, (val & SW_STAT0)?"ON":"OFF"); snprintf(addrstr,sizeof(addrstr),"%sS1%s",outprefix,addrbuf); // Serial.println(addrstr); client.publish(addrstr, (val & SW_STAT1)?"ON":"OFF"); @@ -488,42 +497,42 @@ void Changed (int i, DeviceAddress addr, int val) // Serial.println(addrstr); client.publish(addrstr, (val & SW_AUX1)?"OFF":"ON"); break; - + case 0x28: // Thermomerer - - snprintf(addrstr,sizeof(addrstr),"%s%s",outprefix,addrbuf); + + snprintf(addrstr,sizeof(addrstr),"%s%s",outprefix,addrbuf); sprintf(valstr,"%d",val); //Serial.println(val); //Serial.println(valstr); client.publish(addrstr, valstr); - if (owItem) + if (owItem) { thermoSetCurTemp(owItem,val); } break; - + case 0x01: case 0x81: - snprintf(addrstr,sizeof(addrstr),"%sDS%s",outprefix,addrbuf); + snprintf(addrstr,sizeof(addrstr),"%sDS%s",outprefix,addrbuf); if (val) sprintf(valstr,"%s","ON"); else sprintf(valstr,"%s","OFF"); client.publish(addrstr, valstr); - } + } */ if ((val==-127) || (val==85)) { // Serial.print("Temp err ");Serial.println(t); - return; - } + return; + } strcpy_P (addrstr,outprefix); strncat (addrstr,addrbuf,sizeof(addrstr)); - //snprintf(addrstr,sizeof(addrstr),"%s%s",F(outprefix),addrbuf); + //snprintf(addrstr,sizeof(addrstr),"%s%s",F(outprefix),addrbuf); sprintf(valstr,"%d",val); client.publish(addrstr, valstr); - if (owItem) + if (owItem) { thermoSetCurTemp(owItem,val); ///TODO: Refactore using Items interface } @@ -551,48 +560,48 @@ void parseConfig() aJsonObject *dmxoutArr = aJson.getObjectItem(root, "dmx"); #ifdef _dmxout if (dmxoutArr && aJson.getArraySize(dmxoutArr)==2) - { - DMXoutSetup(mc=aJson.getArrayItem(dmxoutArr,1)->valueint,aJson.getArrayItem(dmxoutArr,0)->valueint); + { + DMXoutSetup(mc=aJson.getArrayItem(dmxoutArr,1)->valueint,aJson.getArrayItem(dmxoutArr,0)->valueint); Serial.print(F("DMX out started. Channels: ")); Serial.println(mc); } #endif //DMX in is configured #ifdef _dmxin - dmxArr= aJson.getObjectItem(root, "dmxin"); + dmxArr= aJson.getObjectItem(root, "dmxin"); if (dmxArr && (incnt=aJson.getArraySize(dmxArr))) { - DMXinSetup(incnt*4); + DMXinSetup(incnt*4); Serial.print(F("DMX in started. Channels:")); Serial.println(incnt*4); } #endif - - items = aJson.getObjectItem(root,"items"); + + items = aJson.getObjectItem(root,"items"); modbusitem = items->child; - inputs = aJson.getObjectItem(root,"in"); + inputs = aJson.getObjectItem(root,"in"); #ifdef _modbus modbusArr= aJson.getObjectItem(root, "modbus"); #endif - - mqttArr= aJson.getObjectItem(root, "mqtt"); - + + mqttArr= aJson.getObjectItem(root, "mqtt"); + #ifdef _owire - owArr= aJson.getObjectItem(root, "ow"); + owArr= aJson.getObjectItem(root, "ow"); #endif - + Serial.println(F("Configured:")); - + Serial.print(F("items ")); printBool(items); Serial.print(F("inputs ")); printBool(inputs); Serial.print(F("modbus ")); printBool(modbusArr); Serial.print(F("mqtt ")); printBool(mqttArr); Serial.print(F("1-wire ")); printBool(owArr); - + #ifdef _owire if (owArr && !owReady) - { + { aJsonObject * item= owArr->child; owReady=owSetup(&Changed); @@ -601,13 +610,13 @@ void parseConfig() if ((item->type==aJson_Object) ) { DeviceAddress addr; - //Serial.print(F("Add:")),Serial.println(item->name); - SetAddr(item->name,addr); + //Serial.print(F("Add:")),Serial.println(item->name); + SetAddr(item->name,addr); owAdd(addr); } item=item->next; } - + } #endif } @@ -615,30 +624,30 @@ void parseConfig() void _loadConfig (int arg_cnt, char **args) {loadConfig(arg_cnt,args);restoreState();} int loadConfig (int arg_cnt, char **args) //(char* tokens) -{ char ch; - Serial.println(F("loading Config")); - +{ char ch; + Serial.println(F("loading Config")); + ch=EEPROM.read(EEPROM_offset); if (ch=='{') { - aJsonEEPROMStream as=aJsonEEPROMStream(EEPROM_offset); + aJsonEEPROMStream as=aJsonEEPROMStream(EEPROM_offset); aJson.deleteItem(root); root = aJson.parse(&as); Serial.println(); if (!root) - { + { Serial.println(F("load failed")); return 0; - } + } Serial.println(F("Loaded")); parseConfig(); - return 1; + return 1; } - else + else { Serial.println(F("No stored config")); return 0; - + } } @@ -649,54 +658,54 @@ int mqttConfigReq (int arg_cnt, char **args) //(char* tokens) { char buf[25] ="/"; - Serial.println(F("request MQTT Config")); + Serial.println(F("request MQTT Config")); SetBytes((uint8_t*)mac,6,buf+1); buf[13]=0; strncat(buf,"/resp/#",25); Serial.println(buf); client.subscribe(buf); - buf[13]=0; + buf[13]=0; strncat(buf,"/req/conf",25); Serial.println(buf); client.publish(buf,"1"); - + } int mqttConfigResp (char * as) { - Serial.println(F("got MQTT Config")); - - //aJsonEEPROMStream as=aJsonEEPROMStream(EEPROM_offset); - + Serial.println(F("got MQTT Config")); + + //aJsonEEPROMStream as=aJsonEEPROMStream(EEPROM_offset); + //aJson.deleteItem(root); root = aJson.parse(as); Serial.println(); if (!root) - { + { Serial.println(F("load failed")); return 0; - } + } Serial.println(F("Loaded")); parseConfig(); - return 1; + return 1; } void _saveConfig(int arg_cnt, char **args) //(char* tokens) -{ - aJsonEEPROMStream es=aJsonEEPROMStream(EEPROM_offset); +{ + aJsonEEPROMStream es=aJsonEEPROMStream(EEPROM_offset); Serial.println(F("Saving config..")); aJson.print(root,&es); es.putEOF(); Serial.println(F("Saved")); - + } void _setConfig(int arg_cnt, char **args) -{ - +{ + //Serial.print("Got:"); //Serial.println(args[1]); if (sscanf(args[1], "%x:%x:%x:%x:%x:%x%с", @@ -714,7 +723,7 @@ void _setConfig(int arg_cnt, char **args) printMACAddress(); for (short i=0;i<6;i++) { EEPROM.write(i, mac[i]);} Serial.println(F("Updated")); - + } void _getConfig(int arg_cnt, char **args) {getConfig(arg_cnt,args);restoreState();} @@ -732,59 +741,59 @@ void loadFlash(short n, char* str) int getConfig (int arg_cnt, char **args) //(char *tokens) { - - + + int returnCode =0; char ch; char URI [32]; - char server[32] = "lazyhome.ru"; + char server[32] = "lazyhome.ru"; if (arg_cnt>0) { strncpy(server,args[1],sizeof(server)-1); saveFlash(0,server); } - else loadFlash(0,server); + else loadFlash(0,server); snprintf(URI, sizeof(URI), "/%02x-%02x-%02x-%02x-%02x-%02x.config.json",mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); Serial.println(F("Config URI: "));Serial.print(F("http://"));Serial.print(server);Serial.println(URI); #if defined(__AVR__) FILE* result; - //byte hserver[] = { 192,168,88,2 }; + //byte hserver[] = { 192,168,88,2 }; wdt_dis(); HTTPClient hclient(server,80); - - + + // FILE is the return STREAM type of the HTTPClient result = hclient.getURI( URI); returnCode = hclient.getLastReturnCode(); - wdt_en(); + wdt_en(); if (result!=NULL) { if (returnCode==200) { - - Serial.println(F("got Config")); - aJsonFileStream as=aJsonFileStream(result); - aJson.deleteItem(root); - root = aJson.parse(&as); + + Serial.println(F("got Config")); + aJsonFileStream as=aJsonFileStream(result); + aJson.deleteItem(root); + root = aJson.parse(&as); hclient.closeStream(result); // this is very important -- be sure to close the STREAM - + if (!root) { Serial.println(F("Config parsing failed")); lanCheck=millis()+15000; return -11; - } - else + } + else { char * outstr=aJson.print(root); Serial.println(outstr); free (outstr); - + parseConfig(); - + } - - } + + } else { Serial.print(F("ERROR: Server returned ")); Serial.println(returnCode); @@ -792,18 +801,18 @@ int getConfig (int arg_cnt, char **args) return -11; } - } + } else { Serial.println(F("failed to connect")); Serial.println(F(" try again in 5 seconds")); lanCheck=millis()+5000; return -11; } - + #else - //Non AVR code + //Non AVR code String response; - + HttpClient htclient = HttpClient(ethClient, server, 80); htclient.setHttpResponseTimeout(4000); wdt_res(); @@ -811,8 +820,8 @@ int getConfig (int arg_cnt, char **args) htclient.beginRequest(); htclient.get(URI); htclient.endRequest(); - - + + // read the status code and body of the response returnCode = htclient.responseStatusCode(); response = htclient.responseBody(); @@ -821,43 +830,43 @@ int getConfig (int arg_cnt, char **args) Serial.print("HTTP Status code: "); Serial.println(returnCode); //Serial.print("GET Response: "); - + if (returnCode==200) { - aJson.deleteItem(root); - root = aJson.parse((char*) response.c_str()); - + aJson.deleteItem(root); + root = aJson.parse((char*) response.c_str()); + if (!root) { Serial.println(F("Config parsing failed")); // lanCheck=millis()+15000; return -11; //Load from NVRAM - } - else + } + else { /* char * outstr=aJson.print(root); Serial.println(outstr); free (outstr); */ - Serial.println(response); + Serial.println(response); parseConfig(); - + } } - else + else { Serial.println(F("Config retrieving failed")); //lanCheck=millis()+15000; return -11; //Load from NVRAM - } + } + - #endif return 2; } - + #define TXEnablePin 13 void preTransmission() { @@ -866,14 +875,14 @@ void preTransmission() void postTransmission() { - //modbusSerial.flush(); + //modbusSerial.flush(); digitalWrite(TXEnablePin, 0); } -void setup() { +void setup() { cmdInit(115200); - Serial.println(F("\nLazyhome.ru LightHub controller v0.96")); + Serial.println(F("\nLazyhome.ru LightHub controller v0.97")); cmdAdd("help", _handleHelp); cmdAdd("save", _saveConfig); @@ -890,52 +899,52 @@ void setup() { short macvalid=0; byte defmac[6]={0xDE,0xAD,0xBE,0xEF,0xFE,0}; - - for (short i=0;i<6;i++) + + for (short i=0;i<6;i++) { mac[i]=EEPROM.read(i); if (mac[i]!=0 && mac[i]!=0xff) macvalid=1; } - if (!macvalid) + if (!macvalid) { Serial.println(F("Invalid MAC: set default")); memcpy(mac,defmac,6); } printMACAddress(); - - loadConfig(0,NULL); - + + loadConfig(0,NULL); + #ifdef _modbus pinMode(TXEnablePin,OUTPUT); modbusSerial.begin(9600); - node.idle(&modbusIdle); + node.idle(&modbusIdle); // Callbacks allow us to configure the RS485 transceiver correctly node.preTransmission(preTransmission); node.postTransmission(postTransmission); - #endif - + #endif + delay(20); - + owReady=0; - + #ifdef _owire if (net) net->idle(&owIdle); #endif - + //client.setServer(server, 1883); client.setCallback(callback); - + #ifdef _artnet ArtnetSetup(); #endif - + #if defined(__SAM3X8E__) // checkForRemoteSketchUpdate(); #endif - + } @@ -944,9 +953,9 @@ void loop(){ //commandLine.update(); cmdPoll(); -if (lanLoop() >1) +if (lanLoop() >1) { - client.loop(); + client.loop(); #ifdef _artnet if (artnet) artnet->read(); #endif @@ -959,7 +968,7 @@ if (owReady && owArr) owLoop(); #ifdef _dmxin // unsigned long lastpacket = DMXSerial.noDataSince(); DMXCheck(); -#endif +#endif // if (lastpacket && (lastpacket%10==0)) Serial.println(lastpacket); @@ -971,19 +980,19 @@ if (owReady && owArr) owLoop(); #ifdef _owire if (items) thermoLoop(); #endif - + if (inputs) inputLoop(); -#if defined (_espdmx) +#if defined (_espdmx) dmxout.update(); #endif } // Idle handlers -void owIdle(void) +void owIdle(void) { -#ifdef _artnet +#ifdef _artnet if (artnet) artnet->read(); #endif @@ -994,11 +1003,11 @@ void owIdle(void) if (lanLoop() == 1) client.loop(); //if (owReady) owLoop(); -#ifdef _dmxin +#ifdef _dmxin DMXCheck(); #endif -#if defined (_espdmx) +#if defined (_espdmx) dmxout.update(); #endif @@ -1006,25 +1015,25 @@ if (lanLoop() == 1) client.loop(); } -void modbusIdle(void) +void modbusIdle(void) { //Serial.print("m"); wdt_res(); -if (lanLoop() > 1) +if (lanLoop() > 1) { client.loop(); #ifdef _artnet if (artnet) artnet->read(); #endif } - + //if (owReady) owLoop(); #ifdef _dmxin DMXCheck(); #endif -#if defined (_espdmx) +#if defined (_espdmx) dmxout.update(); #endif @@ -1038,11 +1047,11 @@ if (lanLoop() > 1) void inputLoop(void) -{ +{ if (millis()>incheck) - { - + { + aJsonObject * input= inputs->child; while (input) @@ -1055,22 +1064,22 @@ void inputLoop(void) input=input->next; } - + incheck=millis()+50; - + } } void modbusLoop(void) -{ +{ boolean done=false; if (millis()>modbuscheck) - { + { while (modbusitem && !done) { if (modbusitem->type==aJson_Array) - { + { switch (aJson.getArrayItem(modbusitem, 0)->valueint) { case CH_MODBUS: @@ -1080,11 +1089,11 @@ void modbusLoop(void) Item it(modbusitem); it.Pool(); modbuscheck=millis()+2000; - done=true; + done=true; break; //case; } } //switch - + }//if modbusitem=modbusitem->next; if (!modbusitem) {modbusitem=items->child;return;} //start from 1-st element @@ -1096,14 +1105,14 @@ void modbusLoop(void) // To be refactored void thermoLoop(void) -{ +{ #define T_ATTEMPTS 200 -#define IET_TEMP 0 +#define IET_TEMP 0 #define IET_ATTEMPTS 1 if (millis()>thermocheck) - { - + { + aJsonObject * item= items->child; while (item) @@ -1112,25 +1121,25 @@ void thermoLoop(void) { int pin=aJson.getArrayItem(item, I_ARG)->valueint; int temp=aJson.getArrayItem(item, I_VAL)->valueint; - + int cmd=aJson.getArrayItem(item, I_CMD)->valueint; - + aJsonObject * extArr=aJson.getArrayItem(item, I_EXT); if (extArr && (aJson.getArraySize(extArr)>1) ) { int curtemp = aJson.getArrayItem(extArr, IET_TEMP)->valueint; - if (!aJson.getArrayItem(extArr, IET_ATTEMPTS)->valueint) + if (!aJson.getArrayItem(extArr, IET_ATTEMPTS)->valueint) { Serial.print(item->name);Serial.println(F(" Expired")); - - } - else + + } + else { if (! (--aJson.getArrayItem(extArr, IET_ATTEMPTS)->valueint)) client.publish("/alarm",item->name); - + } - Serial.print(item->name);Serial.print(F(" Set:"));Serial.print(temp); Serial.print(F(" Curtemp:"));Serial.print(curtemp); Serial.print(F( " cmd:")); Serial.print(cmd), + Serial.print(item->name);Serial.print(F(" Set:"));Serial.print(temp); Serial.print(F(" Curtemp:"));Serial.print(curtemp); Serial.print(F( " cmd:")); Serial.print(cmd), pinMode(pin,OUTPUT); if (cmd==CMD_OFF || cmd==CMD_HALT || aJson.getArrayItem(extArr, IET_ATTEMPTS)->valueint==0) {digitalWrite(pin,LOW);Serial.println(F(" OFF"));} @@ -1140,18 +1149,18 @@ void thermoLoop(void) else if(temp<=curtemp) {digitalWrite(pin,LOW);Serial.println(F(" OFF")); } //Reached settings else Serial.println(F(" --")); // Nothing to do } - - } + + } } item=item->next; } - + thermocheck=millis()+5000; Serial.println(freeRam()); } - -} + +} @@ -1161,32 +1170,29 @@ if (items) { aJsonObject *item= aJson.getObjectItem(items, name); if (item && (item->type==aJson_Array) && (aJson.getArrayItem(item, I_TYPE)->valueint==CH_THERMO) && (aJson.getArraySize(item)>=4)) - { + { aJsonObject * extArray =NULL; - + if (aJson.getArraySize(item)==4) //No thermo extension yet { extArray = aJson.createArray(); //Create Ext Array - + aJsonObject * ocurt=aJson.createItem(t); //Create int aJsonObject * oattempts=aJson.createItem(T_ATTEMPTS); //Create int aJson.addItemToArray(extArray,ocurt); aJson.addItemToArray(extArray,oattempts); - aJson.addItemToArray(item,extArray); //Adding to item + aJson.addItemToArray(item,extArray); //Adding to item } //if - else if (extArray=aJson.getArrayItem(item,I_EXT)) + else if (extArray=aJson.getArrayItem(item,I_EXT)) { - aJsonObject * att = aJson.getArrayItem(extArray, IET_ATTEMPTS); + aJsonObject * att = aJson.getArrayItem(extArray, IET_ATTEMPTS); aJson.getArrayItem(extArray, IET_TEMP)->valueint=t; if (att->valueint == 0) client.publish("/alarmoff",item->name); att->valueint =(int) T_ATTEMPTS; } //if - - + + } //if } // if items } //proc - - - diff --git a/platformio.ini b/platformio.ini index 1a8554f..316f61e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -14,17 +14,18 @@ src_dir = lighthub platform = atmelavr board = megaatmega2560 framework = arduino +build_flags = + -D Wiz5500 lib_deps = - https://github.com/livello/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 - 126 - https://github.com/PaulStoffregen/SPI.git - https://github.com/knolleary/pubsubclient.git - https://github.com/natcl/Artnet.git \ No newline at end of file + 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 diff --git a/platformio.txt b/platformio.txt new file mode 100644 index 0000000..ccab70f --- /dev/null +++ b/platformio.txt @@ -0,0 +1,100 @@ +; 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 + build_flags = + -D Wiz5500 + ib_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-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:megaatmega2560] + platform = atmelavr + board = megaatmega2560 + framework = arduino + 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/Ethernet + https://github.com/PaulStoffregen/SPI.git + https://github.com/knolleary/pubsubclient.git + https://github.com/anklimov/Artnet.git + + + [env:due] + platform = atmelsam + framework = arduino + board = due + ib_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/Ethernet + 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 + ib_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