Skip to content

Commit efccd2c

Browse files
authored
limit swserial to esp8266
1 parent f3393a5 commit efccd2c

File tree

12 files changed

+115
-20
lines changed

12 files changed

+115
-20
lines changed

.github/workflows/build_arduino_ide.yml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ jobs:
2727
- examples/simple-write-VS1
2828
- examples/simple-write-VS2
2929
- examples/simple-read-GWG
30-
libraries: |
31-
- name: VitoWiFi
32-
source-path: ./
33-
- name: EspSoftwareSerial
34-
source-url: https://github.com/plerup/espsoftwareserial.git
30+
- examples/softwareserial
3531
3632
build-for-esp32:
3733
runs-on: ubuntu-latest
@@ -54,9 +50,4 @@ jobs:
5450
- examples/simple-read-VS2
5551
- examples/simple-write-VS1
5652
- examples/simple-write-VS2
57-
- examples/simple-read-GWG
58-
libraries: |
59-
- name: VitoWiFi
60-
source-path: ./
61-
- name: EspSoftwareSerial
62-
source-url: https://github.com/plerup/espsoftwareserial.git
53+
- examples/simple-read-GWG

.github/workflows/build_platformio.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ jobs:
1212
examples/simple-read-VS2/simple-read-VS2.ino,
1313
examples/simple-write-VS1/simple-write-VS1.ino,
1414
examples/simple-write-VS2/simple-write-VS2.ino,
15-
examples/simple-read-GWG/simple-read-GWG.ino
15+
examples/simple-read-GWG/simple-read-GWG.ino,
16+
examples/softwareserial/softwareserial.ino
1617
]
1718
steps:
1819
- uses: actions/checkout@v3
@@ -27,8 +28,6 @@ jobs:
2728
python-version: '3.9'
2829
- name: Install PlatformIO Core
2930
run: pip install --upgrade platformio
30-
- name: Download external libraries
31-
run: pio pkg install --global --library plerup/EspSoftwareSerial
3231
- name: Build PlatformIO examples
3332
run: pio ci --lib="." --board=d1_mini
3433
env:
@@ -58,8 +57,6 @@ jobs:
5857
python-version: '3.9'
5958
- name: Install PlatformIO Core
6059
run: pip install --upgrade platformio
61-
- name: Download external libraries
62-
run: pio pkg install --global --library plerup/EspSoftwareSerial
6360
- name: Build PlatformIO examples
6461
run: pio ci --lib="." --board=lolin32
6562
env:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Based on the fantastic work on [openv](https://github.com/openv/openv/wiki).
1313
- VS1 (KW) and VS2 (P300) support. Older systems using the GWG protocol are not supported
1414
- Non-blocking API calls
1515
- For the Arduino framework and POSIX systems (Linux, tested on a Raspberry Pi 1B)
16-
- Possible to use `SoftwareSerial`
16+
- Possible to use `SoftwareSerial` on ESP8266
1717

1818
## Contents
1919

@@ -254,7 +254,7 @@ Returns a pointer to the payload.
254254
##### `VitoWiFi<PROTOCOL_VERSION>(IFACE* interface)`
255255
256256
Constructor of the VitoWiFi class. `PROTOCOL_VERSION` can be `GWG`, `VS1` or `VS2`. If your Viessmann device is somewhat modern, you should use `VS2`.
257-
`interface` can be any of the `HardwareSerial` interfaces (`Serial`, `Serial1`...), `SoftwareSerial` or if you are on Linux, pass the c-string depicting your device (for example `"/dev/ttyUSB0"`).
257+
`interface` can be any of the `HardwareSerial` interfaces (`Serial`, `Serial1`...) on Arduino boards, `SoftwareSerial` (on ESP8266) or if you are on Linux, pass the c-string depicting your device (for example `"/dev/ttyUSB0"`).
258258
259259
##### `void onResponse(typename PROTOCOLVERSION::OnResponseCallback callback)`
260260
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#include <Arduino.h>
2+
3+
#include <VitoWiFi.h>
4+
#include <SoftwareSerial.h>
5+
const int sRX = 4; // software RX on D2(GPIO 4)
6+
const int sTX = 5; // software TX on D1(GPIO 5)
7+
8+
EspSoftwareSerial::UART swSer(sRX, sTX);
9+
10+
// optolink on softwareserial, logging output on hardware UART
11+
12+
VitoWiFi::VitoWiFi<VitoWiFi::VS1> vitoWiFi(&swSer);
13+
bool readValues = false;
14+
uint8_t datapointIndex = 0;
15+
16+
VitoWiFi::Datapoint datapoints[] = {
17+
VitoWiFi::Datapoint("outsidetemp", 0x5525, 2, VitoWiFi::div10),
18+
VitoWiFi::Datapoint("boilertemp", 0x0810, 2, VitoWiFi::div10),
19+
VitoWiFi::Datapoint("pump", 0x2906, 1, VitoWiFi::noconv)
20+
};
21+
22+
void onResponse(const uint8_t* data, uint8_t length, const VitoWiFi::Datapoint& request) {
23+
// raw data can be accessed through the 'response' argument
24+
Serial.print("Raw data received:");
25+
for (uint8_t i = 0; i < length; ++i) {
26+
Serial.printf(" %02x", data[i]);
27+
}
28+
Serial.print("\n");
29+
30+
// the raw data can be decoded using the datapoint. Be sure to use the correct type
31+
Serial.printf("%s: ", request.name());
32+
if (request.converter() == VitoWiFi::div10) {
33+
float value = request.decode(data, length);
34+
Serial.printf("%.1f\n", value);
35+
} else if (request.converter() == VitoWiFi::noconv) {
36+
// in this example, the response is one byte
37+
Serial.printf("%s\n", (data[0] > 0) ? "ON" : "OFF");
38+
}
39+
}
40+
41+
void onError(VitoWiFi::OptolinkResult error, const VitoWiFi::Datapoint& request) {
42+
Serial.printf("Datapoint \"%s\" error: ", request.name());
43+
if (error == VitoWiFi::OptolinkResult::TIMEOUT) {
44+
Serial.print("timeout\n");
45+
} else if (error == VitoWiFi::OptolinkResult::LENGTH) {
46+
Serial.print("length\n");
47+
} else if (error == VitoWiFi::OptolinkResult::NACK) {
48+
Serial.print("nack\n");
49+
} else if (error == VitoWiFi::OptolinkResult::CRC) {
50+
Serial.print("crc\n");
51+
} else if (error == VitoWiFi::OptolinkResult::ERROR) {
52+
Serial.print("error\n");
53+
}
54+
}
55+
56+
void setup() {
57+
delay(1000);
58+
Serial.begin(74880);
59+
Serial.print("Setting up vitoWiFi\n");
60+
61+
vitoWiFi.onResponse(onResponse);
62+
vitoWiFi.onError(onError);
63+
vitoWiFi.begin();
64+
65+
Serial.print("Setup finished\n");
66+
}
67+
68+
void loop() {
69+
static uint32_t lastMillis = 0;
70+
if (millis() - lastMillis > 60000UL) { // read all values every 60 seconds
71+
lastMillis = millis();
72+
readValues = true;
73+
datapointIndex = 0;
74+
}
75+
76+
if (readValues) {
77+
if (vitoWiFi.read(datapoints[datapointIndex])) {
78+
++datapointIndex;
79+
}
80+
if (datapointIndex == 3) {
81+
readValues = false;
82+
}
83+
}
84+
85+
vitoWiFi.loop();
86+
}

src/GWG/GWG.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ GWG::GWG(HardwareSerial* interface)
3737
}
3838
}
3939

40+
#if defined(ARDUINO_ARCH_ESP8266)
4041
GWG::GWG(SoftwareSerial* interface)
4142
: _state(State::UNDEFINED)
4243
, _currentMillis(vw_millis())
@@ -62,6 +63,8 @@ GWG::GWG(SoftwareSerial* interface)
6263
vw_abort();
6364
}
6465
}
66+
#endif
67+
6568
#else
6669
GWG::GWG(const char* interface)
6770
: _state(State::UNDEFINED)

src/GWG/GWG.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ the LICENSE file.
1717
#include "../Datapoint/Datapoint.h"
1818
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
1919
#include "../Interface/HardwareSerialInterface.h"
20+
#if defined(ARDUINO_ARCH_ESP8266)
2021
#include "../Interface/SoftwareSerialInterface.h"
22+
#endif
2123
#elif defined(__linux__)
2224
#include "../Interface/LinuxSerialInterface.h"
2325
#else
@@ -33,7 +35,9 @@ class GWG {
3335

3436
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
3537
explicit GWG(HardwareSerial* interface);
38+
#if defined(ARDUINO_ARCH_ESP8266)
3639
explicit GWG(SoftwareSerial* interface);
40+
#endif
3741
#else
3842
explicit GWG(const char* interface);
3943
#endif

src/Interface/SoftwareSerialInterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ For a copy, see <https://opensource.org/licenses/MIT> or
66
the LICENSE file.
77
*/
88

9-
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
9+
#if defined(ARDUINO_ARCH_ESP8266)
1010

1111
#include "SoftwareSerialInterface.h"
1212

src/Interface/SoftwareSerialInterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ the LICENSE file.
88

99
#pragma once
1010

11-
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
11+
#if defined(ARDUINO_ARCH_ESP8266)
1212

1313
#include <cassert>
1414

src/VS1/VS1.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ VS1::VS1(HardwareSerial* interface)
3737
}
3838
}
3939

40+
#if defined(ARDUINO_ARCH_ESP8266)
4041
VS1::VS1(SoftwareSerial* interface)
4142
: _state(State::UNDEFINED)
4243
, _currentMillis(vw_millis())
@@ -62,6 +63,8 @@ VS1::VS1(SoftwareSerial* interface)
6263
vw_abort();
6364
}
6465
}
66+
#endif
67+
6568
#else
6669
VS1::VS1(const char* interface)
6770
: _state(State::UNDEFINED)

src/VS1/VS1.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ the LICENSE file.
1717
#include "../Datapoint/Datapoint.h"
1818
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
1919
#include "../Interface/HardwareSerialInterface.h"
20+
#if defined(ARDUINO_ARCH_ESP8266)
2021
#include "../Interface/SoftwareSerialInterface.h"
22+
#endif
2123
#elif defined(__linux__)
2224
#include "../Interface/LinuxSerialInterface.h"
2325
#else
@@ -33,7 +35,9 @@ class VS1 {
3335

3436
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
3537
explicit VS1(HardwareSerial* interface);
38+
#if defined(ARDUINO_ARCH_ESP8266)
3639
explicit VS1(SoftwareSerial* interface);
40+
#endif
3741
#else
3842
explicit VS1(const char* interface);
3943
#endif

0 commit comments

Comments
 (0)