diff --git a/main.cpp b/main.cpp index 94fdaca..595fe25 100644 --- a/main.cpp +++ b/main.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include @@ -11,10 +10,9 @@ #include "Socket.h" #include "spa/support/loop.h" - #define BUFFER_SIZE 2048 -#define SENSOR_STRING "bcst: SENSOR TYPE: 254 ID: " +#define MSG_STRING "MSG JSON LEN " struct PwlPriv { @@ -46,12 +44,11 @@ static void send_sensor(TCPSocket* socket, uint8_t id, bool state) lastState = state; - std::string sendbuf(SENSOR_STRING); - sendbuf.append(std::to_string(static_cast(id))); - sendbuf.append(" FIELD: "); - sendbuf.append(std::to_string(static_cast(state))); - sendbuf.push_back('\n'); - Log(Log::DEBUG, false)<(id)) + ", "); + json.append("\"Field\":" + std::to_string(static_cast(state))); + json.append(" }\n"); + std::string sendbuf(MSG_STRING + std::to_string(json.length()) + "\n" + json); socket->send(sendbuf.c_str(), sendbuf.size()); } @@ -140,7 +137,6 @@ static void node_event_info(void* data, const struct pw_node_info *info) prev_state = info->state; Log(Log::INFO)<<"node "<id<<" is in state "<state); - std::string sendbuf(SENSOR_STRING); switch(info->state) { case PW_NODE_STATE_RUNNING: diff --git a/options.h b/options.h index cf4549d..17ad853 100644 --- a/options.h +++ b/options.h @@ -29,7 +29,7 @@ struct Config std::string sink_name; bool use_active = false; std::string host = "localhost"; - unsigned short port = 6856; + unsigned short port = 38940; uint8_t id = 0; unsigned int timeout = 60; };