Skip to content

Commit

Permalink
pingpong
Browse files Browse the repository at this point in the history
  • Loading branch information
yuichiroaoki committed Nov 7, 2023
1 parent 7a5579b commit 161f1c5
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const char* clientId = "ESP32Client";
const char* sensorTopic = "sensor/data";
const char* controlTopic = "sensor/control";
const char* pingTopic = "sensor/ping";
const char* pongTopic = "sensor/pong";


WiFiClient espClient;
Expand Down Expand Up @@ -63,7 +64,7 @@ void callback(char* topic, byte* payload, unsigned int length) {
Serial.println(topic);
// check payload is 'ping' and send response 'pong'
if (strcmp(topic, pingTopic) == 0 && strncmp((char*)payload, "ping", 4) == 0) {
client.publish(pingTopic, "pong");
client.publish(pongTopic, "pong");
} else if (strcmp(topic, controlTopic) == 0) {
char receivedJson[200];
for (int i = 0; i < length; i++) {
Expand Down

0 comments on commit 161f1c5

Please sign in to comment.