EthW5500+STM32

Dependencies:   MQTT WIZnet_Library mbed

Fork of EthW5500 by YX ZHANG

Files at this revision

API Documentation at this revision

Comitter:
AlexQian
Date:
Fri Apr 20 01:37:27 2018 +0000
Parent:
2:566a6b762cdf
Child:
4:10f83daba9ea
Commit message:
URL

Changed in this revision

ETHW5500.cpp Show annotated file Show diff for this revision Revisions of this file
ETHW5500.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/ETHW5500.cpp	Thu Apr 19 13:57:24 2018 +0000
+++ b/ETHW5500.cpp	Fri Apr 20 01:37:27 2018 +0000
@@ -30,14 +30,19 @@
     printf("DHCP...\r\n");
     wiz.connect();
     printf("IP: %s\r\n", wiz.getIPAddress());
+    return ret;
     
+}
+int Eth_ConnectToSer(char *URL)
+{
+    int ret;
     int timecount=1;
-    ret = sock.connect("tdxls-iot.xicp.net",1883);
+    ret = sock.connect(URL,1883);
     //printf("%d-th Server connetion attemp\n",timecount);
     while(ret!=0){
         timecount++;
         //printf("%d-th Server connetion attemp\n",timecount);
-        ret = sock.connect("tdxls-iot.xicp.net",1883);
+        ret = sock.connect(URL,1883);
         if(timecount>20){
             printf("failed to connet Server,Please Check out and Reset\n");
             return 1;
@@ -52,6 +57,7 @@
     }
     printf("client.connect()=%d\r\n",ret);
     return ret;
+    
 }
 
 int Eth_Subscribe(const char* ns,const char *NODE_NAME, const char* type)
--- a/ETHW5500.h	Thu Apr 19 13:57:24 2018 +0000
+++ b/ETHW5500.h	Fri Apr 20 01:37:27 2018 +0000
@@ -6,6 +6,7 @@
 #include "MQTTClient.h"
 typedef MQTT::Client<MQTTSocket,Countdown> MClient;
 int Eth_Init(uint8_t *mar_addr);
+int Eth_ConnectToSer(char *URL);
 int Eth_Subscribe(const char* ns,const char *NODE_NAME, const char* type);
 void Eth_Report(const char* ns,const char *NODE_NAME, const char* type,const char* payload , size_t payload_len , 
                     bool retain );
--- a/main.cpp	Thu Apr 19 13:57:24 2018 +0000
+++ b/main.cpp	Fri Apr 20 01:37:27 2018 +0000
@@ -9,6 +9,8 @@
 char *NODE_NAME="n_12345";
  //接在同一子网下的设备MAC地址必须不同
 uint8_t mac_addr[6]={0x50,0x51,0x50,0x00,0x00,0x01};
+//服务器地址
+char *SeverURL="tdxls-iot.xicp.net";
 
 int main() {
     
@@ -16,6 +18,7 @@
     const char* sensors = "analog,mV\n";
     
     Eth_Init(mac_addr);//初始化
+    Eth_ConnectToSer(SeverURL);//连接到服务器
     
     Eth_Subscribe("control",NODE_NAME,"switch");//订阅服务器信息