UA_StatusCode temperature_sensor_read(void * handle, const UA_NodeId node_id, UA_Boolean source_timestamp, const UA_NumericRange *range, UA_DataValue * data_value) { UA_DateTime sourceTimestamp = UA_DateTime_now(); int result = 0; if(i2c_fd < 0) return UA_STATUSCODE_BADNOTREADABLE; if(!temperature_get(i2c_fd, CONVERSION_CURRENT, &result)) return UA_STATUSCODE_BADNOTREADABLE; data_value->hasValue = true; data_value->hasSourceTimestamp = true; data_value->hasServerTimestamp = true; data_value->sourceTimestamp = sourceTimestamp; UA_Variant_setScalarCopy(&data_value->value, &result, &UA_TYPES[UA_TYPES_INT32]); return UA_STATUSCODE_GOOD; }
void ICACHE_FLASH_ATTR temperature_object_pack(PARAMS * params) { if(NULL == params){ PRINTF("Create first tlv param failed.\n"); return; } struct temperature* temperature = create_temperature(); temperature_get(temperature); if (add_next_uint8(params, temperature->centigrade)){ PRINTF("Add next param failed.\n"); return; } delete_temperature(temperature); }