void mvdNotify_WifiStatusHandler(WiFiEvent event, mico_Context_t * const inContext) { mvd_log_trace(); (void)inContext; switch (event) { case NOTIFY_STATION_UP: MVDDevInterfaceSend(DEFAULT_MVD_STATION_UP_MSG_2MCU, strlen(DEFAULT_MVD_STATION_UP_MSG_2MCU)); if(NULL == _wifi_station_on_sem){ mico_rtos_init_semaphore(&_wifi_station_on_sem, 1); } mico_rtos_set_semaphore(&_wifi_station_on_sem); break; case NOTIFY_STATION_DOWN: MVDDevInterfaceSend(DEFAULT_MVD_STATION_DOWN_MSG_2MCU, strlen(DEFAULT_MVD_STATION_DOWN_MSG_2MCU)); break; case NOTIFY_AP_UP: break; case NOTIFY_AP_DOWN: break; default: break; } return; }
void mvdNotify_WifiStatusHandler(WiFiEvent event, mico_Context_t * const inContext) { mvd_log_trace(); (void)inContext; switch (event) { case NOTIFY_STATION_UP: MVDDevInterfaceSend(DEFAULT_MVD_STATION_UP_MSG_2MCU, strlen(DEFAULT_MVD_STATION_UP_MSG_2MCU)); if(NULL == _wifi_station_on_sem){ mico_rtos_init_semaphore(&_wifi_station_on_sem, 1); } mico_rtos_set_semaphore(&_wifi_station_on_sem); // set LED to green means station down, data: on/off,H,S,B LedControlMsgHandler("1,120,100,100", strlen("1,120,100,100")); break; case NOTIFY_STATION_DOWN: MVDDevInterfaceSend(DEFAULT_MVD_STATION_DOWN_MSG_2MCU, strlen(DEFAULT_MVD_STATION_DOWN_MSG_2MCU)); // set LED to light green means station down, data: on/off,H,S,B LedControlMsgHandler("1,120,100,10", strlen("1,120,100,10")); break; case NOTIFY_AP_UP: break; case NOTIFY_AP_DOWN: break; default: break; } return; }
// handle MCU msg here, for example: send to Cloud OSStatus MVDDeviceMsgProcess(mico_Context_t* const context, uint8_t *inBuf, unsigned int inBufLen) { mvd_log_trace(); OSStatus err = kUnknownErr; err = MVDCloudInterfaceSend(inBuf, inBufLen); // transfer raw data to cloud require_noerr_action( err, exit, mvd_log("ERROR: send to cloud error! err=%d", err) ); return kNoErr; exit: return err; }
// MVD => Cloud // if topic is NULL, send to default topic: device_id/out, // else send to sub-channel: device_id/out/<topic> OSStatus MVDSendMsg2Cloud(mico_Context_t* const context, const char* topic, unsigned char *inBuf, unsigned int inBufLen) { mvd_log_trace(); OSStatus err = kUnknownErr; err = MVDCloudInterfaceSendtoChannel(topic, inBuf, inBufLen); // transfer raw data require_noerr_action( err, exit, mvd_log("ERROR: send to cloud error! err=%d", err) ); return kNoErr; exit: return err; }
// handle cloud msg here, for example: send to USART or echo to cloud OSStatus MVDCloudMsgProcess(mico_Context_t* context, const char* topic, const unsigned int topicLen, unsigned char *inBuf, unsigned int inBufLen) { mvd_log_trace(); OSStatus err = kUnknownErr; char* responseTopic = NULL; unsigned char* responseMsg = NULL; unsigned char* ptr = NULL; int responseMsgLen = 0; /* send to USART */ err = MVDDevInterfaceSend(inBuf, inBufLen); // transfer raw data to USART require_noerr_action( err, exit, mvd_log("ERROR: send to MCU error! err=%d", err) ); /* echo to cloud */ // responseTopic = device_id/out, message = [MAC]msg responseTopic = ECS_str_replace(responseTopic, topic, topicLen, "/in", "/out"); responseMsgLen = strlen(context->micoStatus.mac) + 2 + inBufLen; responseMsg = (unsigned char*)malloc(responseMsgLen + 1); memset(responseMsg, 0x00, responseMsgLen); if(NULL == responseMsg){ err = kNoMemoryErr; goto exit; } ptr = responseMsg; memcpy(ptr, "[", 1); ptr += 1; memcpy(ptr, (const void*)&(context->micoStatus.mac), strlen(context->micoStatus.mac)); ptr += strlen(context->micoStatus.mac); memcpy(ptr, "]", 1); ptr += 1; memcpy(ptr, inBuf, inBufLen); ptr += inBufLen; memcpy(ptr, '\0', 1); err = MVDCloudInterfaceSendto(responseTopic, responseMsg, responseMsgLen); if(NULL != responseTopic){ free(responseTopic); } if(NULL != responseMsg){ ptr = NULL; free(responseMsg); } return kNoErr; exit: return err; }
// handle cloud msg here, for example: send to USART or echo to cloud OSStatus MVDCloudMsgProcess(mico_Context_t* context, const char* topic, const unsigned int topicLen, unsigned char *inBuf, unsigned int inBufLen) { mvd_log_trace(); OSStatus err = kUnknownErr; /* send to USART */ err = MVDDevInterfaceSend(inBuf, inBufLen); // transfer raw data to USART require_noerr_action( err, exit, mvd_log("ERROR: send to MCU error! err=%d", err) ); return kNoErr; exit: return err; }
// handle cloud msg here, for example: send to USART or echo to cloud OSStatus MVDCloudMsgProcess(mico_Context_t* context, const char* topic, const unsigned int topicLen, unsigned char *inBuf, unsigned int inBufLen) { mvd_log_trace(); OSStatus err = kUnknownErr; // char* responseTopic = NULL; // unsigned char* responseMsg = NULL; // unsigned char* ptr = NULL; // int responseMsgLen = 0; // // /* send to USART */ // err = MVDDevInterfaceSend(inBuf, inBufLen); // transfer raw data to USART // require_noerr_action( err, exit, mvd_log("ERROR: send to MCU error! err=%d", err) ); // // /* echo to cloud */ // // responseTopic = device_id/out, message = [MAC]msg // responseTopic = ECS_str_replace(responseTopic, topic, topicLen, "/in", "/out"); // responseMsgLen = strlen(context->micoStatus.mac) + 2 + inBufLen; // responseMsg = (unsigned char*)malloc(responseMsgLen + 1); // memset(responseMsg, 0x00, responseMsgLen); // if(NULL == responseMsg){ // err = kNoMemoryErr; // goto exit; // } // ptr = responseMsg; // memcpy(ptr, "[", 1); // ptr += 1; // memcpy(ptr, (const void*)&(context->micoStatus.mac), strlen(context->micoStatus.mac)); // ptr += strlen(context->micoStatus.mac); // memcpy(ptr, "]", 1); // ptr += 1; // memcpy(ptr, inBuf, inBufLen); // ptr += inBufLen; // memcpy(ptr, '\0', 1); // err = MVDCloudInterfaceSendto(responseTopic, responseMsg, responseMsgLen); // if(NULL != responseTopic){ // free(responseTopic); // } // if(NULL != responseMsg){ // ptr = NULL; // free(responseMsg); // } /* LED control */ unsigned char* usartCmd = NULL; unsigned int usartCmdLen = 0; // translate cloud message to control protocol format err = MVDMsgTransformCloud2Device(inBuf, inBufLen, &usartCmd, &usartCmdLen); if(NULL != usartCmd){ free(usartCmd); usartCmd = NULL; usartCmdLen = 0; } if (kNoErr == err){ //err = MVDCloudInterfaceSend(LED_RESP_CMD_VALUE_OK, strlen((const char*)LED_RESP_CMD_VALUE_OK)); return kNoErr; } else { //err = MVDCloudInterfaceSend(LED_RESP_CMD_VALUE_FAILED, strlen((const char*)LED_RESP_CMD_VALUE_FAILED)); return kRequestErr; } //exit: // return err; }