Skip to content

Commit

Permalink
limit swserial to esp8266
Browse files Browse the repository at this point in the history
  • Loading branch information
bertmelis authored Sep 24, 2024
1 parent f3393a5 commit efccd2c
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 20 deletions.
13 changes: 2 additions & 11 deletions .github/workflows/build_arduino_ide.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ jobs:
- examples/simple-write-VS1
- examples/simple-write-VS2
- examples/simple-read-GWG
libraries: |
- name: VitoWiFi
source-path: ./
- name: EspSoftwareSerial
source-url: https://github.com/plerup/espsoftwareserial.git
- examples/softwareserial
build-for-esp32:
runs-on: ubuntu-latest
Expand All @@ -54,9 +50,4 @@ jobs:
- examples/simple-read-VS2
- examples/simple-write-VS1
- examples/simple-write-VS2
- examples/simple-read-GWG
libraries: |
- name: VitoWiFi
source-path: ./
- name: EspSoftwareSerial
source-url: https://github.com/plerup/espsoftwareserial.git
- examples/simple-read-GWG
7 changes: 2 additions & 5 deletions .github/workflows/build_platformio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ jobs:
examples/simple-read-VS2/simple-read-VS2.ino,
examples/simple-write-VS1/simple-write-VS1.ino,
examples/simple-write-VS2/simple-write-VS2.ino,
examples/simple-read-GWG/simple-read-GWG.ino
examples/simple-read-GWG/simple-read-GWG.ino,
examples/softwareserial/softwareserial.ino
]
steps:
- uses: actions/checkout@v3
Expand All @@ -27,8 +28,6 @@ jobs:
python-version: '3.9'
- name: Install PlatformIO Core
run: pip install --upgrade platformio
- name: Download external libraries
run: pio pkg install --global --library plerup/EspSoftwareSerial
- name: Build PlatformIO examples
run: pio ci --lib="." --board=d1_mini
env:
Expand Down Expand Up @@ -58,8 +57,6 @@ jobs:
python-version: '3.9'
- name: Install PlatformIO Core
run: pip install --upgrade platformio
- name: Download external libraries
run: pio pkg install --global --library plerup/EspSoftwareSerial
- name: Build PlatformIO examples
run: pio ci --lib="." --board=lolin32
env:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Based on the fantastic work on [openv](https://github.com/openv/openv/wiki).
- VS1 (KW) and VS2 (P300) support. Older systems using the GWG protocol are not supported
- Non-blocking API calls
- For the Arduino framework and POSIX systems (Linux, tested on a Raspberry Pi 1B)
- Possible to use `SoftwareSerial`
- Possible to use `SoftwareSerial` on ESP8266

## Contents

Expand Down Expand Up @@ -254,7 +254,7 @@ Returns a pointer to the payload.
##### `VitoWiFi<PROTOCOL_VERSION>(IFACE* interface)`
Constructor of the VitoWiFi class. `PROTOCOL_VERSION` can be `GWG`, `VS1` or `VS2`. If your Viessmann device is somewhat modern, you should use `VS2`.
`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"`).
`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"`).
##### `void onResponse(typename PROTOCOLVERSION::OnResponseCallback callback)`
Expand Down
86 changes: 86 additions & 0 deletions examples/softwareserial/softwareserial.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include <Arduino.h>

#include <VitoWiFi.h>
#include <SoftwareSerial.h>
const int sRX = 4; // software RX on D2(GPIO 4)
const int sTX = 5; // software TX on D1(GPIO 5)

EspSoftwareSerial::UART swSer(sRX, sTX);

// optolink on softwareserial, logging output on hardware UART

VitoWiFi::VitoWiFi<VitoWiFi::VS1> vitoWiFi(&swSer);
bool readValues = false;
uint8_t datapointIndex = 0;

VitoWiFi::Datapoint datapoints[] = {
VitoWiFi::Datapoint("outsidetemp", 0x5525, 2, VitoWiFi::div10),
VitoWiFi::Datapoint("boilertemp", 0x0810, 2, VitoWiFi::div10),
VitoWiFi::Datapoint("pump", 0x2906, 1, VitoWiFi::noconv)
};

void onResponse(const uint8_t* data, uint8_t length, const VitoWiFi::Datapoint& request) {
// raw data can be accessed through the 'response' argument
Serial.print("Raw data received:");
for (uint8_t i = 0; i < length; ++i) {
Serial.printf(" %02x", data[i]);
}
Serial.print("\n");

// the raw data can be decoded using the datapoint. Be sure to use the correct type
Serial.printf("%s: ", request.name());
if (request.converter() == VitoWiFi::div10) {
float value = request.decode(data, length);
Serial.printf("%.1f\n", value);
} else if (request.converter() == VitoWiFi::noconv) {
// in this example, the response is one byte
Serial.printf("%s\n", (data[0] > 0) ? "ON" : "OFF");
}
}

void onError(VitoWiFi::OptolinkResult error, const VitoWiFi::Datapoint& request) {
Serial.printf("Datapoint \"%s\" error: ", request.name());
if (error == VitoWiFi::OptolinkResult::TIMEOUT) {
Serial.print("timeout\n");
} else if (error == VitoWiFi::OptolinkResult::LENGTH) {
Serial.print("length\n");
} else if (error == VitoWiFi::OptolinkResult::NACK) {
Serial.print("nack\n");
} else if (error == VitoWiFi::OptolinkResult::CRC) {
Serial.print("crc\n");
} else if (error == VitoWiFi::OptolinkResult::ERROR) {
Serial.print("error\n");
}
}

void setup() {
delay(1000);
Serial.begin(74880);
Serial.print("Setting up vitoWiFi\n");

vitoWiFi.onResponse(onResponse);
vitoWiFi.onError(onError);
vitoWiFi.begin();

Serial.print("Setup finished\n");
}

void loop() {
static uint32_t lastMillis = 0;
if (millis() - lastMillis > 60000UL) { // read all values every 60 seconds
lastMillis = millis();
readValues = true;
datapointIndex = 0;
}

if (readValues) {
if (vitoWiFi.read(datapoints[datapointIndex])) {
++datapointIndex;
}
if (datapointIndex == 3) {
readValues = false;
}
}

vitoWiFi.loop();
}
3 changes: 3 additions & 0 deletions src/GWG/GWG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ GWG::GWG(HardwareSerial* interface)
}
}

#if defined(ARDUINO_ARCH_ESP8266)
GWG::GWG(SoftwareSerial* interface)
: _state(State::UNDEFINED)
, _currentMillis(vw_millis())
Expand All @@ -62,6 +63,8 @@ GWG::GWG(SoftwareSerial* interface)
vw_abort();
}
}
#endif

#else
GWG::GWG(const char* interface)
: _state(State::UNDEFINED)
Expand Down
4 changes: 4 additions & 0 deletions src/GWG/GWG.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ the LICENSE file.
#include "../Datapoint/Datapoint.h"
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
#include "../Interface/HardwareSerialInterface.h"
#if defined(ARDUINO_ARCH_ESP8266)
#include "../Interface/SoftwareSerialInterface.h"
#endif
#elif defined(__linux__)
#include "../Interface/LinuxSerialInterface.h"
#else
Expand All @@ -33,7 +35,9 @@ class GWG {

#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
explicit GWG(HardwareSerial* interface);
#if defined(ARDUINO_ARCH_ESP8266)
explicit GWG(SoftwareSerial* interface);
#endif
#else
explicit GWG(const char* interface);
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/Interface/SoftwareSerialInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ For a copy, see <https://opensource.org/licenses/MIT> or
the LICENSE file.
*/

#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
#if defined(ARDUINO_ARCH_ESP8266)

#include "SoftwareSerialInterface.h"

Expand Down
2 changes: 1 addition & 1 deletion src/Interface/SoftwareSerialInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ the LICENSE file.

#pragma once

#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
#if defined(ARDUINO_ARCH_ESP8266)

#include <cassert>

Expand Down
3 changes: 3 additions & 0 deletions src/VS1/VS1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ VS1::VS1(HardwareSerial* interface)
}
}

#if defined(ARDUINO_ARCH_ESP8266)
VS1::VS1(SoftwareSerial* interface)
: _state(State::UNDEFINED)
, _currentMillis(vw_millis())
Expand All @@ -62,6 +63,8 @@ VS1::VS1(SoftwareSerial* interface)
vw_abort();
}
}
#endif

#else
VS1::VS1(const char* interface)
: _state(State::UNDEFINED)
Expand Down
4 changes: 4 additions & 0 deletions src/VS1/VS1.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ the LICENSE file.
#include "../Datapoint/Datapoint.h"
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
#include "../Interface/HardwareSerialInterface.h"
#if defined(ARDUINO_ARCH_ESP8266)
#include "../Interface/SoftwareSerialInterface.h"
#endif
#elif defined(__linux__)
#include "../Interface/LinuxSerialInterface.h"
#else
Expand All @@ -33,7 +35,9 @@ class VS1 {

#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
explicit VS1(HardwareSerial* interface);
#if defined(ARDUINO_ARCH_ESP8266)
explicit VS1(SoftwareSerial* interface);
#endif
#else
explicit VS1(const char* interface);
#endif
Expand Down
3 changes: 3 additions & 0 deletions src/VS2/VS2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ VS2::VS2(HardwareSerial* interface)
}
}

#if defined(ARDUINO_ARCH_ESP8266)
VS2::VS2(SoftwareSerial* interface)
: _state(State::UNDEFINED)
, _currentMillis(vw_millis())
Expand All @@ -50,6 +51,8 @@ VS2::VS2(SoftwareSerial* interface)
vw_abort();
}
}
#endif

#else
VS2::VS2(const char* interface)
: _state(State::UNDEFINED)
Expand Down
4 changes: 4 additions & 0 deletions src/VS2/VS2.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ the LICENSE file.
#include "../Datapoint/Datapoint.h"
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
#include "../Interface/HardwareSerialInterface.h"
#if defined(ARDUINO_ARCH_ESP8266)
#include "../Interface/SoftwareSerialInterface.h"
#endif
#elif defined(__linux__)
#include "../Interface/LinuxSerialInterface.h"
#else
Expand All @@ -33,7 +35,9 @@ class VS2 {

#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
explicit VS2(HardwareSerial* interface);
#if defined(ARDUINO_ARCH_ESP8266)
explicit VS2(SoftwareSerial* interface);
#endif
#else
explicit VS2(const char* interface);
#endif
Expand Down

0 comments on commit efccd2c

Please sign in to comment.