Fix response type prefix (LoadProhibitedCause)

This commit is contained in:
Antonín Skala
2022-08-22 12:28:53 +02:00
committed by Markus
parent 2b0e8f6fe9
commit ccdba4ed8a
2 changed files with 8 additions and 4 deletions

View File

@ -117,6 +117,10 @@ void STATE(JsonDocument &msg){
// Do something with message
}
// Count of responses handled by RESPONSES_STRUCT
// increase increase if another response handler is added
int nrOfResponses = 2;
RESPONSES_STRUCT responses[] = {
{"ota", OTA},
{"state", STATE},
@ -145,7 +149,7 @@ void text(uint8_t * payload, size_t length){
// Handle each TYPE of message
int b = 0;
for( b=0 ; strlen(responses[b].type) ; b++ )
for( b=0 ; b<nrOfResponses ; b++ )
{
if( strncmp(doc_in["type"], responses[b].type, strlen(responses[b].type)) == 0 ) {
responses[b].func(doc_in);

View File

@ -163,7 +163,7 @@ async def _register(websocket, message):
Logger.info("Client(%s) mac: %s", name, mac)
# Some code
response = {'response_type': 'registry', 'state': 'ok'}
response = {'type': 'registry', 'state': 'ok'}
await websocket.send(json.dumps(response))
@ -173,13 +173,13 @@ async def _state(websocket, message):
Logger.info("Client(%s) mac: %s", name, mac)
# Some code
response = {'response_type': 'state', 'state': 'ok'}
response = {'type': 'state', 'state': 'ok'}
await websocket.send(json.dumps(response))
async def _unhandleld(websocket, msg):
Logger.info("Unhandled message from device: %s", str(msg))
response = {'response_type': 'response', 'state': 'nok'}
response = {'type': 'response', 'state': 'nok'}
await websocket.send(json.dumps(response))