void iot_subscribe_callback_handler(AWS_IoT_Client *pClient, char *topicName, uint16_t topicNameLen, IoT_Publish_Message_Params *params, void *pData) { IOT_UNUSED(pData); IOT_UNUSED(pClient); IOT_INFO("Subscribe callback"); IOT_INFO("%.*s\t%.*s", topicNameLen, topicName, (int) params->payloadLen, params->payload); }
IoT_Error_t iot_tls_write(Network *pNetwork, unsigned char *pMsg, size_t len, Timer *timer, size_t *written_len) { size_t i = 0; uint8_t firstByte, secondByte; uint16_t topicNameLen; IOT_UNUSED(pNetwork); IOT_UNUSED(timer); for(i = 0; (i < len) && left_ms(timer) > 0; i++) { TxBuffer.pBuffer[i] = pMsg[i]; } TxBuffer.len = len; *written_len = len; /* Save last two subscribed topics */ if((TxBuffer.pBuffer[0] == 0x82 ? true : false)) { snprintf(SecondLastSubscribeMessage, lastSubscribeMsgLen, "%s", LastSubscribeMessage); secondLastSubscribeMsgLen = lastSubscribeMsgLen; firstByte = (uint8_t)(TxBuffer.pBuffer[4]); secondByte = (uint8_t)(TxBuffer.pBuffer[5]); topicNameLen = (uint16_t) (secondByte + (256 * firstByte)); snprintf(LastSubscribeMessage, topicNameLen + 1u, "%s", &(TxBuffer.pBuffer[6])); // Added one for null character lastSubscribeMsgLen = topicNameLen + 1u; } return SUCCESS; }
void windowActuate_Callback(const char *pJsonString, uint32_t JsonStringDataLen, jsonStruct_t *pContext) { IOT_UNUSED(pJsonString); IOT_UNUSED(JsonStringDataLen); if(pContext != NULL) { IOT_INFO("Delta - Window state changed to %d", *(bool *) (pContext->pData)); } }
static void AckStatusCallback(AWS_IoT_Client *pClient, char *topicName, uint16_t topicNameLen, IoT_Publish_Message_Params *params, void *pData) { int32_t tokenCount; uint8_t i; void *pJsonHandler = NULL; char temporaryClientToken[MAX_SIZE_CLIENT_TOKEN_CLIENT_SEQUENCE]; IOT_UNUSED(pClient); IOT_UNUSED(topicNameLen); IOT_UNUSED(pData); if(params->payloadLen > SHADOW_MAX_SIZE_OF_RX_BUFFER) { IOT_WARN("Payload larger than RX Buffer"); return; } memcpy(shadowRxBuf, params->payload, params->payloadLen); shadowRxBuf[params->payloadLen] = '\0'; // jsmn_parse relies on a string if(!isJsonValidAndParse(shadowRxBuf, pJsonHandler, &tokenCount)) { IOT_WARN("Received JSON is not valid"); return; } if(isAckForMyThingName(topicName)) { uint32_t tempVersionNumber = 0; if(extractVersionNumber(shadowRxBuf, pJsonHandler, tokenCount, &tempVersionNumber)) { if(tempVersionNumber > shadowJsonVersionNum) { shadowJsonVersionNum = tempVersionNumber; } } } if(extractClientToken(shadowRxBuf, temporaryClientToken)) { for(i = 0; i < MAX_ACKS_TO_COMEIN_AT_ANY_GIVEN_TIME; i++) { if(!AckWaitList[i].isFree) { if(strcmp(AckWaitList[i].clientTokenID, temporaryClientToken) == 0) { Shadow_Ack_Status_t status; if(strstr(topicName, "accepted") != NULL) { status = SHADOW_ACK_ACCEPTED; } else if(strstr(topicName, "rejected") != NULL) { status = SHADOW_ACK_REJECTED; } else { continue; } /* status == SHADOW_ACK_ACCEPTED || status == SHADOW_ACK_REJECTED */ if(AckWaitList[i].callback != NULL) { AckWaitList[i].callback(AckWaitList[i].thingName, AckWaitList[i].action, status, shadowRxBuf, AckWaitList[i].pCallbackContext); } unsubscribeFromAcceptedAndRejected(i); AckWaitList[i].isFree = true; return; } } } } }
int privilege_check(launcher_t *l, const char *label, uid_t uid, const char *privilege) { IOT_UNUSED(l); IOT_UNUSED(label); IOT_UNUSED(uid); IOT_UNUSED(privilege); return 1; }
static void shadow_delta_callback(AWS_IoT_Client *pClient, char *topicName, uint16_t topicNameLen, IoT_Publish_Message_Params *params, void *pData) { int32_t tokenCount; uint32_t i = 0; void *pJsonHandler = NULL; int32_t DataPosition; uint32_t dataLength; uint32_t tempVersionNumber = 0; FUNC_ENTRY; IOT_UNUSED(pClient); IOT_UNUSED(topicName); IOT_UNUSED(topicNameLen); IOT_UNUSED(pData); if(params->payloadLen > SHADOW_MAX_SIZE_OF_RX_BUFFER) { IOT_WARN("Payload larger than RX Buffer"); return; } memcpy(shadowRxBuf, params->payload, params->payloadLen); shadowRxBuf[params->payloadLen] = '\0'; // jsmn_parse relies on a string if(!isJsonValidAndParse(shadowRxBuf, pJsonHandler, &tokenCount)) { IOT_WARN("Received JSON is not valid"); return; } if(shadowDiscardOldDeltaFlag) { if(extractVersionNumber(shadowRxBuf, pJsonHandler, tokenCount, &tempVersionNumber)) { if(tempVersionNumber > shadowJsonVersionNum) { shadowJsonVersionNum = tempVersionNumber; } else { IOT_WARN("Old Delta Message received - Ignoring rx: %d local: %d", tempVersionNumber, shadowJsonVersionNum); return; } } } for(i = 0; i < tokenTableIndex; i++) { if(!tokenTable[i].isFree) { if(isJsonKeyMatchingAndUpdateValue(shadowRxBuf, pJsonHandler, tokenCount, (jsonStruct_t *) tokenTable[i].pStruct, &dataLength, &DataPosition)) { if(tokenTable[i].callback != NULL) { tokenTable[i].callback(shadowRxBuf + DataPosition, dataLength, (jsonStruct_t *) tokenTable[i].pStruct); } } } } }
void ShadowUpdateStatusCallback(const char *pThingName, ShadowActions_t action, Shadow_Ack_Status_t status,const char *pReceivedJsonDocument, void *pContextData) { IOT_UNUSED(pThingName); IOT_UNUSED(action); IOT_UNUSED(pReceivedJsonDocument); IOT_UNUSED(pContextData); if (SHADOW_ACK_TIMEOUT == status) { IOT_INFO("Update Timeout--"); } else if (SHADOW_ACK_REJECTED == status) { IOT_INFO("Update RejectedXX"); } else if (SHADOW_ACK_ACCEPTED == status) { IOT_INFO("Update Accepted!!!"); } }
static void iot_tests_unit_acr_subscribe_callback_handler(AWS_IoT_Client *pClient, char *topicName, uint16_t topicNameLen, IoT_Publish_Message_Params *params, void *pData) { char *tmp = params->payload; unsigned int i; IOT_UNUSED(pClient); IOT_UNUSED(topicName); IOT_UNUSED(topicNameLen); IOT_UNUSED(pData); for(i = 0; i < params->payloadLen; i++) { CallbackMsgString[i] = tmp[i]; } }
IoT_Error_t aws_iot_mqtt_client_unlock_mutex(AWS_IoT_Client *pClient, IoT_Mutex_t *pMutex) { if(NULL == pClient || NULL == pMutex) { return NULL_VALUE_ERROR; } IOT_UNUSED(pClient); return aws_iot_thread_mutex_unlock(pMutex); }
IoT_Error_t iot_tls_connect(Network *pNetwork, TLSConnectParams *params) { IOT_UNUSED(pNetwork); if(NULL != params) { _iot_tls_set_connect_params(pNetwork, params->pRootCALocation, params->pDeviceCertLocation, params->pDevicePrivateKeyLocation, params->pDestinationURL, params->DestinationPort, params->timeout_ms, params->ServerVerificationFlag); } if(NULL != invalidEndpointFilter && 0 == strcmp(invalidEndpointFilter, pNetwork->tlsConnectParams.pDestinationURL)) { return NETWORK_ERR_NET_UNKNOWN_HOST; } if(invalidPortFilter == pNetwork->tlsConnectParams.DestinationPort) { return NETWORK_ERR_NET_CONNECT_FAILED; } if(NULL != invalidRootCAPathFilter && 0 == strcmp(invalidRootCAPathFilter, pNetwork->tlsConnectParams.pRootCALocation)) { return NETWORK_ERR_NET_CONNECT_FAILED; } if(NULL != invalidCertPathFilter && 0 == strcmp(invalidCertPathFilter, pNetwork->tlsConnectParams.pDeviceCertLocation)) { return NETWORK_ERR_NET_CONNECT_FAILED; } if(NULL != invalidPrivKeyPathFilter && 0 == strcmp(invalidPrivKeyPathFilter, pNetwork->tlsConnectParams.pDevicePrivateKeyLocation)) { return NETWORK_ERR_NET_CONNECT_FAILED; } return SUCCESS; }
void ShadowUpdateStatusCallback(const char *pThingName, ShadowActions_t action, Shadow_Ack_Status_t status, const char *pReceivedJsonDocument, void *pContextData) { IOT_UNUSED(pThingName); IOT_UNUSED(action); IOT_UNUSED(pReceivedJsonDocument); IOT_UNUSED(pContextData); shadowUpdateInProgress = false; if(SHADOW_ACK_TIMEOUT == status) { ESP_LOGE(TAG, "Update timed out"); } else if(SHADOW_ACK_REJECTED == status) { ESP_LOGE(TAG, "Update rejected"); } else if(SHADOW_ACK_ACCEPTED == status) { ESP_LOGI(TAG, "Update accepted"); } }
void iot_subscribe_callback_handler(AWS_IoT_Client *pClient, char *topicName, uint16_t topicNameLen, IoT_Publish_Message_Params *params, void *pData) { IOT_UNUSED(pData); IOT_UNUSED(pClient); IOT_INFO("Message: %.*s\t%.*s", topicNameLen, topicName, (int) params->payloadLen, (char*)params->payload); char* msg = (char*)(malloc((int) params->payloadLen) + 1); strncpy(msg, (char*) params->payload, (int) params->payloadLen); msg[(int) params->payloadLen] = '\0'; if (findCommand(msg)) { handleCommand(); } else { publishRobotState(); publishMessage("Undefined command"); } }
static void del_defer(void *glue_data, void *id) { dfr_t *d = (dfr_t *)id; IOT_UNUSED(glue_data); uv_timer_stop(&d->uv_tmr); iot_free(d); }
static void del_timer(void *glue_data, void *id) { tmr_t *t = (tmr_t *)id; IOT_UNUSED(glue_data); uv_timer_stop(&t->uv_tmr); iot_free(t); }
static void del_io(void *glue_data, void *id) { io_t *io = (io_t *)id; IOT_UNUSED(glue_data); uv_poll_stop(&io->uv_poll); iot_free(io); }
void DeltaCallback(const char *pJsonValueBuffer, uint32_t valueLength, jsonStruct_t *pJsonStruct_t) { IOT_UNUSED(pJsonStruct_t); IOT_DEBUG("Received Delta message %.*s", valueLength, pJsonValueBuffer); if (buildJSONForReported(stringToEchoDelta, SHADOW_MAX_SIZE_OF_RX_BUFFER, pJsonValueBuffer, valueLength)) { messageArrivedOnDelta = true; } }
static void iot_tests_unit_yield_test_subscribe_callback_handler(AWS_IoT_Client *pClient, char *topicName, uint16_t topicNameLen, IoT_Publish_Message_Params *params, void *pData) { char *tmp = params->payload; unsigned int i; IoT_Error_t rc = SUCCESS; IOT_UNUSED(pClient); IOT_UNUSED(topicName); IOT_UNUSED(topicNameLen); IOT_UNUSED(pData); rc = aws_iot_mqtt_yield(pClient, 1000); CHECK_EQUAL_C_INT(MQTT_CLIENT_NOT_IDLE_ERROR, rc); for(i = 0; i < params->payloadLen; i++) { CallbackMsgString[i] = tmp[i]; } }
IoT_Error_t iot_tls_read(Network *pNetwork, unsigned char *pMsg, size_t len, Timer *pTimer, size_t *read_len) { IOT_UNUSED(pNetwork); IOT_UNUSED(pTimer); if(RxIndex > TLSMaxBufferSize - 1) { RxIndex = TLSMaxBufferSize - 1; } if(RxBuffer.len <= RxIndex || !isTimerExpired(RxBuffer.expiry_time)) { return NETWORK_SSL_NOTHING_TO_READ; } if((false == RxBuffer.NoMsgFlag) && (RxIndex < RxBuffer.len)) { memcpy(pMsg, &(RxBuffer.pBuffer[RxIndex]), len); RxIndex += len; *read_len = len; } return SUCCESS; }
static void timer_cb(uv_timer_t *handle #if UV_VERSION_MAJOR < 1 , int status #endif ) { tmr_t *t = (tmr_t *)handle->data; #if UV_VERSION_MAJOR < 1 IOT_UNUSED(status); #endif t->cb(t->glue_data, t, t->user_data); }
bool extractVersionNumber(const char *pJsonDocument, void *pJsonHandler, int32_t tokenCount, uint32_t *pVersionNumber) { int32_t i; IoT_Error_t ret_val = AWS_SUCCESS; IOT_UNUSED(pJsonHandler); for(i = 1; i < tokenCount; i++) { if(jsoneq(pJsonDocument, &(jsonTokenStruct[i]), SHADOW_VERSION_STRING) == 0) { ret_val = parseUnsignedInteger32Value(pVersionNumber, pJsonDocument, &jsonTokenStruct[i + 1]); if(ret_val == AWS_SUCCESS) { return true; } } } return false; }
static void defer_cb(uv_timer_t *handle #if UV_VERSION_MAJOR < 1 , int status #endif ) { dfr_t *d = (dfr_t *)handle->data; #if UV_VERSION_MAJOR < 1 IOT_UNUSED(status); #endif d->cb(d->glue_data, d, d->user_data); if (d->enabled) uv_timer_again(&d->uv_tmr); }
void disconnectCallbackHandler(AWS_IoT_Client *pClient, void *data) { IOT_WARN("MQTT Disconnect"); IoT_Error_t rc = FAILURE; if (NULL == pClient) { return; } IOT_UNUSED(data); if (aws_iot_is_autoreconnect_enabled(pClient)) { IOT_INFO("Auto Reconnect is enabled, Reconnecting attempt will start now"); } else { IOT_WARN("Auto Reconnect not enabled. Starting manual reconnect..."); rc = aws_iot_mqtt_attempt_reconnect(pClient); if (NETWORK_RECONNECTED == rc) { IOT_WARN("Manual Reconnect Successful"); } else { IOT_WARN("Manual Reconnect Failed - %d", rc); } } }
IoT_Error_t iot_tls_destroy(Network *pNetwork) { IOT_UNUSED(pNetwork); return SUCCESS; }
IoT_Error_t iot_tls_is_connected(Network *pNetwork) { IOT_UNUSED(pNetwork); /* Use this to add implementation which can check for physical layer disconnect */ return NETWORK_PHYSICAL_LAYER_CONNECTED; }
void iot_tests_unit_disconnect_handler(AWS_IoT_Client *pClient, void *disconParam) { IOT_UNUSED(pClient); IOT_UNUSED(disconParam); dcHandlerInvoked = true; }
void disconnectTestHandler(AWS_IoT_Client *pClient, void *disconHandlerParam) { IOT_UNUSED(pClient); IOT_UNUSED(disconHandlerParam); handlerInvoked = true; }
IoT_Error_t iot_tls_disconnect(Network *pNetwork) { IOT_UNUSED(pNetwork); return SUCCESS; }