start mqtt client (based on paho.mqtt.c), basically works
This commit is contained in:
25
main.cpp
25
main.cpp
@@ -3,6 +3,7 @@
|
||||
#include "pidigest.h"
|
||||
#include "pihttpclient.h"
|
||||
#include "piliterals.h"
|
||||
#include "pimqttclient.h"
|
||||
#include "pip.h"
|
||||
#include "piunits.h"
|
||||
#include "pivaluetree_conversions.h"
|
||||
@@ -18,8 +19,32 @@ inline PIByteArray SMBusTypeInfo_genHash(PIString n) {
|
||||
return piSerialize(c.shorthash(n.removeAll(" "), PIString("SMBusDataHashKey").toByteArray()));
|
||||
}
|
||||
|
||||
PIKbdListener kbd;
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
PIMQTT::Client cl;
|
||||
cl.setConnectTimeout(2_s);
|
||||
CONNECTL(&cl, connected, [&cl] {
|
||||
piCout << "connected";
|
||||
cl.subscribe("/zigbee2mqtt");
|
||||
cl.subscribe("/zigbee2mqtt/+");
|
||||
cl.unsubscribe("/zigbee2mqtt");
|
||||
cl.publish("/zigbee2mqtt/abc", "hello from PIP"_a.toAscii());
|
||||
});
|
||||
CONNECTL(&cl, disconnected, [&cl](PIMQTT::Error code) {
|
||||
piCout << "disconnected code" << (int)code;
|
||||
cl.connect("localhost", "PIP");
|
||||
});
|
||||
CONNECTL(&cl, received, [](const PIMQTT::Message & message) { piCout << "received" << message.topic << message.payload.size(); });
|
||||
|
||||
cl.connect("localhost", "PIP");
|
||||
|
||||
kbd.enableExitCapture('Q');
|
||||
WAIT_FOR_EXIT
|
||||
|
||||
piCout << "exiting ...";
|
||||
return 0;
|
||||
|
||||
PICrypt _crypt;
|
||||
// auto ba = PIFile::readAll("logo.png");
|
||||
PIString str = "hello!"_a;
|
||||
|
||||
Reference in New Issue
Block a user