当前位置:   article > 正文

AWS iot SDK(aws-iot-device-sdk-embedded-C)添加设备断电后上报离线状态的功能_sigv4-for-aws-iot-embedded-sdk

sigv4-for-aws-iot-embedded-sdk

1.在ESP8266_RTOS_SDK\components\aws_iot\aws-iot-device-sdk-embedded-C\include\aws_iot_shadow_interface.h中添加如下代码:

  1. typedef struct {
  2. ShadowConnectParameters_t scp;
  3. unsigned int magic;
  4. unsigned short topicLen;
  5. unsigned short msgLen;
  6. char topic[64];
  7. char msg[64];
  8. } HLE_ShadowConnectParameters_t;
  9. #define HLE_LAST_WILL_MSG "{\"state\":{\"reported\":{\"firmwave\":{\"connected\":\"false\",\"socket\":\"null\",\"usb\":\"null\"}}}}"

2.在ESP8266_RTOS_SDK\components\aws_iot\aws-iot-device-sdk-embedded-C\src\aws_iot_shadow.c中添加如下代码:

修改 函数 aws_iot_shadow_connect:

  1. #if 0 //HLE modify
  2. ConnectParams.isWillMsgPresent = false;
  3. #else
  4. typedef struct {
  5. unsigned int magic;
  6. unsigned short topicLen;
  7. unsigned short msgLen;
  8. char topic[64];
  9. char msg[64];
  10. } HLE_LASTWILL_PARA;
  11. HLE_LASTWILL_PARA* hlp = (HLE_LASTWILL_PARA*)((void*)pParams+sizeof(ShadowConnectParameters_t));
  12. if(hlp->magic == 0x19750521)
  13. {
  14. ConnectParams.isWillMsgPresent = true;
  15. ConnectParams.will = iotMqttWillOptionsDefault;
  16. ConnectParams.will.pTopicName = hlp->topic;
  17. ConnectParams.will.topicNameLen = hlp->topicLen;
  18. ConnectParams.will.pMessage = hlp->msg;
  19. ConnectParams.will.msgLen = hlp->msgLen;
  20. ConnectParams.keepAliveIntervalInSec = 10;//30;
  21. }
  22. else
  23. {
  24. ConnectParams.isWillMsgPresent = false;
  25. }
  26. #endif

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/472950
推荐阅读
相关标签
  

闽ICP备14008679号