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>
|
#include <PubSubClient.h>
|
||||||
|
|
||||||
#ifndef DHT_DISABLE
|
#ifndef DHT_DISABLE
|
||||||
|
#if defined(ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||||
|
#include <DHTesp.h>
|
||||||
|
#else
|
||||||
#include "DHT.h"
|
#include "DHT.h"
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
extern PubSubClient mqttClient;
|
extern PubSubClient mqttClient;
|
||||||
//DHT dht();
|
|
||||||
|
static volatile unsigned long nextPollMillisValue[5];
|
||||||
|
static volatile int nextPollMillisPin[5] = {0,0,0,0,0};
|
||||||
|
|
||||||
#if defined(__AVR__)
|
#if defined(__AVR__)
|
||||||
static volatile long encoder_value[6];
|
static volatile long counter_value[6];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
static volatile long encoder_value[6];
|
static volatile long counter_value[6];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
static volatile long encoder_value[6];
|
static volatile long counter_value[6];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32F1)
|
#if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32F1)
|
||||||
static short encoder_irq_map[54];
|
static short counter_irq_map[54];
|
||||||
static long encoder_value[54];
|
static long counter_value[54];
|
||||||
static int encoders_count;
|
static int counters_count;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Input::Input(char * name) //Constructor
|
Input::Input(char * name) //Constructor
|
||||||
{
|
{
|
||||||
if (name)
|
if (name)
|
||||||
@@ -57,13 +62,13 @@ Input::Input(char * name) //Constructor
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Input::Input(int pin) //Constructor
|
Input::Input(int pin)
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Input::Input(aJsonObject * obj) //Constructor
|
Input::Input(aJsonObject * obj)
|
||||||
{
|
{
|
||||||
inputObj= obj;
|
inputObj= obj;
|
||||||
Parse();
|
Parse();
|
||||||
@@ -86,9 +91,9 @@ void Input::Parse()
|
|||||||
aJsonObject *s;
|
aJsonObject *s;
|
||||||
|
|
||||||
s = aJson.getObjectItem(inputObj, "T");
|
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");
|
s = aJson.getObjectItem(inputObj, "S");
|
||||||
if (!s) {
|
if (!s) {
|
||||||
@@ -108,18 +113,17 @@ int Input::poll() {
|
|||||||
if (!isValid()) return -1;
|
if (!isValid()) return -1;
|
||||||
if (inType & IN_DHT22)
|
if (inType & IN_DHT22)
|
||||||
dht22Poll();
|
dht22Poll();
|
||||||
else if(inType & IN_ENCODER)
|
else if (inType & IN_COUNTER)
|
||||||
encoderPoll();
|
counterPoll();
|
||||||
/* example
|
else if (inType & IN_UPTIME)
|
||||||
else if (inType & IN_ANALOG)
|
uptimePoll();
|
||||||
analogPoll(); */
|
|
||||||
else
|
else
|
||||||
contactPoll();
|
contactPoll();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Input::encoderPoll() {
|
void Input::counterPoll() {
|
||||||
if (store->nextPollMillis > millis())
|
if(nextPollTime()>millis())
|
||||||
return;
|
return;
|
||||||
if (store->logicState == 0) {
|
if (store->logicState == 0) {
|
||||||
#if defined(__AVR__)
|
#if defined(__AVR__)
|
||||||
@@ -131,31 +135,31 @@ void Input::encoderPoll() {
|
|||||||
} else {
|
} else {
|
||||||
Serial.print(F("IRQ:"));
|
Serial.print(F("IRQ:"));
|
||||||
Serial.print(pin);
|
Serial.print(pin);
|
||||||
Serial.print(F(" Encoder type. INCORRECT Interrupt number!!!"));
|
Serial.print(F(" Counter type. INCORRECT Interrupt number!!!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__)
|
||||||
attachInterruptPinIrq(pin,encoders_count);
|
attachInterruptPinIrq(pin,counters_count);
|
||||||
encoder_irq_map[encoders_count]=pin;
|
counter_irq_map[counters_count]=pin;
|
||||||
encoders_count++;
|
counters_count++;
|
||||||
#endif
|
#endif
|
||||||
store->logicState = 1;
|
store->logicState = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
long encoderValue = encoder_value[pin];
|
long counterValue = counter_value[pin];
|
||||||
Serial.print(F("IN:"));Serial.print(pin);Serial.print(F(" Encoder type. val="));Serial.print(encoderValue);
|
Serial.print(F("IN:"));Serial.print(pin);Serial.print(F(" Counter type. val="));Serial.print(counterValue);
|
||||||
|
|
||||||
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
||||||
if (emit) {
|
if (emit) {
|
||||||
char valstr[10];
|
char valstr[10];
|
||||||
char addrstr[100] = "";
|
char addrstr[100] = "";
|
||||||
strcat(addrstr, emit->valuestring);
|
strcat(addrstr, emit->valuestring);
|
||||||
sprintf(valstr, "%d", encoderValue);
|
sprintf(valstr, "%d", counterValue);
|
||||||
mqttClient.publish(addrstr, valstr);
|
mqttClient.publish(addrstr, valstr);
|
||||||
store->nextPollMillis = millis() + DHT_POLL_DELAY_DEFAULT;
|
setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT);
|
||||||
Serial.print(F(" NextPollMillis="));Serial.println(store->nextPollMillis);
|
Serial.print(F(" NextPollMillis="));Serial.println(nextPollTime());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Serial.print(F(" No emit data!"));
|
Serial.print(F(" No emit data!"));
|
||||||
@@ -172,22 +176,22 @@ void Input::attachInterruptPinIrq(int realPin, int irq) {
|
|||||||
#endif
|
#endif
|
||||||
switch(irq){
|
switch(irq){
|
||||||
case 0:
|
case 0:
|
||||||
attachInterrupt(real_irq, onEncoderChanged0, RISING);
|
attachInterrupt(real_irq, onCounterChanged0, RISING);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
attachInterrupt(real_irq, onEncoderChanged1, RISING);
|
attachInterrupt(real_irq, onCounterChanged1, RISING);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
attachInterrupt(real_irq, onEncoderChanged2, RISING);
|
attachInterrupt(real_irq, onCounterChanged2, RISING);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
attachInterrupt(real_irq, onEncoderChanged3, RISING);
|
attachInterrupt(real_irq, onCounterChanged3, RISING);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
attachInterrupt(real_irq, onEncoderChanged4, RISING);
|
attachInterrupt(real_irq, onCounterChanged4, RISING);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
attachInterrupt(real_irq, onEncoderChanged5, RISING);
|
attachInterrupt(real_irq, onCounterChanged5, RISING);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Serial.print(F("Incorrect irq:"));Serial.println(irq);
|
Serial.print(F("Incorrect irq:"));Serial.println(irq);
|
||||||
@@ -197,14 +201,27 @@ void Input::attachInterruptPinIrq(int realPin, int irq) {
|
|||||||
|
|
||||||
void Input::dht22Poll() {
|
void Input::dht22Poll() {
|
||||||
#ifndef DHT_DISABLE
|
#ifndef DHT_DISABLE
|
||||||
if (store->nextPollMillis > millis())
|
if(nextPollTime()>millis())
|
||||||
return;
|
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);
|
DHT dht(pin, DHT22);
|
||||||
float temp = dht.readTemperature();
|
float temp = dht.readTemperature();
|
||||||
float humidity = dht.readHumidity();
|
float humidity = dht.readHumidity();
|
||||||
|
#endif
|
||||||
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
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("IN:"));
|
||||||
Serial.print(F("°C H="));Serial.print(humidity);Serial.print(F("%"));
|
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) {
|
if (emit && temp && humidity && temp == temp && humidity == humidity) {
|
||||||
char valstr[10];
|
char valstr[10];
|
||||||
char addrstr[100] = "";
|
char addrstr[100] = "";
|
||||||
@@ -215,28 +232,53 @@ void Input::dht22Poll() {
|
|||||||
addrstr[strlen(addrstr) - 1] = 'H';
|
addrstr[strlen(addrstr) - 1] = 'H';
|
||||||
printFloatValueToStr(humidity, valstr);
|
printFloatValueToStr(humidity, valstr);
|
||||||
mqttClient.publish(addrstr, valstr);
|
mqttClient.publish(addrstr, valstr);
|
||||||
store->nextPollMillis = millis() + DHT_POLL_DELAY_DEFAULT;
|
setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT);
|
||||||
Serial.print(" NextPollMillis=");Serial.println(store->nextPollMillis);
|
Serial.print(" NextPollMillis=");
|
||||||
}
|
Serial.println(nextPollTime());
|
||||||
else
|
} else
|
||||||
store->nextPollMillis = millis() + DHT_POLL_DELAY_DEFAULT/3;
|
setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT / 3);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Input::printFloatValueToStr(float temp, char *valstr) {
|
unsigned long Input::nextPollTime() const {
|
||||||
#if defined(ESP8266)
|
for(int i=0;i<5;i++){
|
||||||
sprintf(valstr, "%2.1f", temp);
|
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
|
#endif
|
||||||
#if defined(__AVR__)
|
#if defined(__AVR__)
|
||||||
sprintf(valstr, "%d", (int)temp);
|
sprintf(valstr, "%d", (int)value);
|
||||||
int fractional = 10.0*((float)abs(temp)-(float)abs((int)temp));
|
int fractional = 10.0*((float)abs(value)-(float)abs((int)value));
|
||||||
int val_len =strlen(valstr);
|
int val_len =strlen(valstr);
|
||||||
valstr[val_len]='.';
|
valstr[val_len]='.';
|
||||||
valstr[val_len+1]='0'+fractional;
|
valstr[val_len+1]='0'+fractional;
|
||||||
valstr[val_len+2]='\0';
|
valstr[val_len+2]='\0';
|
||||||
#endif
|
#endif
|
||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__)
|
||||||
sprintf(valstr, "%2.1f", temp);
|
sprintf(valstr, "%2.1f",value);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,7 +287,7 @@ void Input::contactPoll() {
|
|||||||
#if defined(ARDUINO_ARCH_STM32F1)
|
#if defined(ARDUINO_ARCH_STM32F1)
|
||||||
WiringPinMode inputPinMode;
|
WiringPinMode inputPinMode;
|
||||||
#endif
|
#endif
|
||||||
#if defined(__SAM3X8E__)||defined(__AVR__)||defined(ESP8266)
|
#if defined(__SAM3X8E__)||defined(__AVR__)||defined(ESP8266)||defined(ARDUINO_ARCH_ESP32)
|
||||||
uint32_t inputPinMode;
|
uint32_t inputPinMode;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -271,6 +313,19 @@ void Input::contactPoll() {
|
|||||||
store->bounce = SAME_STATE_ATTEMPTS;
|
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)
|
void Input::onContactChanged(int val)
|
||||||
{
|
{
|
||||||
Serial.print(F("IN:")); Serial.print(pin);Serial.print(F("="));Serial.println(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__)
|
#if defined(__SAM3X8E__)
|
||||||
encoder_value[encoder_irq_map[i]]++;
|
counter_value[counter_irq_map[i]]++;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__AVR__)
|
#if defined(__AVR__)
|
||||||
encoder_value[i]++;
|
counter_value[i]++;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Input::onEncoderChanged0() {
|
void Input::onCounterChanged0() {
|
||||||
onEncoderChanged(0);
|
onCounterChanged(0);
|
||||||
}
|
}
|
||||||
void Input::onEncoderChanged1() {
|
void Input::onCounterChanged1() {
|
||||||
onEncoderChanged(1);
|
onCounterChanged(1);
|
||||||
}
|
}
|
||||||
void Input::onEncoderChanged2() {
|
void Input::onCounterChanged2() {
|
||||||
onEncoderChanged(2);
|
onCounterChanged(2);
|
||||||
}
|
}
|
||||||
void Input::onEncoderChanged3() {
|
void Input::onCounterChanged3() {
|
||||||
onEncoderChanged(3);
|
onCounterChanged(3);
|
||||||
}
|
}
|
||||||
void Input::onEncoderChanged4() {
|
void Input::onCounterChanged4() {
|
||||||
onEncoderChanged(4);
|
onCounterChanged(4);
|
||||||
}
|
}
|
||||||
void Input::onEncoderChanged5() {
|
void Input::onCounterChanged5() {
|
||||||
onEncoderChanged(5);
|
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_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_PUSH_TOGGLE 1 // Every physicall push toggle logical switch on/off
|
||||||
#define IN_DHT22 4
|
#define IN_DHT22 4
|
||||||
#define IN_ENCODER 8
|
#define IN_COUNTER 8
|
||||||
|
#define IN_UPTIME 16
|
||||||
|
|
||||||
#define SAME_STATE_ATTEMPTS 3
|
#define SAME_STATE_ATTEMPTS 3
|
||||||
|
|
||||||
@@ -72,7 +73,7 @@ typedef union {
|
|||||||
int8_t bounce;
|
int8_t bounce;
|
||||||
int8_t currentValue;
|
int8_t currentValue;
|
||||||
};
|
};
|
||||||
unsigned long nextPollMillis;
|
|
||||||
} inStore;
|
} inStore;
|
||||||
|
|
||||||
class Input {
|
class Input {
|
||||||
@@ -94,13 +95,13 @@ public:
|
|||||||
|
|
||||||
int poll();
|
int poll();
|
||||||
|
|
||||||
static void inline onEncoderChanged(int i);
|
static void inline onCounterChanged(int i);
|
||||||
static void onEncoderChanged0();
|
static void onCounterChanged0();
|
||||||
static void onEncoderChanged1();
|
static void onCounterChanged1();
|
||||||
static void onEncoderChanged2();
|
static void onCounterChanged2();
|
||||||
static void onEncoderChanged3();
|
static void onCounterChanged3();
|
||||||
static void onEncoderChanged4();
|
static void onCounterChanged4();
|
||||||
static void onEncoderChanged5();
|
static void onCounterChanged5();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -111,10 +112,17 @@ protected:
|
|||||||
|
|
||||||
void dht22Poll();
|
void dht22Poll();
|
||||||
|
|
||||||
void printFloatValueToStr(float temp, char *valstr);
|
void printFloatValueToStr(float value, char *valstr);
|
||||||
|
|
||||||
void encoderPoll();
|
void counterPoll();
|
||||||
|
|
||||||
void attachInterruptPinIrq(int realPin, int irq);
|
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 <WiFi.h>
|
||||||
#include <HTTPClient.h>
|
#include <HTTPClient.h>
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
|
#include "Ethernet3.h"
|
||||||
WiFiClient ethClient;
|
WiFiClient ethClient;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -105,6 +106,14 @@ WiFiClient ethClient;
|
|||||||
EthernetClient ethClient;
|
EthernetClient ethClient;
|
||||||
#endif
|
#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;
|
lan_status lanStatus = INITIAL_STATE;
|
||||||
|
|
||||||
const char outprefix[] PROGMEM = OUTTOPIC;
|
const char outprefix[] PROGMEM = OUTTOPIC;
|
||||||
@@ -120,6 +129,7 @@ aJsonObject *mqttArr = NULL;
|
|||||||
aJsonObject *modbusArr = NULL;
|
aJsonObject *modbusArr = NULL;
|
||||||
aJsonObject *owArr = NULL;
|
aJsonObject *owArr = NULL;
|
||||||
aJsonObject *dmxArr = NULL;
|
aJsonObject *dmxArr = NULL;
|
||||||
|
aJsonObject *udpSyslogArr = NULL;
|
||||||
|
|
||||||
unsigned long nextPollingCheck = 0;
|
unsigned long nextPollingCheck = 0;
|
||||||
unsigned long nextInputCheck = 0;
|
unsigned long nextInputCheck = 0;
|
||||||
@@ -347,7 +357,24 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
|||||||
char *user = ∅
|
char *user = ∅
|
||||||
char passwordBuf[16] = "";
|
char passwordBuf[16] = "";
|
||||||
char *password = passwordBuf;
|
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)) {
|
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;
|
||||||
@@ -587,6 +614,9 @@ void cmdFunctionHelp(int arg_cnt, char **args)
|
|||||||
//(char* tokens)
|
//(char* tokens)
|
||||||
{
|
{
|
||||||
printFirmwareVersionAndBuildOptions();
|
printFirmwareVersionAndBuildOptions();
|
||||||
|
#ifndef SYSLOG_DISABLE
|
||||||
|
// udpSyslog.logf(LOG_INFO, "free RAM: %d",freeRam());
|
||||||
|
#endif
|
||||||
debugSerial.print(F(" free RAM: "));debugSerial.print(freeRam());
|
debugSerial.print(F(" free RAM: "));debugSerial.print(freeRam());
|
||||||
debugSerial.println(F(" Use the commands: 'help' - this text\n"
|
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"
|
"'mac de:ad:be:ef:fe:00' set and store MAC-address in EEPROM\n"
|
||||||
@@ -690,6 +720,7 @@ while (items && item)
|
|||||||
}
|
}
|
||||||
inputs = aJson.getObjectItem(root, "in");
|
inputs = aJson.getObjectItem(root, "in");
|
||||||
mqttArr = aJson.getObjectItem(root, "mqtt");
|
mqttArr = aJson.getObjectItem(root, "mqtt");
|
||||||
|
udpSyslogArr = aJson.getObjectItem(root, "syslog");
|
||||||
printConfigSummary();
|
printConfigSummary();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -705,6 +736,8 @@ void printConfigSummary() {
|
|||||||
printBool(mqttArr);
|
printBool(mqttArr);
|
||||||
debugSerial.print(F("1-wire "));
|
debugSerial.print(F("1-wire "));
|
||||||
printBool(owArr);
|
printBool(owArr);
|
||||||
|
debugSerial.print(F("udp syslog "));
|
||||||
|
printBool(udpSyslogArr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmdFunctionLoad(int arg_cnt, char **args) {
|
void cmdFunctionLoad(int arg_cnt, char **args) {
|
||||||
@@ -1129,6 +1162,8 @@ void setup_main() {
|
|||||||
void printFirmwareVersionAndBuildOptions() {
|
void printFirmwareVersionAndBuildOptions() {
|
||||||
debugSerial.print(F("\nLazyhome.ru LightHub controller "));
|
debugSerial.print(F("\nLazyhome.ru LightHub controller "));
|
||||||
debugSerial.println(F(QUOTE(PIO_SRC_REV)));
|
debugSerial.println(F(QUOTE(PIO_SRC_REV)));
|
||||||
|
debugSerial.print(F("C++ version:"));
|
||||||
|
debugSerial.println(F(QUOTE(__cplusplus)));
|
||||||
#ifdef CONTROLLINO
|
#ifdef CONTROLLINO
|
||||||
debugSerial.println(F("(+)CONTROLLINO"));
|
debugSerial.println(F("(+)CONTROLLINO"));
|
||||||
#endif
|
#endif
|
||||||
@@ -1274,6 +1309,12 @@ void loop_main() {
|
|||||||
#if defined (_espdmx)
|
#if defined (_espdmx)
|
||||||
dmxout.update();
|
dmxout.update();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef SYSLOG_DISABLE
|
||||||
|
// debugSerial.print(F("#"));
|
||||||
|
// udpSyslog.log(LOG_INFO, "Ping syslog:");
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void owIdle(void) {
|
void owIdle(void) {
|
||||||
|
|||||||
@@ -109,7 +109,7 @@
|
|||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <Ethernet3.h>
|
//#include <Ethernet3.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -136,13 +136,14 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DHT_POLL_DELAY_DEFAULT 15000
|
#define DHT_POLL_DELAY_DEFAULT 15000
|
||||||
|
#define UPTIME_POLL_DELAY_DEFAULT 30000
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_STM32F1
|
#ifdef ARDUINO_ARCH_STM32F1
|
||||||
#define strncpy_P strncpy
|
#define strncpy_P strncpy
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef debugSerial
|
#ifndef debugSerial
|
||||||
#define debugSerial Serial1
|
#define debugSerial Serial
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef Wiz5500
|
#ifndef Wiz5500
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ env_default =
|
|||||||
; megaatmega2560-5500
|
; megaatmega2560-5500
|
||||||
; due-5500
|
; due-5500
|
||||||
; controllino
|
; controllino
|
||||||
stm32
|
; stm32
|
||||||
|
|
||||||
build_dir = /tmp/pioenvs
|
build_dir = /tmp/pioenvs
|
||||||
libdeps_dir = /tmp/piolibdeps
|
libdeps_dir = /tmp/piolibdeps
|
||||||
@@ -48,7 +48,9 @@ lib_deps =
|
|||||||
platform = ststm32
|
platform = ststm32
|
||||||
framework = arduino
|
framework = arduino
|
||||||
board = nucleo_f103rb
|
board = nucleo_f103rb
|
||||||
upload_protocol = st-link
|
upload_protocol = stlink
|
||||||
|
debug_tool = stlink
|
||||||
|
extra_scripts = pre:!pre_stm32.sh
|
||||||
;lib_ldf_mode = chain+
|
;lib_ldf_mode = chain+
|
||||||
build_flags = !sh build_flags_stm32.sh
|
build_flags = !sh build_flags_stm32.sh
|
||||||
lib_deps =
|
lib_deps =
|
||||||
@@ -62,7 +64,11 @@ lib_deps =
|
|||||||
https://github.com/knolleary/pubsubclient.git
|
https://github.com/knolleary/pubsubclient.git
|
||||||
Adafruit Unified Sensor
|
Adafruit Unified Sensor
|
||||||
DHT sensor library
|
DHT sensor library
|
||||||
|
; https://github.com/anklimov/DMXSerial
|
||||||
|
; Syslog
|
||||||
|
; https://github.com/No3x/Syslog.git
|
||||||
|
https://github.com/arcao/Syslog.git
|
||||||
|
; UIPEthernet
|
||||||
|
|
||||||
[env:due]
|
[env:due]
|
||||||
platform = atmelsam
|
platform = atmelsam
|
||||||
@@ -88,6 +94,7 @@ lib_deps =
|
|||||||
SdFat
|
SdFat
|
||||||
Adafruit Unified Sensor
|
Adafruit Unified Sensor
|
||||||
DHT sensor library
|
DHT sensor library
|
||||||
|
https://github.com/arcao/Syslog.git
|
||||||
|
|
||||||
|
|
||||||
[env:megaatmega2560]
|
[env:megaatmega2560]
|
||||||
@@ -136,6 +143,7 @@ lib_deps =
|
|||||||
DHT sensor library for ESPx
|
DHT sensor library for ESPx
|
||||||
DHT sensor library
|
DHT sensor library
|
||||||
WifiManager
|
WifiManager
|
||||||
|
https://github.com/arcao/Syslog.git
|
||||||
|
|
||||||
[env:megaatmega2560-net]
|
[env:megaatmega2560-net]
|
||||||
platform = atmelavr
|
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