mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-13 05:28:14 +08:00
fix:字符串长度不足导致的数据异常及mac地址异常
fix:mac地址错误(为ap设备mac地址)的问题 add:mqtt配置/idx配置/device name配置
This commit is contained in:
@@ -17,13 +17,13 @@ void user_send( int udp_flag, uint8_t *s )
|
||||
if ( udp_flag )
|
||||
user_udp_send( s ); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
else
|
||||
user_mqtt_send( "domoticz/in", s );
|
||||
user_mqtt_send( s );
|
||||
}
|
||||
|
||||
void user_function_cmd_received( int udp_flag, uint8_t *pusrdata )
|
||||
{
|
||||
OSStatus err = kNoErr;
|
||||
char *out;
|
||||
|
||||
cJSON * pJsonRoot = cJSON_Parse( pusrdata );
|
||||
if ( !pJsonRoot )
|
||||
{
|
||||
@@ -32,7 +32,6 @@ void user_function_cmd_received( int udp_flag, uint8_t *pusrdata )
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>device report
|
||||
os_log( "start json:device report\r\n" );
|
||||
cJSON *p_cmd = cJSON_GetObjectItem( pJsonRoot, "cmd" );
|
||||
if ( p_cmd && cJSON_IsString( p_cmd ) && strcmp( p_cmd->valuestring, "device report" ) == 0 )
|
||||
{
|
||||
@@ -51,23 +50,161 @@ void user_function_cmd_received( int udp_flag, uint8_t *pusrdata )
|
||||
// cJSON_Delete(p_cmd);
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>idx<EFBFBD>ֶ<EFBFBD>int<EFBFBD><EFBFBD><EFBFBD><EFBFBD> description<6F>ֶ<EFBFBD>string<6E><67><EFBFBD><EFBFBD> name<6D>ֶ<EFBFBD>string<6E><67><EFBFBD><EFBFBD>
|
||||
//<2F><><EFBFBD><EFBFBD>
|
||||
cJSON *p_idx = cJSON_GetObjectItem( pJsonRoot, "idx" );
|
||||
cJSON *p_description = cJSON_GetObjectItem( pJsonRoot, "description" );
|
||||
cJSON *p_name = cJSON_GetObjectItem( pJsonRoot, "name" );
|
||||
cJSON *p_mac = cJSON_GetObjectItem( pJsonRoot, "mac" );
|
||||
|
||||
if ( p_idx && cJSON_IsNumber( p_idx ) && (p_idx->valueint >= 3 && p_idx->valueint <= 9) ) //idx
|
||||
//
|
||||
if ( (p_idx && cJSON_IsNumber( p_idx ) && p_idx->valueint == user_config->idx) //idx
|
||||
|| (p_description && cJSON_IsString( p_description ) && strcmp( p_description->valuestring, sys_config->micoSystemConfig.name ) == 0) //p_description name
|
||||
|| (p_name && cJSON_IsString( p_name ) && strcmp( p_name->valuestring, sys_config->micoSystemConfig.name ) == 0) //name
|
||||
|| (p_mac && cJSON_IsString( p_mac ) && strcmp( p_mac->valuestring, strMac ) == 0) //mac
|
||||
)
|
||||
{
|
||||
// os_log("device enter\r\n");
|
||||
cJSON *json_send = cJSON_CreateObject( );
|
||||
cJSON_AddStringToObject( json_send, "mac", strMac );
|
||||
|
||||
cJSON *p_nvalue = cJSON_GetObjectItem( pJsonRoot, "nvalue" );
|
||||
if ( p_nvalue )
|
||||
// if ( p_nvalue && cJSON_IsNumber( p_nvalue ) )
|
||||
// {
|
||||
//// uint32 now_time = system_get_time( );
|
||||
//// os_log( "system_get_time:%d,%d = %09d\r\n", last_time, now_time, now_time - last_time );
|
||||
//// if ( now_time - last_time < 1500000 && p_idx && p_nvalue->valueint == user_rudder_get_direction( ) )
|
||||
//// {
|
||||
//// return_flag = false;
|
||||
//// } else
|
||||
//// {
|
||||
//// user_rudder_press( p_nvalue->valueint );
|
||||
//// }
|
||||
//// user_json_set_last_time( );
|
||||
// }
|
||||
//
|
||||
// if ( p_nvalue )
|
||||
// {
|
||||
// cJSON_AddNumberToObject( json_send, "nvalue", user_rudder_get_direction( ) );
|
||||
// } else
|
||||
// last_time = 0;
|
||||
|
||||
cJSON *p_setting = cJSON_GetObjectItem( pJsonRoot, "setting" );
|
||||
if ( p_setting )
|
||||
{
|
||||
user_led_set( p_nvalue->valueint );
|
||||
user_relay_set( p_idx->valueint - 3, p_nvalue->valueint );
|
||||
cJSON *json_setting_send = cJSON_CreateObject( );
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>/deviceid
|
||||
cJSON *p_setting_name = cJSON_GetObjectItem( p_setting, "name" );
|
||||
if ( p_setting_name && cJSON_IsString( p_setting_name ) )
|
||||
{
|
||||
sprintf( sys_config->micoSystemConfig.name, p_setting_name->valuestring );
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>mqtt ip
|
||||
cJSON *p_mqtt_ip = cJSON_GetObjectItem( p_setting, "mqtt_uri" );
|
||||
if ( p_mqtt_ip && cJSON_IsString( p_mqtt_ip ) )
|
||||
{
|
||||
sprintf( user_config->mqtt_ip, p_mqtt_ip->valuestring );
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>mqtt port
|
||||
cJSON *p_mqtt_port = cJSON_GetObjectItem( p_setting, "mqtt_port" );
|
||||
if ( p_mqtt_port && cJSON_IsNumber( p_mqtt_port ) )
|
||||
{
|
||||
user_config->mqtt_port = p_mqtt_port->valueint;
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>mqtt user
|
||||
cJSON *p_mqtt_user = cJSON_GetObjectItem( p_setting, "mqtt_user" );
|
||||
if ( p_mqtt_user && cJSON_IsString( p_mqtt_user ) )
|
||||
{
|
||||
sprintf( user_config->mqtt_user, p_mqtt_user->valuestring );
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>mqtt password
|
||||
cJSON *p_mqtt_password = cJSON_GetObjectItem( p_setting, "mqtt_password" );
|
||||
if ( p_mqtt_password && cJSON_IsString( p_mqtt_password ) )
|
||||
{
|
||||
sprintf( user_config->mqtt_password, p_mqtt_password->valuestring );
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>domoticz idx
|
||||
cJSON *p_setting_idx = cJSON_GetObjectItem( p_setting, "idx" );
|
||||
if ( p_setting_idx && cJSON_IsNumber( p_setting_idx ) )
|
||||
{
|
||||
user_config->idx = p_setting_idx->valueint;
|
||||
os_log( "idx:%d",user_config->idx );
|
||||
mico_system_context_update( sys_config );
|
||||
}
|
||||
|
||||
if ( p_setting_name || p_mqtt_ip || p_mqtt_port || p_mqtt_user || p_mqtt_password || p_setting_idx )
|
||||
{
|
||||
os_log( "mico_system_context_update" );
|
||||
err = mico_system_context_update( sys_config );
|
||||
require_noerr( err, exit );
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>/deviceid
|
||||
if ( p_setting_name )
|
||||
{
|
||||
cJSON_AddStringToObject( json_setting_send, "name", sys_config->micoSystemConfig.name );
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>mqtt ip
|
||||
if ( p_mqtt_ip )
|
||||
{
|
||||
cJSON_AddStringToObject( json_setting_send, "mqtt_uri", user_config->mqtt_ip );
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>mqtt port
|
||||
if ( p_mqtt_port )
|
||||
{
|
||||
cJSON_AddNumberToObject( json_setting_send, "mqtt_port", user_config->mqtt_port );
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>mqtt user
|
||||
if ( p_mqtt_user )
|
||||
{
|
||||
cJSON_AddStringToObject( json_setting_send, "mqtt_user", user_config->mqtt_user );
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>mqtt password
|
||||
if ( p_mqtt_password )
|
||||
{
|
||||
cJSON_AddStringToObject( json_setting_send, "mqtt_password", user_config->mqtt_password );
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>domoticz idx
|
||||
if ( p_setting_idx )
|
||||
{
|
||||
cJSON_AddNumberToObject( json_setting_send, "idx", user_config->idx );
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject( json_send, "setting", json_setting_send );
|
||||
}
|
||||
|
||||
cJSON_AddStringToObject( json_send, "name", sys_config->micoSystemConfig.name );
|
||||
|
||||
//if (p_idx)
|
||||
if ( user_config->idx >= 0 )
|
||||
cJSON_AddNumberToObject( json_send, "idx", user_config->idx );
|
||||
|
||||
//if ( return_flag == true )
|
||||
{
|
||||
char *json_str = cJSON_Print( json_send );
|
||||
os_log( "pRoot: %s\r\n", json_str );
|
||||
user_send( udp_flag, json_str ); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
free( (void *) json_str );
|
||||
}
|
||||
cJSON_Delete( json_send );
|
||||
}
|
||||
|
||||
cJSON_Delete( pJsonRoot );
|
||||
free( out );
|
||||
return;
|
||||
exit:
|
||||
os_log("user_function_cmd_received ERROR:0x%x",err);
|
||||
|
||||
cJSON_Delete( pJsonRoot );
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user