Skip to content

Commit e62fdc6

Browse files
committed
rename + count topic
1 parent fda888a commit e62fdc6

File tree

8 files changed

+51
-32
lines changed

8 files changed

+51
-32
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
.piolibdeps
22
.pioenvs
3-
EthernetRelayTemp/settings.h
3+
ethernet_relay_temp/settings.h

.travis.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
language: python
2+
python:
3+
- "2.7"
4+
5+
sudo: false
6+
cache:
7+
directories:
8+
- "~/.platformio"
9+
10+
install:
11+
- pip install -U platformio
12+
- platformio update
13+
14+
script:
15+
- platformio run
16+
17+
notifications:
18+
email:
19+
on_success: change
20+
on_failure: change
File renamed without changes.

EthernetRelayTemp/settings.example.h renamed to ethernet_relay_temp/settings.example.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define MQTT_TOPIC_ANALOG_TEMP MQTT_BASE_TOPIC"/atemp" // will result ie. someName/atemp/* where aterisk is temp index
1515
#define MQTT_TOPIC_WILL MQTT_BASE_TOPIC"/status"
1616
#define MQTT_TOPIC_ERROR MQTT_BASE_TOPIC"/err"
17+
#define MQTT_TOPIC_COUNT MQTT_BASE_TOPIC"/count"
1718
#define MQTT_STATUS_ON "1"
1819
#define MQTT_STATUS_OFF "0"
1920
#define MQTT_RELAY_TOPIC_STATE MQTT_BASE_TOPIC"/relay/0" // will result ie. someName/relay/0
@@ -30,7 +31,7 @@
3031
#define RELAY_PIN PA0
3132
#define ONE_WIRE_PIN PB9
3233
#define ETH_RST_PIN PB0
33-
#define ANALOG_TEMPS 2
34+
#define ANALOG_TEMPS 1
3435
#define TEMPERATURE_PRECISION 11
3536
const int a_temp_pin[ANALOG_TEMPS] = {PB1, PA1};
3637
#define RELAY_PIN PA0

EthernetRelayTemp/temp.h renamed to ethernet_relay_temp/temp.h

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ const char * hex = "0123456789ABCDEF";
1818
uint8_t ds12b20_count = 0;
1919

2020
void tempSetup() {
21-
bool error = false;
22-
2321
for (uint8_t i = 0; i < ANALOG_TEMPS; i++) {
2422
pinMode(a_temp_pin[i], INPUT_ANALOG);
2523
aHysteresis[i].set(10);
@@ -37,18 +35,12 @@ void tempSetup() {
3735

3836
ds12b20_count = (ds12b20_count > MAX_DS18B20 ? MAX_DS18B20 : ds12b20_count); // prevent overflow
3937

40-
if (ds12b20_count == 0) {
41-
#if defined(ENABLE_DEBUG)
42-
debugPort.println("Sending message: error, no dallas devices");
43-
#endif
44-
45-
char data[2];
46-
data[0] = MAX_DS18B20 + '0';
47-
data[1] = 0;
48-
sendData(MQTT_TOPIC_ERROR, data, true);
49-
error = true;
38+
char data[2];
39+
data[0] = ds12b20_count + '0';
40+
data[1] = 0;
41+
sendData(MQTT_TOPIC_COUNT, data, true);
5042

51-
} else {
43+
if (ds12b20_count != 0) {
5244
for (uint8_t i = 0; i < ds12b20_count; i++) {
5345
dHysteresis[i].set(10);
5446
dHysteresis[i].prev(LONG_MIN);
@@ -67,8 +59,6 @@ void tempSetup() {
6759
data[1] = i + '0';
6860
data[2] = 0;
6961
sendData(MQTT_TOPIC_ERROR, data, true);
70-
error = true;
71-
7262

7363
#if defined(ENABLE_DEBUG)
7464
debugPort.print("Sending message: Dallas ");
@@ -80,17 +70,6 @@ void tempSetup() {
8070
iwdg_feed();
8171
}
8272
}
83-
84-
if (!error) {
85-
#if defined(ENABLE_DEBUG)
86-
debugPort.println("Sending message: no error");
87-
#endif
88-
89-
char data[2];
90-
data[0] = ds12b20_count + '0';
91-
data[1] = 0;
92-
sendData(MQTT_TOPIC_ERROR, data, true);
93-
}
9473
}
9574

9675
void readTemp() {
@@ -113,7 +92,14 @@ void readTemp() {
11392
debugPort.println(tempC, 3);
11493
#endif
11594

116-
dHysteresis[i].add(dAverage[i].add(static_cast<int32_t>(tempC * 100)));
95+
if (tempC != -127.0) {
96+
dHysteresis[i].add(dAverage[i].add(static_cast<int32_t>(tempC * 100)));
97+
98+
} else {
99+
dHysteresis[i].prev(LONG_MIN);
100+
dAverage[i].reset();
101+
}
102+
117103
iwdg_feed();
118104
}
119105

File renamed without changes.

platformio.ini

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[platformio]
2-
env_default = mqtt_temp_relay_v1
3-
src_dir = EthernetRelayTemp
2+
env_default = ethernet-relay-temp-v1-debug
3+
src_dir = ethernet_relay_temp
44

5-
[env:mqtt_temp_relay_v1]
5+
[env:ethernet-relay-temp-v1-debug]
66
platform = ststm32
77
board = genericSTM32F103C8
88
framework = arduino
@@ -14,3 +14,15 @@ lib_deps =
1414
DallasTemperature
1515
PubSubClient
1616
UIPEthernet
17+
18+
[env:ethernet-relay-temp-v1]
19+
platform = ststm32
20+
board = genericSTM32F103C8
21+
framework = arduino
22+
upload_protocol = stlink
23+
lib_deps =
24+
MovingAverage
25+
https://github.com/pilotak/Hysteresis
26+
DallasTemperature
27+
PubSubClient
28+
UIPEthernet

0 commit comments

Comments
 (0)