ch582串口通信

我收到數(shù)據(jù)后解析,想通過串口發(fā)送,注釋的JSON格式可以成功和阿里云傳輸,但是沒注釋的JSON格式不能和阿里云傳輸。著兩個JSON格式我打印后解析也都是標準的JSON格式,想問問是因為硬件什么的原因?qū)е峦ㄐ攀幔苛硗馊绻以谖醋⑨尩腏SON格式里直接傳XX.X這類%.1f的格式數(shù)據(jù),會導(dǎo)致APP_DBG打印不出來數(shù)據(jù)。

????????????if(len?>=?4)??//?假設(shè)數(shù)據(jù)至少有4字節(jié)
????????????{
????????????????//?解析數(shù)據(jù)
???????????????char?dataStr[254];
???????????????int?offset?=?sprintf(dataStr,?"data={");
???????????????for(int?i?=?0;?i?<?len;?i++)?{
???????????????????offset?+=?sprintf(dataStr?+?offset,?"%d",?received_data[i]);
???????????????????if(i?<?len?-?1)
???????????????????????offset?+=?sprintf(dataStr?+?offset,?",");
???????????????}
???????????????sprintf(dataStr?+?offset,?"},src:0x%04x",?ctx->addr);
???????????????APP_DBG("%s\n",?dataStr);

???????????????//?直接獲取整數(shù)值
???????????????uint8_t?co2?=?received_data[0];
???????????????uint8_t?WindSpeed?=?received_data[1];
???????????????uint8_t?Humidity?=?received_data[2];
???????????????uint8_t?temperature?=?received_data[3];

??????????????int?co2_dec?=?rand()%10;
??????????????int?wind_dec?=?rand()%10;
??????????????int?hum_dec?=?rand()%10;
??????????????int?temp_dec?=?rand()%10;

??????????????APP_DBG("CO2:?%d.%d,?WindSpeed:?%d.%d,?Humidity:?%d.%d,?Temperature:?%d.%d\n",
??????????????????????co2,?co2_dec,
??????????????????????WindSpeed,?wind_dec,
??????????????????????Humidity,?hum_dec,
??????????????????????temperature,?temp_dec);

//???????????????????uint8_t?TxBuff7[]?=?"{\"method\":\"thing.XXX.property.post\","
//????????????????????????????????????????"\"id\":\"224\","
//????????????????????????????????????????"\"params\":{"
//????????????????????????????????????????"\"co2\":5.1,"
//????????????????????????????????????????"\"WindSpeed\":17.2,"
//????????????????????????????????????????"\"Humidity\":27.2,"
//????????????????????????????????????????"\"temperature\":37.2"
//????????????????????????????????????????"},"
//????????????????????????????????????????"\"version\":\"1.0\"}\r\n";

???????????????uint8_t?TxBuff7[256];
???????????????snprintf(TxBuff7,?sizeof(TxBuff7),
????????????????????????"{\"method\":\"thing.XXX.property.post\","
????????????????????????"\"id\":\"224\","
????????????????????????"\"params\":{"
????????????????????????"\"co2\":%d.%d,"
????????????????????????"\"WindSpeed\":%d.%d,"
????????????????????????"\"Humidity\":%d.%d,"
????????????????????????"\"temperature\":%d.%d"
????????????????????????"},"
????????????????????????"\"version\":\"1.0\"}\r\n",
????????????????????????co2,?co2_dec,
????????????????????????WindSpeed,?wind_dec,
????????????????????????Humidity,?hum_dec,
????????????????????????temperature,?temp_dec);
???????????????????APP_DBG("Sent?JSON:?%s",?TxBuff7);
???????????????????/*?配置串口3:先配置IO口模式,再配置串口?*/
???????????????????GPIOA_SetBits(GPIO_Pin_5);
???????????????????GPIOA_ModeCfg(GPIO_Pin_4,?GPIO_ModeIN_PU);??????//?RXD-配置上拉輸入
???????????????????GPIOA_ModeCfg(GPIO_Pin_5,?GPIO_ModeOut_PP_5mA);?//?TXD-配置推挽輸出,注意先讓IO口輸出高電平
???????????????????UART3_DefInit();
//??????????????????DelayMs(3000);
???????????????????UART3_SendString(TxBuff7,?sizeof(TxBuff7));


如果是存在浮點類操作,注意博客第3點:

關(guān)于MounRiver編譯器配置的若干問題 - JayWell - 博客園



只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频