mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
from IS-STM32Duino
This commit is contained in:
8
.idea/markdown-exported-files.xml
generated
Normal file
8
.idea/markdown-exported-files.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="MarkdownExportedFiles">
|
||||
<htmlFiles />
|
||||
<imageFiles />
|
||||
<otherFiles />
|
||||
</component>
|
||||
</project>
|
||||
@@ -23,30 +23,35 @@ e-mail anklimov@gmail.com
|
||||
#include <PubSubClient.h>
|
||||
|
||||
#ifndef DHT_DISABLE
|
||||
#if defined(ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||
#include <DHTesp.h>
|
||||
#else
|
||||
#include "DHT.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
extern PubSubClient mqttClient;
|
||||
//DHT dht();
|
||||
|
||||
static volatile unsigned long nextPollMillisValue[5];
|
||||
static volatile int nextPollMillisPin[5] = {0,0,0,0,0};
|
||||
|
||||
#if defined(__AVR__)
|
||||
static volatile long encoder_value[6];
|
||||
static volatile long counter_value[6];
|
||||
#endif
|
||||
|
||||
#if defined(ESP8266)
|
||||
static volatile long encoder_value[6];
|
||||
static volatile long counter_value[6];
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
static volatile long encoder_value[6];
|
||||
static volatile long counter_value[6];
|
||||
#endif
|
||||
|
||||
#if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32F1)
|
||||
static short encoder_irq_map[54];
|
||||
static long encoder_value[54];
|
||||
static int encoders_count;
|
||||
static short counter_irq_map[54];
|
||||
static long counter_value[54];
|
||||
static int counters_count;
|
||||
#endif
|
||||
|
||||
Input::Input(char * name) //Constructor
|
||||
{
|
||||
if (name)
|
||||
@@ -57,13 +62,13 @@ Input::Input(char * name) //Constructor
|
||||
}
|
||||
|
||||
|
||||
Input::Input(int pin) //Constructor
|
||||
Input::Input(int pin)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
||||
Input::Input(aJsonObject * obj) //Constructor
|
||||
Input::Input(aJsonObject * obj)
|
||||
{
|
||||
inputObj= obj;
|
||||
Parse();
|
||||
@@ -86,9 +91,9 @@ void Input::Parse()
|
||||
aJsonObject *s;
|
||||
|
||||
s = aJson.getObjectItem(inputObj, "T");
|
||||
if (s) inType = s->valueint;
|
||||
if (s) inType = static_cast<uint8_t>(s->valueint);
|
||||
|
||||
pin = atoi(inputObj->name);
|
||||
pin = static_cast<uint8_t>(atoi(inputObj->name));
|
||||
|
||||
s = aJson.getObjectItem(inputObj, "S");
|
||||
if (!s) {
|
||||
@@ -108,18 +113,17 @@ int Input::poll() {
|
||||
if (!isValid()) return -1;
|
||||
if (inType & IN_DHT22)
|
||||
dht22Poll();
|
||||
else if(inType & IN_ENCODER)
|
||||
encoderPoll();
|
||||
/* example
|
||||
else if (inType & IN_ANALOG)
|
||||
analogPoll(); */
|
||||
else if (inType & IN_COUNTER)
|
||||
counterPoll();
|
||||
else if (inType & IN_UPTIME)
|
||||
uptimePoll();
|
||||
else
|
||||
contactPoll();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Input::encoderPoll() {
|
||||
if (store->nextPollMillis > millis())
|
||||
void Input::counterPoll() {
|
||||
if(nextPollTime()>millis())
|
||||
return;
|
||||
if (store->logicState == 0) {
|
||||
#if defined(__AVR__)
|
||||
@@ -131,31 +135,31 @@ void Input::encoderPoll() {
|
||||
} else {
|
||||
Serial.print(F("IRQ:"));
|
||||
Serial.print(pin);
|
||||
Serial.print(F(" Encoder type. INCORRECT Interrupt number!!!"));
|
||||
Serial.print(F(" Counter type. INCORRECT Interrupt number!!!"));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
attachInterruptPinIrq(pin,encoders_count);
|
||||
encoder_irq_map[encoders_count]=pin;
|
||||
encoders_count++;
|
||||
attachInterruptPinIrq(pin,counters_count);
|
||||
counter_irq_map[counters_count]=pin;
|
||||
counters_count++;
|
||||
#endif
|
||||
store->logicState = 1;
|
||||
return;
|
||||
}
|
||||
long encoderValue = encoder_value[pin];
|
||||
Serial.print(F("IN:"));Serial.print(pin);Serial.print(F(" Encoder type. val="));Serial.print(encoderValue);
|
||||
long counterValue = counter_value[pin];
|
||||
Serial.print(F("IN:"));Serial.print(pin);Serial.print(F(" Counter type. val="));Serial.print(counterValue);
|
||||
|
||||
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
||||
if (emit) {
|
||||
char valstr[10];
|
||||
char addrstr[100] = "";
|
||||
strcat(addrstr, emit->valuestring);
|
||||
sprintf(valstr, "%d", encoderValue);
|
||||
sprintf(valstr, "%d", counterValue);
|
||||
mqttClient.publish(addrstr, valstr);
|
||||
store->nextPollMillis = millis() + DHT_POLL_DELAY_DEFAULT;
|
||||
Serial.print(F(" NextPollMillis="));Serial.println(store->nextPollMillis);
|
||||
setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT);
|
||||
Serial.print(F(" NextPollMillis="));Serial.println(nextPollTime());
|
||||
}
|
||||
else
|
||||
Serial.print(F(" No emit data!"));
|
||||
@@ -172,22 +176,22 @@ void Input::attachInterruptPinIrq(int realPin, int irq) {
|
||||
#endif
|
||||
switch(irq){
|
||||
case 0:
|
||||
attachInterrupt(real_irq, onEncoderChanged0, RISING);
|
||||
attachInterrupt(real_irq, onCounterChanged0, RISING);
|
||||
break;
|
||||
case 1:
|
||||
attachInterrupt(real_irq, onEncoderChanged1, RISING);
|
||||
attachInterrupt(real_irq, onCounterChanged1, RISING);
|
||||
break;
|
||||
case 2:
|
||||
attachInterrupt(real_irq, onEncoderChanged2, RISING);
|
||||
attachInterrupt(real_irq, onCounterChanged2, RISING);
|
||||
break;
|
||||
case 3:
|
||||
attachInterrupt(real_irq, onEncoderChanged3, RISING);
|
||||
attachInterrupt(real_irq, onCounterChanged3, RISING);
|
||||
break;
|
||||
case 4:
|
||||
attachInterrupt(real_irq, onEncoderChanged4, RISING);
|
||||
attachInterrupt(real_irq, onCounterChanged4, RISING);
|
||||
break;
|
||||
case 5:
|
||||
attachInterrupt(real_irq, onEncoderChanged5, RISING);
|
||||
attachInterrupt(real_irq, onCounterChanged5, RISING);
|
||||
break;
|
||||
default:
|
||||
Serial.print(F("Incorrect irq:"));Serial.println(irq);
|
||||
@@ -197,14 +201,27 @@ void Input::attachInterruptPinIrq(int realPin, int irq) {
|
||||
|
||||
void Input::dht22Poll() {
|
||||
#ifndef DHT_DISABLE
|
||||
if (store->nextPollMillis > millis())
|
||||
if(nextPollTime()>millis())
|
||||
return;
|
||||
#if defined(ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||
DHTesp dhtSensor;
|
||||
dhtSensor.setup(pin, DHTesp::DHT22);
|
||||
TempAndHumidity dhtSensorData = dhtSensor.getTempAndHumidity();
|
||||
float temp = dhtSensorData.temperature;
|
||||
float humidity = dhtSensorData.humidity;
|
||||
#else
|
||||
DHT dht(pin, DHT22);
|
||||
float temp = dht.readTemperature();
|
||||
float humidity = dht.readHumidity();
|
||||
#endif
|
||||
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
||||
Serial.print(F("IN:"));Serial.print(pin);Serial.print(F(" DHT22 type. T="));Serial.print(temp);
|
||||
Serial.print(F("°C H="));Serial.print(humidity);Serial.print(F("%"));
|
||||
Serial.print(F("IN:"));
|
||||
Serial.print(pin);
|
||||
Serial.print(F(" DHT22 type. T="));
|
||||
Serial.print(temp);
|
||||
Serial.print(F("°C H="));
|
||||
Serial.print(humidity);
|
||||
Serial.print(F("%"));
|
||||
if (emit && temp && humidity && temp == temp && humidity == humidity) {
|
||||
char valstr[10];
|
||||
char addrstr[100] = "";
|
||||
@@ -215,28 +232,53 @@ void Input::dht22Poll() {
|
||||
addrstr[strlen(addrstr) - 1] = 'H';
|
||||
printFloatValueToStr(humidity, valstr);
|
||||
mqttClient.publish(addrstr, valstr);
|
||||
store->nextPollMillis = millis() + DHT_POLL_DELAY_DEFAULT;
|
||||
Serial.print(" NextPollMillis=");Serial.println(store->nextPollMillis);
|
||||
}
|
||||
else
|
||||
store->nextPollMillis = millis() + DHT_POLL_DELAY_DEFAULT/3;
|
||||
setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT);
|
||||
Serial.print(" NextPollMillis=");
|
||||
Serial.println(nextPollTime());
|
||||
} else
|
||||
setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT / 3);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Input::printFloatValueToStr(float temp, char *valstr) {
|
||||
#if defined(ESP8266)
|
||||
sprintf(valstr, "%2.1f", temp);
|
||||
unsigned long Input::nextPollTime() const {
|
||||
for(int i=0;i<5;i++){
|
||||
if(nextPollMillisPin[i]==pin)
|
||||
return nextPollMillisValue[i];
|
||||
else if(nextPollMillisPin[i]==0) {
|
||||
nextPollMillisPin[i]=pin;
|
||||
return nextPollMillisValue[i] = 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Input::setNextPollTime(unsigned long pollTime) {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (nextPollMillisPin[i] == pin) {
|
||||
nextPollMillisValue[i] = pollTime;
|
||||
return;
|
||||
} else if (nextPollMillisPin[i] == 0) {
|
||||
nextPollMillisPin[i] == pin;
|
||||
nextPollMillisValue[i] = pollTime;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Input::printFloatValueToStr(float value, char *valstr) {
|
||||
#if defined(ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||
sprintf(valstr, "%2.1f", value);
|
||||
#endif
|
||||
#if defined(__AVR__)
|
||||
sprintf(valstr, "%d", (int)temp);
|
||||
int fractional = 10.0*((float)abs(temp)-(float)abs((int)temp));
|
||||
sprintf(valstr, "%d", (int)value);
|
||||
int fractional = 10.0*((float)abs(value)-(float)abs((int)value));
|
||||
int val_len =strlen(valstr);
|
||||
valstr[val_len]='.';
|
||||
valstr[val_len+1]='0'+fractional;
|
||||
valstr[val_len+2]='\0';
|
||||
#endif
|
||||
#if defined(__SAM3X8E__)
|
||||
sprintf(valstr, "%2.1f", temp);
|
||||
sprintf(valstr, "%2.1f",value);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -245,7 +287,7 @@ void Input::contactPoll() {
|
||||
#if defined(ARDUINO_ARCH_STM32F1)
|
||||
WiringPinMode inputPinMode;
|
||||
#endif
|
||||
#if defined(__SAM3X8E__)||defined(__AVR__)||defined(ESP8266)
|
||||
#if defined(__SAM3X8E__)||defined(__AVR__)||defined(ESP8266)||defined(ARDUINO_ARCH_ESP32)
|
||||
uint32_t inputPinMode;
|
||||
#endif
|
||||
|
||||
@@ -271,6 +313,19 @@ void Input::contactPoll() {
|
||||
store->bounce = SAME_STATE_ATTEMPTS;
|
||||
}
|
||||
|
||||
void Input::uptimePoll() {
|
||||
if(nextPollTime()>millis())
|
||||
return;
|
||||
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
||||
if (emit) {
|
||||
char valstr[11];
|
||||
// printUlongValueToStr(valstr,millis());
|
||||
printUlongValueToStr(valstr,millis());
|
||||
mqttClient.publish(emit->valuestring, valstr);
|
||||
}
|
||||
setNextPollTime(millis() +UPTIME_POLL_DELAY_DEFAULT);
|
||||
}
|
||||
|
||||
void Input::onContactChanged(int val)
|
||||
{
|
||||
Serial.print(F("IN:")); Serial.print(pin);Serial.print(F("="));Serial.println(val);
|
||||
@@ -309,32 +364,47 @@ void Input::onContactChanged(int val)
|
||||
}
|
||||
}
|
||||
|
||||
void Input::onEncoderChanged(int i) {
|
||||
void Input::onCounterChanged(int i) {
|
||||
#if defined(__SAM3X8E__)
|
||||
encoder_value[encoder_irq_map[i]]++;
|
||||
counter_value[counter_irq_map[i]]++;
|
||||
#endif
|
||||
|
||||
#if defined(__AVR__)
|
||||
encoder_value[i]++;
|
||||
counter_value[i]++;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Input::onEncoderChanged0() {
|
||||
onEncoderChanged(0);
|
||||
void Input::onCounterChanged0() {
|
||||
onCounterChanged(0);
|
||||
}
|
||||
void Input::onEncoderChanged1() {
|
||||
onEncoderChanged(1);
|
||||
void Input::onCounterChanged1() {
|
||||
onCounterChanged(1);
|
||||
}
|
||||
void Input::onEncoderChanged2() {
|
||||
onEncoderChanged(2);
|
||||
void Input::onCounterChanged2() {
|
||||
onCounterChanged(2);
|
||||
}
|
||||
void Input::onEncoderChanged3() {
|
||||
onEncoderChanged(3);
|
||||
void Input::onCounterChanged3() {
|
||||
onCounterChanged(3);
|
||||
}
|
||||
void Input::onEncoderChanged4() {
|
||||
onEncoderChanged(4);
|
||||
void Input::onCounterChanged4() {
|
||||
onCounterChanged(4);
|
||||
}
|
||||
void Input::onEncoderChanged5() {
|
||||
onEncoderChanged(5);
|
||||
void Input::onCounterChanged5() {
|
||||
onCounterChanged(5);
|
||||
}
|
||||
|
||||
void Input::printUlongValueToStr(char *valstr, unsigned long value) {
|
||||
char buf[11];
|
||||
int i=0;
|
||||
for(;value>0;i++){
|
||||
unsigned long mod = value - ((unsigned long)(value/10))*10;
|
||||
buf[i]=mod+48;
|
||||
value = (unsigned long)(value/10);
|
||||
}
|
||||
|
||||
for(int n=0;n<=i;n++){
|
||||
valstr[n]=buf[i-n-1];
|
||||
}
|
||||
valstr[i]='\0';
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,8 @@ e-mail anklimov@gmail.com
|
||||
#define IN_PUSH_ON 0 // PUSH - ON, Release - OFF (ovverrided by pcmd/rcmd) - DEFAULT
|
||||
#define IN_PUSH_TOGGLE 1 // Every physicall push toggle logical switch on/off
|
||||
#define IN_DHT22 4
|
||||
#define IN_ENCODER 8
|
||||
#define IN_COUNTER 8
|
||||
#define IN_UPTIME 16
|
||||
|
||||
#define SAME_STATE_ATTEMPTS 3
|
||||
|
||||
@@ -72,7 +73,7 @@ typedef union {
|
||||
int8_t bounce;
|
||||
int8_t currentValue;
|
||||
};
|
||||
unsigned long nextPollMillis;
|
||||
|
||||
} inStore;
|
||||
|
||||
class Input {
|
||||
@@ -94,13 +95,13 @@ public:
|
||||
|
||||
int poll();
|
||||
|
||||
static void inline onEncoderChanged(int i);
|
||||
static void onEncoderChanged0();
|
||||
static void onEncoderChanged1();
|
||||
static void onEncoderChanged2();
|
||||
static void onEncoderChanged3();
|
||||
static void onEncoderChanged4();
|
||||
static void onEncoderChanged5();
|
||||
static void inline onCounterChanged(int i);
|
||||
static void onCounterChanged0();
|
||||
static void onCounterChanged1();
|
||||
static void onCounterChanged2();
|
||||
static void onCounterChanged3();
|
||||
static void onCounterChanged4();
|
||||
static void onCounterChanged5();
|
||||
|
||||
|
||||
|
||||
@@ -111,10 +112,17 @@ protected:
|
||||
|
||||
void dht22Poll();
|
||||
|
||||
void printFloatValueToStr(float temp, char *valstr);
|
||||
void printFloatValueToStr(float value, char *valstr);
|
||||
|
||||
void encoderPoll();
|
||||
void counterPoll();
|
||||
|
||||
void attachInterruptPinIrq(int realPin, int irq);
|
||||
|
||||
unsigned long nextPollTime() const;
|
||||
void setNextPollTime(unsigned long pollTime);
|
||||
|
||||
|
||||
void uptimePoll();
|
||||
|
||||
void printUlongValueToStr(char *valstr, unsigned long value);
|
||||
};
|
||||
|
||||
@@ -88,6 +88,7 @@ WiFiClient ethClient;
|
||||
#include <WiFi.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <EEPROM.h>
|
||||
#include "Ethernet3.h"
|
||||
WiFiClient ethClient;
|
||||
#endif
|
||||
|
||||
@@ -105,6 +106,14 @@ WiFiClient ethClient;
|
||||
EthernetClient ethClient;
|
||||
#endif
|
||||
|
||||
#ifndef SYSLOG_DISABLE
|
||||
#include <EthernetUdp.h>
|
||||
#include <Syslog.h>
|
||||
EthernetUDP udpSyslogClient;
|
||||
Syslog udpSyslog(udpSyslogClient, SYSLOG_PROTO_IETF);
|
||||
unsigned long nextSyslogPingTime;
|
||||
#endif
|
||||
|
||||
lan_status lanStatus = INITIAL_STATE;
|
||||
|
||||
const char outprefix[] PROGMEM = OUTTOPIC;
|
||||
@@ -120,6 +129,7 @@ aJsonObject *mqttArr = NULL;
|
||||
aJsonObject *modbusArr = NULL;
|
||||
aJsonObject *owArr = NULL;
|
||||
aJsonObject *dmxArr = NULL;
|
||||
aJsonObject *udpSyslogArr = NULL;
|
||||
|
||||
unsigned long nextPollingCheck = 0;
|
||||
unsigned long nextInputCheck = 0;
|
||||
@@ -230,7 +240,7 @@ lan_status lanLoop() {
|
||||
|
||||
#ifdef NOETHER
|
||||
lanStatus=DO_NOTHING;//-14;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
switch (lanStatus) {
|
||||
case INITIAL_STATE:
|
||||
@@ -347,7 +357,24 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
||||
char *user = ∅
|
||||
char passwordBuf[16] = "";
|
||||
char *password = passwordBuf;
|
||||
|
||||
#ifndef SYSLOG_DISABLE
|
||||
debugSerial.println("debugSerial:");
|
||||
delay(100);
|
||||
char *syslogServer = aJson.getArrayItem(udpSyslogArr, 0)->valuestring;
|
||||
int syslogPort = aJson.getArrayItem(udpSyslogArr, 1)->valueint;
|
||||
char *syslogDeviceHostname = aJson.getArrayItem(udpSyslogArr, 2)->valuestring;
|
||||
char *syslogAppname = aJson.getArrayItem(udpSyslogArr, 3)->valuestring;
|
||||
debugSerial.println("debugSerial:");
|
||||
debugSerial.println(syslogServer);
|
||||
debugSerial.println(syslogPort);
|
||||
debugSerial.println(syslogDeviceHostname);
|
||||
debugSerial.println(syslogAppname);
|
||||
udpSyslog.server(syslogServer, syslogPort);
|
||||
udpSyslog.deviceHostname(syslogDeviceHostname);
|
||||
udpSyslog.appName(syslogAppname);
|
||||
udpSyslog.defaultPriority(LOG_KERN);
|
||||
udpSyslog.log(LOG_INFO, "UDP Syslog initialized!");
|
||||
#endif
|
||||
|
||||
if (!mqttClient.connected() && mqttArr && ((n = aJson.getArraySize(mqttArr)) > 1)) {
|
||||
char *client_id = aJson.getArrayItem(mqttArr, 0)->valuestring;
|
||||
@@ -510,7 +537,7 @@ void onInitialStateInitLAN() {
|
||||
printIPAddress(Ethernet.localIP());
|
||||
lanStatus = HAVE_IP_ADDRESS;//1;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ARDUINO_ARCH_STM32F1
|
||||
@@ -587,6 +614,9 @@ void cmdFunctionHelp(int arg_cnt, char **args)
|
||||
//(char* tokens)
|
||||
{
|
||||
printFirmwareVersionAndBuildOptions();
|
||||
#ifndef SYSLOG_DISABLE
|
||||
// udpSyslog.logf(LOG_INFO, "free RAM: %d",freeRam());
|
||||
#endif
|
||||
debugSerial.print(F(" free RAM: "));debugSerial.print(freeRam());
|
||||
debugSerial.println(F(" Use the commands: 'help' - this text\n"
|
||||
"'mac de:ad:be:ef:fe:00' set and store MAC-address in EEPROM\n"
|
||||
@@ -659,10 +689,10 @@ void applyConfig() {
|
||||
items = aJson.getObjectItem(root, "items");
|
||||
|
||||
// Digital output related Items initialization
|
||||
pollingItem=NULL;
|
||||
if (items) {
|
||||
aJsonObject * item = items->child;
|
||||
while (items && item)
|
||||
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()) {
|
||||
@@ -687,9 +717,10 @@ while (items && item)
|
||||
item = item->next;
|
||||
} //if
|
||||
pollingItem = items->child;
|
||||
}
|
||||
}
|
||||
inputs = aJson.getObjectItem(root, "in");
|
||||
mqttArr = aJson.getObjectItem(root, "mqtt");
|
||||
udpSyslogArr = aJson.getObjectItem(root, "syslog");
|
||||
printConfigSummary();
|
||||
}
|
||||
|
||||
@@ -705,6 +736,8 @@ void printConfigSummary() {
|
||||
printBool(mqttArr);
|
||||
debugSerial.print(F("1-wire "));
|
||||
printBool(owArr);
|
||||
debugSerial.print(F("udp syslog "));
|
||||
printBool(udpSyslogArr);
|
||||
}
|
||||
|
||||
void cmdFunctionLoad(int arg_cnt, char **args) {
|
||||
@@ -847,7 +880,7 @@ void cmdFunctionPwd(int arg_cnt, char **args)
|
||||
saveFlash(OFFSET_MQTT_PWD,args[1]);
|
||||
else saveFlash(OFFSET_MQTT_PWD,empty);
|
||||
debugSerial.println(F("Password updated"));
|
||||
}
|
||||
}
|
||||
|
||||
void cmdFunctionSetMac(int arg_cnt, char **args) {
|
||||
|
||||
@@ -887,12 +920,12 @@ void saveFlash(short n, char *str) {
|
||||
}
|
||||
|
||||
int loadFlash(short n, char *str, short l) {
|
||||
short i;
|
||||
uint8_t ch = EEPROM.read(n);
|
||||
if (!ch || (ch == 0xff)) return 0;
|
||||
short i;
|
||||
uint8_t ch = EEPROM.read(n);
|
||||
if (!ch || (ch == 0xff)) return 0;
|
||||
for (i=0;i<l-1 && (str[i] = EEPROM.read(n++));i++);
|
||||
str[i]=0;
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void saveFlash(short n, IPAddress& ip) {
|
||||
@@ -902,7 +935,7 @@ void saveFlash(short n, IPAddress& ip) {
|
||||
int ipLoadFromFlash(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;
|
||||
return 0;
|
||||
}
|
||||
|
||||
lan_status getConfig(int arg_cnt, char **args)
|
||||
@@ -1059,7 +1092,7 @@ lan_status getConfig(int arg_cnt, char **args)
|
||||
|
||||
void preTransmission() {
|
||||
#ifdef CONTROLLINO
|
||||
// set DE and RE on HIGH
|
||||
// set DE and RE on HIGH
|
||||
PORTJ |= B01100000;
|
||||
#else
|
||||
digitalWrite(TXEnablePin, 1);
|
||||
@@ -1086,7 +1119,7 @@ void setup_main() {
|
||||
loadConfigFromEEPROM(0, NULL);
|
||||
|
||||
#ifdef _modbus
|
||||
#ifdef CONTROLLINO
|
||||
#ifdef CONTROLLINO
|
||||
//set PORTJ pin 5,6 direction (RE,DE)
|
||||
DDRJ |= B01100000;
|
||||
//set RE,DE on LOW
|
||||
@@ -1129,6 +1162,8 @@ void setup_main() {
|
||||
void printFirmwareVersionAndBuildOptions() {
|
||||
debugSerial.print(F("\nLazyhome.ru LightHub controller "));
|
||||
debugSerial.println(F(QUOTE(PIO_SRC_REV)));
|
||||
debugSerial.print(F("C++ version:"));
|
||||
debugSerial.println(F(QUOTE(__cplusplus)));
|
||||
#ifdef CONTROLLINO
|
||||
debugSerial.println(F("(+)CONTROLLINO"));
|
||||
#endif
|
||||
@@ -1254,7 +1289,7 @@ void loop_main() {
|
||||
#endif
|
||||
|
||||
#ifdef _dmxin
|
||||
// unsigned long lastpacket = DMXSerial.noDataSince();
|
||||
// unsigned long lastpacket = DMXSerial.noDataSince();
|
||||
DMXCheck();
|
||||
#endif
|
||||
// if (lastpacket && (lastpacket%10==0)) debugSerial.println(lastpacket);
|
||||
@@ -1274,6 +1309,12 @@ void loop_main() {
|
||||
#if defined (_espdmx)
|
||||
dmxout.update();
|
||||
#endif
|
||||
|
||||
#ifndef SYSLOG_DISABLE
|
||||
// debugSerial.print(F("#"));
|
||||
// udpSyslog.log(LOG_INFO, "Ping syslog:");
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void owIdle(void) {
|
||||
@@ -1299,7 +1340,7 @@ void ethernetIdle(void){
|
||||
wdt_res();
|
||||
inputLoop();
|
||||
// debugSerial.print(".");
|
||||
};
|
||||
};
|
||||
|
||||
void modbusIdle(void) {
|
||||
wdt_res();
|
||||
|
||||
@@ -109,7 +109,7 @@
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include <SPI.h>
|
||||
#include <Ethernet3.h>
|
||||
//#include <Ethernet3.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -136,13 +136,14 @@
|
||||
#endif
|
||||
|
||||
#define DHT_POLL_DELAY_DEFAULT 15000
|
||||
#define UPTIME_POLL_DELAY_DEFAULT 30000
|
||||
|
||||
#ifdef ARDUINO_ARCH_STM32F1
|
||||
#define strncpy_P strncpy
|
||||
#endif
|
||||
|
||||
#ifndef debugSerial
|
||||
#define debugSerial Serial1
|
||||
#define debugSerial Serial
|
||||
#endif
|
||||
|
||||
#ifndef Wiz5500
|
||||
|
||||
@@ -18,7 +18,7 @@ env_default =
|
||||
; megaatmega2560-5500
|
||||
; due-5500
|
||||
; controllino
|
||||
stm32
|
||||
; stm32
|
||||
|
||||
build_dir = /tmp/pioenvs
|
||||
libdeps_dir = /tmp/piolibdeps
|
||||
@@ -48,7 +48,9 @@ lib_deps =
|
||||
platform = ststm32
|
||||
framework = arduino
|
||||
board = nucleo_f103rb
|
||||
upload_protocol = st-link
|
||||
upload_protocol = stlink
|
||||
debug_tool = stlink
|
||||
extra_scripts = pre:!pre_stm32.sh
|
||||
;lib_ldf_mode = chain+
|
||||
build_flags = !sh build_flags_stm32.sh
|
||||
lib_deps =
|
||||
@@ -62,7 +64,11 @@ lib_deps =
|
||||
https://github.com/knolleary/pubsubclient.git
|
||||
Adafruit Unified Sensor
|
||||
DHT sensor library
|
||||
|
||||
; https://github.com/anklimov/DMXSerial
|
||||
; Syslog
|
||||
; https://github.com/No3x/Syslog.git
|
||||
https://github.com/arcao/Syslog.git
|
||||
; UIPEthernet
|
||||
|
||||
[env:due]
|
||||
platform = atmelsam
|
||||
@@ -88,6 +94,7 @@ lib_deps =
|
||||
SdFat
|
||||
Adafruit Unified Sensor
|
||||
DHT sensor library
|
||||
https://github.com/arcao/Syslog.git
|
||||
|
||||
|
||||
[env:megaatmega2560]
|
||||
@@ -136,6 +143,7 @@ lib_deps =
|
||||
DHT sensor library for ESPx
|
||||
DHT sensor library
|
||||
WifiManager
|
||||
https://github.com/arcao/Syslog.git
|
||||
|
||||
[env:megaatmega2560-net]
|
||||
platform = atmelavr
|
||||
|
||||
4
pre_stm32.sh
Normal file
4
pre_stm32.sh
Normal file
@@ -0,0 +1,4 @@
|
||||
#! /bin/bash
|
||||
rm /tmp/piolibdeps -Rf
|
||||
mkdir /tmp/piolibdeps_stm32
|
||||
ln -s /tmp/piolibdeps_stm32 /tmp/piolibdeps
|
||||
Reference in New Issue
Block a user