SWA2G422 & 485JK2G Basics: Mobile APP binding W5500 (Ethernet) devices APMACBind way to achieve remote communication control MQTT

 

 

 

Explanation

  On a demonstration W5500 realize MQTT communication control

  By the one we know

  W5500 subscribe to the theme: user / W5500 MAC address

  W5500 released the theme: device / W5500 MAC address

  This section demonstrates the use APP APMACBind way to get the MAC address of W5500, W5500, and further implemented to achieve communications MQTT

APMACBind way of introduction

  (Only along the footsteps of others, will stand still! We need to be creative problem solving!)

  APMACBind is a way of my own doing, this way there is a project currently in use.

  But that was two years ago to do the project, was micro-channel distribution network in order to solve the binding problem

  However, since the micro-channel applet supports UDP, this way also I eliminated (in my mind was eliminated, with a more convenient way)

  But still it is necessary to come up with speaking about, because this way more classic! Reflects the flexible use of knowledge.

 

  First, a brief description of what makes the phone APP W5500 get the MAC address how to achieve

  1.W5500 connects to a router connected MQTT

  2.W5500 get the MAC address of the router

  3.W5500 posted topics: device / router MAC

  4. W5500 mobile phone connection and a router APP

  The phone APP acquisition router MAC address

  6. APP mobile phone subscription: user / router MAC

  Such W5500 will be able to put their MAC address to the phone APP by MQTT, to achieve binding

  As for why the MAC address of the router as the subject (because the only)

  All users with a MQTT server, I need to ensure at the same time without disturbing each other when binding

  W5500 acquisition router MAC using arp, I did not find another easy way ..... Xueyibujing ....

This section features presentations

  First, the device is powered on, the router network cable

    

    

 

 

  Second, the microcontroller program download

 

    

  Third, install mobile APP

    

 

 

    

 

 

 

By APMACBind binding W5500

  First, select Add Device

    

 

 

   二,请确保自己的手机连接了路由器(和W5500连接的同一个)

    连接路由器以后,将自动显示路由器的MAC地址

    

 

 

  三,确定开发板指示灯是否是1S闪耀

 

    注:1S闪耀说明开发板连接了MQTT,APMACBind需要借助MQTT,

    所以需要先保证开发板连接上了MQTT服务器

    

 

 

 

 

 

  三,长按开发板的 PB5 按钮,直至指示灯快闪

    注:闪耀频率加快

    

  四,点击APP上的 添加设备 按钮

    

 

 

  五,搜索成功以后 自动跳转到主页面 并显示绑定的设备

 

    

 

 

 

 

 

 

测试

  一,点击设备进入控制页面

    

 

 

  二,控制第一路继电器吸合

 

     

 

 

  三,控制第二路继电器吸合

 

     

 

 

单片机源码说明(流程说明)

   注:这节代码只是在上一节的基础上增加的功能,只叙述这节增加的功能

    1.1点击按钮3S左右,获取路由器MAC地址,并订阅主题

    

 

 

    

 

 

    1.2 订阅主题成功以后,每隔1S通过MQTT发送W5500自身的MAC地址信息

    发布的主题为: device/路由器的MAC地址

 

    

 

 

    1.3 超时(60S),或者收到APP发来的 "{\"bind\":\"success\"}" 信息以后停止发送信息

 

    

 

单片机源码说明(ARP说明)

  一,我是利用arp获取的路由器的MAC地址信息

  

  二,为了获取路由器的MAC,ARP的远端IP我写的网关

  咱先前在DHCP的时候获取了网关.

  因为咱的W5500连接的路由器,路由器的IP就是网关

 

 

  

 

 

 

 

 

 

APP源码说明

  一,进入绑定页面,监听网络信号改变的广播,然后获取手机APP连接的路由器的MAC地址

    

 

 

    

 

 

  二,点击添加设备以后

    1.订阅主题 device/路由器的MAC地址

    2.显示等待对话框

    3.启动绑定超时

 

    

 

 

 

 

  三,获取到W5500发来的信息

 

    1.提取MAC地址信息,携带信息跳转到主页面

 

    

 

 

 

 

 

 

 

 

 

 

 

 

 

   

Guess you like

Origin www.cnblogs.com/yangfengwu/p/12181710.html