8000 Fix response type prefix (LoadProhibitedCause) · smartcoder00/arduinoWebSockets@ccdba4e · GitHub
[go: up one dir, main page]

Skip to content

Commit ccdba4e

Browse files
Tony763Links2004
authored andcommitted
Fix response type prefix (LoadProhibitedCause)
1 parent 2b0e8f6 commit ccdba4e

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

examples/esp8266/WebSocketClientOTA/WebSocketClientOTA.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ void STATE(JsonDocument &msg){
117117
// Do something with message
118118
}
119119

120+
// Count of responses handled by RESPONSES_STRUCT
121+
// increase increase if another response handler is added
122+
int nrOfResponses = 2;
123+
120124
RESPONSES_STRUCT responses[] = {
121125
{"ota", OTA},
122126
{"state", STATE},
@@ -145,7 +149,7 @@ void text(uint8_t * payload, size_t length){
145149
// Handle each TYPE of message
146150
int b = 0;
147151

148-
for( b=0 ; strlen(responses[b].type) ; b++ )
152+
for( b=0 ; b<nrOfResponses ; b++ )
149153
{
150154
if( strncmp(doc_in["type"], responses[b].type, strlen(responses[b].type)) == 0 ) {
151155
responses[b].func(doc_in);

examples/esp8266/WebSocketClientOTA/python_ota_server/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ async def _register(websocket, message):
163163
Logger.info("Client(%s) mac: %s", name, mac)
164164
# Some code
165165

166-
response = {'response_type': 'registry', 'state': 'ok'}
166+
response = {'type': 'registry', 'state': 'ok'}
167167
await websocket.send(json.dumps(response))
168168

169169

@@ -173,13 +173,13 @@ async def _state(websocket, message):
173173
Logger.info("Client(%s) mac: %s", name, mac)
174174
# Some code
175175

176-
response = {'response_type': 'state', 'state': 'ok'}
176+
response = {'type': 'state', 'state': 'ok'}
177177
await websocket.send(json.dumps(response))
178178

179179

180180
async def _unhandleld(websocket, msg):
181181
Logger.info("Unhandled message from device: %s", str(msg))
182-
response = {'response_type': 'response', 'state': 'nok'}
182+
response = {'type': 'response', 'state': 'nok'}
183183
await websocket.send(json.dumps(response))
184184

185185

0 commit comments

Comments
 (0)
0