-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
531 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#include <signal.h> | ||
#include <iostream> | ||
#include <iomanip> | ||
#include <thread> | ||
#include <chrono> // is already included by VitoWiFi | ||
#include <VitoWiFi.h> | ||
|
||
VitoWiFi::VitoWiFi<VitoWiFi::VS2> vitoWiFi("/dev/ttyUSB0"); | ||
|
||
bool exitProgram = false; | ||
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 signalHandler(int signum) { | ||
std::cout << "Caught signal " << signum << std::endl; | ||
exitProgram = true; | ||
} | ||
|
||
void onResponse(const VitoWiFi::PacketVS2& response, const VitoWiFi::Datapoint& request) { | ||
// raw data can be accessed through the 'response' argument | ||
std::cout << "Raw data received: " << std::endl; | ||
const uint8_t* data = response.data(); | ||
for (uint8_t i = 0; i < response.dataLength(); ++i) { | ||
std::cout << std::hex << (int)data[i] << " "; | ||
} | ||
std::cout << std::endl; | ||
|
||
// the raw data can be decoded using the datapoint. Be sure to use the correct type | ||
std::cout << request.name() <<": "; | ||
if (request.converter() == VitoWiFi::div10) { | ||
float value = request.decode(response); | ||
std::cout << std::setprecision(2) << value << std::endl; | ||
} else if (request.converter() == VitoWiFi::noconv) { | ||
bool value = request.decode(response); | ||
if (value) { | ||
std::cout << "ON" << std::endl; | ||
} else { | ||
std::cout << "OFF" << std::endl; | ||
} | ||
// alternatively, we can just cast response.data()[0] to bool | ||
} | ||
} | ||
|
||
void onError(VitoWiFi::OptolinkResult error, const VitoWiFi::Datapoint& request) { | ||
printf("Datapoint \"%s\" error: ", request.name()); | ||
if (error == VitoWiFi::OptolinkResult::TIMEOUT) { | ||
std::cout << "timeout" << std::endl; | ||
} else if (error == VitoWiFi::OptolinkResult::LENGTH) { | ||
std::cout << "length" << std::endl; | ||
} else if (error == VitoWiFi::OptolinkResult::NACK) { | ||
std::cout << "nack" << std::endl; | ||
} else if (error == VitoWiFi::OptolinkResult::CRC) { | ||
std::cout << "crc" << std::endl; | ||
} else if (error == VitoWiFi::OptolinkResult::ERROR) { | ||
std::cout << "error" << std::endl; | ||
} | ||
} | ||
|
||
void setup() { | ||
sleep(2); | ||
std::cout << "Setting up vitoWiFi" << std::endl; | ||
|
||
vitoWiFi.onResponse(onResponse); | ||
vitoWiFi.onError(onError); | ||
vitoWiFi.begin(); | ||
|
||
std::cout << "Setup finished" << std::endl; | ||
} | ||
|
||
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(); | ||
} | ||
|
||
|
||
int main() { | ||
setup(); | ||
while(1) { | ||
loop(); | ||
std::this_thread::sleep_for(std::chrono::milliseconds(100)); | ||
if (exitProgram) break; | ||
} | ||
vitoWiFi.end(); | ||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[common] | ||
build_flags = | ||
-std=c++11 | ||
-Wall | ||
-Wextra | ||
-Werror | ||
|
||
[env:native] | ||
platform = native | ||
build_flags = | ||
${common.build_flags} | ||
build_type = debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,38 @@ | ||
{ | ||
"name": "VitoWiFi", | ||
"version": "3.0.0", | ||
"keywords": "iot, home, automation, Arduino, esp8266, esp32, Viessmann, serial, optolink", | ||
"description": "Communicate with Viessmann boilers using the optolink for ESP8266 and ESP32", | ||
"homepage": "https://github.com/bertmelis/VitoWiFi", | ||
"license": "MIT", | ||
"authors": { | ||
"name": "Bert Melis", | ||
"url": "https://github.com/bertmelis", | ||
"maintainer": true | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/bertmelis/VitoWiFi.git", | ||
"branch": "master" | ||
}, | ||
"frameworks": "arduino", | ||
"platforms": [ | ||
"espressif8266", | ||
"espressif32" | ||
], | ||
"dependencies": [ | ||
{ | ||
"owner": "plerup", | ||
"name": "EspSoftwareSerial", | ||
"version": ">=1.2.2", | ||
"platforms": [ | ||
"espressif8266", | ||
"espressif32" | ||
] | ||
} | ||
] | ||
} | ||
"name": "VitoWiFi", | ||
"version": "3.0.0", | ||
"keywords": "iot, home, automation, Arduino, esp8266, esp32, Viessmann, serial, optolink", | ||
"description": "Communicate with Viessmann boilers using the optolink for ESP8266 and ESP32", | ||
"homepage": "https://github.com/bertmelis/VitoWiFi", | ||
"license": "MIT", | ||
"authors": { | ||
"name": "Bert Melis", | ||
"url": "https://github.com/bertmelis", | ||
"maintainer": true | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/bertmelis/VitoWiFi.git", | ||
"branch": "master" | ||
}, | ||
"frameworks": [ | ||
"arduino", | ||
"*" | ||
], | ||
"platforms": [ | ||
"espressif8266", | ||
"espressif32", | ||
"native" | ||
], | ||
"dependencies": [ | ||
{ | ||
"owner": "plerup", | ||
"name": "EspSoftwareSerial", | ||
"version": ">=1.2.2", | ||
"platforms": [ | ||
"espressif8266", | ||
"espressif32" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.