EthW5500+STM32

Dependencies:   MQTT WIZnet_Library mbed

Fork of EthW5500 by YX ZHANG

main.cpp

Committer:
AlexQian
Date:
2018-04-19
Revision:
2:566a6b762cdf
Parent:
1:9689429a0a29
Child:
3:54ad271708ff

File content as of revision 2:566a6b762cdf:

#include "mbed.h"
#include "WIZnetInterface.h"
#include "MQTTSocket.h"
#include "MQTTClient.h"
#include "ETHW5500.h"

DigitalIn BTN(PC_13);
//节点名称任取
char *NODE_NAME="n_12345";
 //接在同一子网下的设备MAC地址必须不同
uint8_t mac_addr[6]={0x50,0x51,0x50,0x00,0x00,0x01};

int main() {
    
    const char* actuators = "switch,int\n";
    const char* sensors = "analog,mV\n";
    
    Eth_Init(mac_addr);//初始化
    
    Eth_Subscribe("control",NODE_NAME,"switch");//订阅服务器信息
    
    Eth_Report("event",NODE_NAME,"online",NULL,0,false);//报告节点状态
    Eth_Report("capability",NODE_NAME,"control",actuators,strlen(actuators),true);//报告传感器参数
    Eth_Report("capability",NODE_NAME,"values",sensors,strlen(sensors),true);
    bool btn = 0;//报告GPIO电平
    while(1){
        bool newBTN = BTN;
        if(newBTN != btn){
            char buf[16];
            int value = newBTN ? 3300 : 0;
            sprintf(buf, "%d mV", value);
            Eth_Report("values",NODE_NAME,"analog",buf,strlen(buf),true);
            btn = newBTN;
        }else{
            wait(0.1);
        }
    }
}