esp8266 worked

esp8266 basic support, DMX now can be disabled
This commit is contained in:
livello
2018-05-22 20:45:02 +03:00
parent bc44c146b9
commit 2ce453db82
8 changed files with 125 additions and 74 deletions

View File

@@ -146,6 +146,8 @@ platformio device monitor -b 115200
* AVR_DMXOUT_PIN=18 // Set Pin for DMXOUT on megaatmega2560 * AVR_DMXOUT_PIN=18 // Set Pin for DMXOUT on megaatmega2560
* CONTROLLINO //Change Modbus port, direction pins and Wiznet SS pins to be working on [Controllino](http://controllino.biz/) * CONTROLLINO //Change Modbus port, direction pins and Wiznet SS pins to be working on [Controllino](http://controllino.biz/)
* LAN_INIT_DELAY=2000 // set lan init delay for Wiznet ethernet shield * LAN_INIT_DELAY=2000 // set lan init delay for Wiznet ethernet shield
* ESP_WIFI_AP=MYAP // esp wifi access point name
* ESP_WIFI_PWD=MYPWD // esp wifi access point password

View File

@@ -21,6 +21,8 @@
export FLAGS="$FLAGS -DAVR_DMXOUT_PIN=18" export FLAGS="$FLAGS -DAVR_DMXOUT_PIN=18"
export FLAGS="$FLAGS -DLAN_INIT_DELAY=2000" export FLAGS="$FLAGS -DLAN_INIT_DELAY=2000"
export FLAGS="$FLAGS -DCONTROLLINO" export FLAGS="$FLAGS -DCONTROLLINO"
export FLAGS="$FLAGS -DESP_WIFI_AP=MYAP"
export FLAGS="$FLAGS -DESP_WIFI_PWD=MYPWD"
export PLATFORMIO_BUILD_FLAGS="$FLAGS" export PLATFORMIO_BUILD_FLAGS="$FLAGS"
echo PLATFORMIO_BUILD_FLAGS=$PLATFORMIO_BUILD_FLAGS echo PLATFORMIO_BUILD_FLAGS=$PLATFORMIO_BUILD_FLAGS
echo "==============================================Custom build flags END=====================================================" echo "==============================================Custom build flags END====================================================="

View File

@@ -29,8 +29,10 @@ e-mail anklimov@gmail.com
#endif #endif
#if defined(__ESP__) #if defined(__ESP__)
#ifndef DMX_DISABLE
DMXESPSerial dmxout; DMXESPSerial dmxout;
#endif #endif
#endif
uint8_t * DMXin = NULL; uint8_t * DMXin = NULL;
int D_State=0; int D_State=0;

View File

@@ -696,8 +696,11 @@ void Item::mb_fail(short addr, short op, int val, int cmd) {
setVal(val); setVal(val);
} }
#ifndef MODBUS_DISABLE
extern ModbusMaster node; extern ModbusMaster node;
int Item::VacomSetFan(int8_t val, int8_t cmd) { int Item::VacomSetFan(int8_t val, int8_t cmd) {
int addr = getArg(); int addr = getArg();
Serial.print(F("VC#")); Serial.print(F("VC#"));
@@ -766,63 +769,6 @@ int Item::VacomSetHeat(int addr, int8_t val, int8_t cmd) {
modbusBusy = 0; modbusBusy = 0;
} }
int Item::SendStatus(short cmd, short n, int *Par, boolean deffered) {
/// ToDo: relative patches, configuration
if (deffered) {
setCmd(cmd | CMD_REPORT);
Serial.println(F("Status deffered"));
// mqttClient.publish("/push", "1");
return 0;
// Todo: Parameters? Now expected that parameters already stored by setVal()
}
else { //publush to MQTT
char addrstr[32];
//char addrbuf[17];
char valstr[16] = "";
strcpy_P(addrstr, outprefix);
strncat(addrstr, itemArr->name, sizeof(addrstr));
switch (cmd) {
case CMD_ON:
strcpy(valstr, "ON");
break;
case CMD_OFF:
case CMD_HALT:
strcpy(valstr, "OFF");
break;
// TODO send Par
case 0:
case CMD_SET:
if (Par)
for (short i = 0; i < n; i++) {
char num[4];
snprintf(num, sizeof(num), "%d", Par[i]);
strncat(valstr, num, sizeof(valstr));
if (i != n - 1) {
strcpy(num, ",");
strncat(valstr, num, sizeof(valstr));
}
}
break;
default:
Serial.println(F("Unknown cmd "));
return -1;
}
Serial.print(F("Pub: "));
Serial.print(addrstr);
Serial.print(F("->"));
Serial.println(valstr);
mqttClient.publish(addrstr, valstr,true);
return 0;
}
}
int Item::modbusDimmerSet(int addr, uint16_t _reg, int _mask, uint16_t value) { int Item::modbusDimmerSet(int addr, uint16_t _reg, int _mask, uint16_t value) {
if (modbusBusy) { if (modbusBusy) {
@@ -856,7 +802,6 @@ int Item::modbusDimmerSet(int addr, uint16_t _reg, int _mask, uint16_t value) {
modbusBusy = 0; modbusBusy = 0;
} }
int Item::checkFM() { int Item::checkFM() {
if (modbusBusy) return -1; if (modbusBusy) return -1;
if (checkModbusRetry()) return -2; if (checkModbusRetry()) return -2;
@@ -1118,3 +1063,59 @@ void Item::sendDelayedStatus(){
setCmd(cmd); setCmd(cmd);
} }
} }
#endif
int Item::SendStatus(short cmd, short n, int *Par, boolean deffered) {
/// ToDo: relative patches, configuration
if (deffered) {
setCmd(cmd | CMD_REPORT);
Serial.println(F("Status deffered"));
// mqttClient.publish("/push", "1");
return 0;
// Todo: Parameters? Now expected that parameters already stored by setVal()
}
else { //publush to MQTT
char addrstr[32];
//char addrbuf[17];
char valstr[16] = "";
strcpy_P(addrstr, outprefix);
strncat(addrstr, itemArr->name, sizeof(addrstr));
switch (cmd) {
case CMD_ON:
strcpy(valstr, "ON");
break;
case CMD_OFF:
case CMD_HALT:
strcpy(valstr, "OFF");
break;
// TODO send Par
case 0:
case CMD_SET:
if (Par)
for (short i = 0; i < n; i++) {
char num[4];
snprintf(num, sizeof(num), "%d", Par[i]);
strncat(valstr, num, sizeof(valstr));
if (i != n - 1) {
strcpy(num, ",");
strncat(valstr, num, sizeof(valstr));
}
}
break;
default:
Serial.println(F("Unknown cmd "));
return -1;
}
Serial.print(F("Pub: "));
Serial.print(addrstr);
Serial.print(F("->"));
Serial.println(valstr);
mqttClient.publish(addrstr, valstr,true);
return 0;
}
}

View File

@@ -270,8 +270,12 @@ int lanLoop() {
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", ""); Serial.print(F("WIFI AP/Password:"));
Serial.print(QUOTE(ESP_WIFI_AP));
Serial.print(F("/"));
Serial.println(QUOTE(ESP_WIFI_PWD));
wifiMulti.addAP(QUOTE(ESP_WIFI_AP), QUOTE(ESP_WIFI_PWD));
if((wifiMulti.run() == WL_CONNECTED)) lanStatus=1; if((wifiMulti.run() == WL_CONNECTED)) lanStatus=1;
#else #else
IPAddress ip; IPAddress ip;
@@ -858,10 +862,7 @@ return 0;
} }
int getConfig(int arg_cnt, char **args) int getConfig(int arg_cnt, char **args)
//(char *tokens)
{ {
int responseStatusCode = 0; int responseStatusCode = 0;
char ch; char ch;
char URI[40]; char URI[40];
@@ -928,9 +929,8 @@ int getConfig(int arg_cnt, char **args)
lanCheck = millis() + 5000; lanCheck = millis() + 5000;
return -11; return -11;
} }
#endif
#else #if defined(__SAM3X8E__)
//Non AVR code
String response; String response;
EthernetClient configEthClient; EthernetClient configEthClient;
HttpClient htclient = HttpClient(configEthClient, configServer, 80); HttpClient htclient = HttpClient(configEthClient, configServer, 80);
@@ -976,9 +976,39 @@ int getConfig(int arg_cnt, char **args)
//lanCheck=millis()+15000; //lanCheck=millis()+15000;
return -11; //Load from NVRAM return -11; //Load from NVRAM
} }
#endif #endif
#if defined(__ESP__)
HTTPClient httpClient;
String fullURI = "http://";
fullURI+=configServer;
fullURI+=URI;
httpClient.begin(fullURI);
int httpResponseCode = httpClient.GET();
if (httpResponseCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTP] GET... code: %d\n", httpResponseCode);
// file found at server
if (httpResponseCode == HTTP_CODE_OK) {
String response = httpClient.getString();
Serial.println(response);
aJson.deleteItem(root);
root = aJson.parse((char *) response.c_str());
if (!root) {
Serial.println(F("Config parsing failed"));
return -11; //Load from NVRAM
} else {
Serial.println(F("Config OK, Applying"));
applyConfig();
}
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", httpClient.errorToString(httpResponseCode).c_str());
httpClient.end();
return -11; //Load from NVRAM
}
httpClient.end();
#endif
return 2; return 2;
} }
@@ -1167,7 +1197,9 @@ void loop_main() {
// if (lastpacket && (lastpacket%10==0)) Serial.println(lastpacket); // if (lastpacket && (lastpacket%10==0)) Serial.println(lastpacket);
if (items) { if (items) {
#ifndef MODBUS_DISABLE
if (lanStatus != 4) pollingLoop(); if (lanStatus != 4) pollingLoop();
#endif
#ifdef _owire #ifdef _owire
thermoLoop(); thermoLoop();
#endif #endif
@@ -1241,6 +1273,7 @@ void inputLoop(void) {
} }
} }
#ifndef MODBUS_DISABLE
void pollingLoop(void) { void pollingLoop(void) {
boolean done = false; boolean done = false;
if (millis() > nextPollingCheck) { if (millis() > nextPollingCheck) {
@@ -1258,6 +1291,7 @@ void pollingLoop(void) {
} //while } //while
}//if }//if
} }
#endif
//TODO: refactoring //TODO: refactoring

View File

@@ -63,7 +63,7 @@
#include <FS.h> //this needs to be first, or it all crashes and burns... #include <FS.h> //this needs to be first, or it all crashes and burns...
#include "esp.h" #include "esp.h"
#include <EEPROM.h> #include <EEPROM.h>
#include <ArduinoHttpClient.h> #include <ESP8266HTTPClient.h>
#endif #endif
#ifdef _owire #ifdef _owire

View File

@@ -109,10 +109,20 @@
#if defined(__ESP__) #if defined(__ESP__)
#undef _dmxin #undef _dmxin
#undef _modbus #undef _modbus
#ifndef DMX_DISABLE
#define _espdmx #define _espdmx
#endif
#define modbusSerial Serial1 #define modbusSerial Serial1
#endif #endif
#ifndef _dmxout #ifndef _dmxout
#undef _artnet #undef _artnet
#endif #endif
#ifndef ESP_WIFI_AP
#define ESP_WIFI_AP mywifiap
#endif
#ifndef ESP_WIFI_PWD
#define ESP_WIFI_PWD mywifipass
#endif

View File

@@ -18,6 +18,7 @@ platform = atmelsam
framework = arduino framework = arduino
board = due board = due
lib_ldf_mode = chain+ lib_ldf_mode = chain+
extra_scripts = pre:my_build_flags.py
build_flags = !echo -n "-DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) build_flags = !echo -n "-DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short)
lib_deps = lib_deps =
https://github.com/sebnil/DueFlashStorage https://github.com/sebnil/DueFlashStorage
@@ -67,17 +68,16 @@ framework = arduino
board = nodemcuv2 board = nodemcuv2
lib_ldf_mode = chain+ lib_ldf_mode = chain+
build_flags = !echo -n "-DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) build_flags = !echo -n "-DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short)
pre = test.py extra_scripts = pre:my_build_flags.py
lib_deps = 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/ESP-Dmx https://github.com/anklimov/ESP-Dmx
https://github.com/arduino-libraries/ArduinoHttpClient ESP8266HTTPClient
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/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
WifiManager@0.12 WifiManager