508 字
3 分钟
物联网应用技能考核Zstack协议栈实现功能

基础#

工程类型#

CoordinatorEB -> 协调器
RouterEB -> 路由器
EndDeviceEB -> 终端节点

组网点灯#

利用 Z-Stack 协议栈实现组网成功后 1 个 LED 常亮
利用 Z-Stack 协议栈实现组网成功后 2 个 LED 常亮

修改SampleApp.c中的SampleApp_ProcessEvent();

uint16 SampleApp_ProcessEvent( uint8 task_id, uint16 events )
{
···
if ( (SampleApp_NwkState == DEV_ZB_COORD)
|| (SampleApp_NwkState == DEV_ROUTER)
|| (SampleApp_NwkState == DEV_END_DEVICE) )
{
//修改位置
// Start sending the periodic message in a regular interval.
osal_start_timerEx( SampleApp_TaskID,
SAMPLEAPP_SEND_PERIODIC_MSG_EVT,
SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT );
}
···
}

#组网闪烁

利用 Z-Stack 协议栈实现组网成功 1 个 LED 闪烁,周期0.5 秒
利用 Z-Stack 协议栈实现组网成功 1 个 LED 闪烁,周期1 秒
利用 Z-Stack 协议栈实现组网成功 1 个 LED 闪烁,周期2 秒
利用 Z-Stack 协议栈实现组网成功 2 个 LED 同时闪烁,周期2秒(P1.0和P1.4)
利用 Z-Stack 协议栈实现组网成功 1 个 LED 闪烁,周期3 秒
利用 Z-Stack 协议栈实现组网成功 2 个 LED 同时闪烁,周期3 秒(P1.0 和P1.4)

修改SampleApp.h中的SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT;

#define SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT 5000//单位ms

修改SampleApp.c中的SampleApp_ProcessEvent();

uint16 SampleApp_ProcessEvent( uint8 task_id, uint16 events )
{
···
if ( events & SAMPLEAPP_SEND_PERIODIC_MSG_EVT )
{
//修改位置
// Send the periodic message
SampleApp_SendPeriodicMessage();
// Setup to send message again in normal period (+ a little jitter)
osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT,
(SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT + (osal_rand() & 0x00FF)) );
// return unprocessed events
return (events ^ SAMPLEAPP_SEND_PERIODIC_MSG_EVT);
}
···
}

串口发送#

利用 Z-Stack 协议栈串口发送字符串“hello”
利用 Z-Stack 协议栈串口发送字符串“hello world”
利用 Z-Stack 协议栈串口发送字符串“hello iot”
利用 Z-Stack 协议栈串口发送字符串“happy”
利用 Z-Stack 协议栈串口发送字符串“I get data”

修改预编译

ZTOOL_P1
xMT_TASK
xMT_SYS_FUNC
xMT_ZDO_FUNC
LCD_SUPPORTED=DEBUG

修改MT_UART.h的MT_UART_DEFAULT_BAUDRATE

#define MT_UART_DEFAULT_BAUDRATE HAL_UART_BR_9600

修改MT_UART.h的MT_UART_DEFAULT_OVERFLOW

#define MT_UART_DEFAULT_OVERFLOW FALSE

修改SampleApp.c中的SampleApp_Init();

void SampleApp_Init( uint8 task_id )
{
SampleApp_TaskID = task_id;
SampleApp_NwkState = DEV_INIT;
SampleApp_TransID = 0;
MT_UartInit ();//修改波特率 关流控
MT_UartRegisterTaskID(task_id);// 登记任务号
HalUARTWrite(0,"Hello World",11);//发送
// Device hardware initialization can be added here or in main() (Zmain.c).
// If the hardware is application specific - add it here.
// If the hardware is other parts of the device add it in main().
···
}
物联网应用技能考核Zstack协议栈实现功能
https://fuwari.vercel.app/posts/物联网应用技能考核zstack协议栈实现功能/
作者
橙橙橙汁
发布于
2022-09-28
许可协议
CC BY-NC-SA 4.0