Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add GWG #98

Merged
merged 5 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build_arduino_ide.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
- examples/simple-read-VS2
- examples/simple-write-VS1
- examples/simple-write-VS2
- examples/simple-read-GWG
libraries: |
- name: VitoWiFi
source-path: ./
Expand Down Expand Up @@ -53,6 +54,7 @@ jobs:
- examples/simple-read-VS2
- examples/simple-write-VS1
- examples/simple-write-VS2
- examples/simple-read-GWG
libraries: |
- name: VitoWiFi
source-path: ./
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/build_platformio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ jobs:
examples/simple-read-VS1/simple-read-VS1.ino,
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-write-VS2/simple-write-VS2.ino,
examples/simple-read-GWG/simple-read-GWG.ino
]
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -41,7 +42,8 @@ jobs:
examples/simple-read-VS1/simple-read-VS1.ino,
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-write-VS2/simple-write-VS2.ino,
examples/simple-read-GWG/simple-read-GWG.ino
]
steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ In the table below you can find how to define your datapoints:
|---|---|---|---|---|
|Temperature|2|div10|float||
|Temperature short|1|noconv|uint8_t|equivalent to Mode|
|Power|1|div2|float||
|Power|1|div2|float|also used for temperature in GWG|
|Status|1|noconv|bool|this is the same as 'Temperature short' and 'Mode'. The `uint8_t` value will be implicitely converted to bool.|
|Hours|4|div3600|float|this is in fact a `Count` datapoint (seconds) converted to hours.|
|Count|4|noconv|uint32_t||
Expand Down Expand Up @@ -253,7 +253,7 @@ Returns a pointer to the payload.

##### `VitoWiFi<PROTOCOL_VERSION>(IFACE* interface)`

Constructor of the VitoWiFi class. `PROTOCOL_VERSION` can be `VS1` or `VS2`. If your Viessmann device is somewhat modern, you should use `VS2`.
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"`).

##### `void onResponse(typename PROTOCOLVERSION::OnResponseCallback callback)`
Expand Down
81 changes: 81 additions & 0 deletions examples/simple-read-GWG/simple-read-GWG.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include <Arduino.h>

#include <VitoWiFi.h>

#if defined(ARDUINO_ARCH_ESP8266)
// optolink on full UART, logging output on secondary
#define SERIAL1 Serial
#define SERIAL2 Serial1
#define SERIALBAUDRATE 74880
#elif defined(ARDUINO_ARCH_ESP32)
// optolink on UART2, logging output on UART1 (connected to USB)
#define SERIAL1 Serial1
#define SERIAL2 Serial
#define SERIALBAUDRATE 115200
#endif

#ifndef SERIALBAUDRATE
#error Target platform not supported
#endif

VitoWiFi::VitoWiFi<VitoWiFi::GWG> vitoWiFi(&SERIAL1);
ssize_t datapointIndex = -1;
constexpr size_t numberDatapoints = 1;
VitoWiFi::Datapoint datapoints[] = {
VitoWiFi::Datapoint("temp", 0x6F, 1, VitoWiFi::div2),
};


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

// the raw data can be decoded using the datapoint. Be sure to use the correct type
SERIAL2.printf("%s: ", request.name());
if (request.converter() == VitoWiFi::div2) {
float value = request.decode(data, length);
SERIAL2.printf("%.1f\n", value);
}
}

void onError(VitoWiFi::OptolinkResult error, const VitoWiFi::Datapoint& request) {
SERIAL2.printf("Datapoint \"%s\" error: ", request.name());
if (error == VitoWiFi::OptolinkResult::TIMEOUT) {
SERIAL2.print("timeout\n");
}
}

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

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

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

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

if (datapointIndex >= 0) {
if (vitoWiFi.read(datapoints[datapointIndex])) {
++datapointIndex;
}
if (datapointIndex == numberDatapoints) {
datapointIndex = -1;
}
}

vitoWiFi.loop();
}
15 changes: 13 additions & 2 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ encode KEYWORD2

#PacketVS2 public methods
createPacket KEYWORD2
#setLength KEYWORD2
length KEYWORD2
packetType KEYWORD2
functionCode KEYWORD2
Expand All @@ -42,8 +41,20 @@ checksum KEYWORD2
# Constants (LITERAL1)
#######################################

#Protocols
GWG LITERAL1
VS1 LITERAL1
VS2 LITERAL1

#Enums
TIMEOUT LITERAL1
LENGTH LITERAL1
NACK LITERAL1
CRC LITERAL1
ERROR LITERAL1

#Transformation
div2 LITERAL2
div10 LITERAL2
div3600 LITERAL2
noconv LITERAL2
raw LITERAL2
5 changes: 5 additions & 0 deletions src/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ constexpr struct {
uint8_t WRITE = 0xF4;
} PacketVS1Type;

constexpr struct {
uint8_t READ = 0xCB;
uint8_t WRITE = 0xC8;
} PacketGWGType;

enum class OptolinkResult {
CONTINUE,
PACKET,
Expand Down
17 changes: 17 additions & 0 deletions src/Datapoint/Converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ void Div10Convert::encode(uint8_t* buf, uint8_t len, const VariantValue& val) co
buf[0] = tmp & 0xFF;
}

VariantValue Div2Convert::decode(const uint8_t* data, uint8_t len) const {
assert(len == 1);
float retVal = 0;
int8_t val = data[0];
retVal = val / 2.f;
return VariantValue(retVal);
}

void Div2Convert::encode(uint8_t* buf, uint8_t len, const VariantValue& val) const {
assert(len == 1);
(void) len;
float srcVal = val;
int8_t tmp = floor((srcVal * 2.f) + 0.5);
buf[0] = tmp;
}

VariantValue Div3600Convert::decode(const uint8_t* data, uint8_t len) const {
assert(len == 4);
(void) len;
Expand Down Expand Up @@ -94,6 +110,7 @@ void NoconvConvert::encode(uint8_t* buf, uint8_t len, const VariantValue& val) c
}

Div10Convert div10;
Div2Convert div2;
Div3600Convert div3600;
NoconvConvert noconv;

Expand Down
7 changes: 7 additions & 0 deletions src/Datapoint/Converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ class Div10Convert : public Converter {
void encode(uint8_t* buf, uint8_t len, const VariantValue& val) const override;
};

class Div2Convert : public Converter {
public:
VariantValue decode(const uint8_t* data, uint8_t len) const override;
void encode(uint8_t* buf, uint8_t len, const VariantValue& val) const override;
};

class Div3600Convert : public Converter {
public:
VariantValue decode(const uint8_t* data, uint8_t len) const override;
Expand All @@ -75,6 +81,7 @@ class NoconvConvert : public Converter {
};

extern Div10Convert div10;
extern Div2Convert div2;
extern Div3600Convert div3600;
extern NoconvConvert noconv;

Expand Down
Loading
Loading