你先把ds18b20的驱动做好(就是读取温度值得函数),做成ds18b20.c,放到APP文件夹里,然后在SampleAPP.c中加入ds18b20.h头文件,在发送函数没将温度值读出来,在void SampleApp_MessageMSGCB( afIncomingMSGPacket_t *pkt )函数中处理收到的温度值就可以了,发送函数的代码如下void SampleApp_Send_P2P_Message( void )
{
byte str[5];
char strTemp[10];
byte temp;
temp = ReadDs18B20(); //读取温度数据
str[0] = temp/10+48;
str[1] = temp%10+48;
str[2] = ' ';
str[3] = 'C';
str[4] = '\0';
HalUARTWrite(0, "TEMP:", 5); //输出提示信息
HalUARTWrite(0, str, 2);
HalUARTWrite(0, "\n",1);
osal_memcpy(strTemp, "TEMP:", 5);
osal_memcpy(&strTemp[5], str, 5);
HalLcdWriteString(strTemp, HAL_LCD_LINE_3); //LCD显示
if ( AF_DataRequest( &SampleApp_P2P_DstAddr, &SampleApp_epDesc,
SAMPLEAPP_P2P_CLUSTERID,
4,
str,
&SampleApp_TransID,
AF_DISCV_ROUTE,
AF_DEFAULT_RADIUS ) == afStatus_SUCCESS )
{
}
else
{
// Error occurred in request to send.
}
}