---
title: "入手arduino和W5100和乐为物联"
url: "https://maker.wiznet.io/chen/projects/%E5%85%A5%E6%89%8Barduino%E5%92%8Cw5100%E5%92%8C%E4%B9%90%E4%B8%BA%E7%89%A9%E8%81%94/"
markdown_url: "https://maker.wiznet.io/chen/projects/%E5%85%A5%E6%89%8Barduino%E5%92%8Cw5100%E5%92%8C%E4%B9%90%E4%B8%BA%E7%89%A9%E8%81%94/md"
type: "UCC: User Created Content"
author: "爱的叹息"
author_url: "https://blog.csdn.net/zp357252539/article/details/76167505?ops_request_misc=%257B%2522request%255Fid"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "爱的叹息"
original_url: "https://blog.csdn.net/zp357252539/article/details/76167505?ops_request_misc=%257B%2522request%255Fid"
published: "2022-09-01"
language: "en"
hardware: ["WIZnet W5500", "Arduino Ethernet Shield 2"]
likes: 7
views: 1241
comments: 1
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# 入手arduino和W5100和乐为物联

> A tutourial of Arduino with W5500 shied to connect Cloud application.

Original author: 爱的叹息 (source: https://blog.csdn.net/zp357252539/article/details/76167505?ops_request_misc=%257B%2522request%255Fid)

## Components

- **WIZnet W5500** x 1 ([docs](https://docs.wiznet.io/Product/Chip/Ethernet/W5500))
- **Arduino Ethernet Shield 2** x 1 ([docs](https://docs.arduino.cc/hardware/ethernet-shield-rev2))
- Software: **Arduino IDE** ([docs](https://www.arduino.cc/en/software))

WIZnet parts: W5500 ([Datasheet](https://docs.wiznet.io/Product/Chip/Ethernet/W5500/datasheet?utm_source=maker&utm_medium=project&utm_campaign=w5500), [product hub](https://maker.wiznet.io/products/w5500/))

## Documents and links

- arduino (code)

## Article

入手arduino和W5100已经有一段时间，朝着物联网的方向努力百度了好几天，试过Yeelink和乐联网均未成功，后来在一个百度贴吧中看到了这个帖子，抱着试一试的心态研究了一下，几经周折终于成功控制LED,在这里感谢[http://tieba.baidu.com/p/4500765226](http://jump.bdimg.com/safecheck/index?url=x+Z5mMbGPAs95UolpNuq+CwM2BpViN6QF0BYrUCVRu/eFc0EpxHr1IeHQfmNX6hX2O5wqAj/AHz4GDvE8C1MKNaPUJPlg5+nS1Bh2J5IcVUexTnSS3e1Wng5cTS2s56uVBKnEWaOOLx5z8Bn4gXBxDA8Zu4mdgY0)这个帖子的楼主给了我重生的希望![](http://tb2.bdstatic.com/tb/editor/images/face/i_f36.png?t=20140803)![](http://tb2.bdstatic.com/tb/editor/images/face/i_f02.png?t=20140803)

下面进入正题

第一先在 [http://www.lewei50.com](http://jump.bdimg.com/safecheck/index?url=x+Z5mMbGPAvE9iZcxuq5DzyPat3fA+S2WfITs42VX/XY7nCoCP8AfPgYO8TwLUwo1o9Qk+WDn6dLUGHYnkhxVR7FOdJLd7VaeDlxNLaznq5UEqcRZo44vHnPwGfiBcHEMDxm7iZ2BjQ=) 申请账号，估计这个大家都不用我教了吧
第二步在“我的物联”列表下的“我的设备”中新建设备如图，名字可以自己定义 ![](http://imgsrc.baidu.com/forum/w%3D580/sign=7ecfea637a0e0cf3a0f74ef33a47f23d/cdbff800baa1cd119c163551b112c8fcc2ce2d86.jpg)

第三
在“传感器与控制器”新建一个传感器如图，设备选择刚才新建的设备，标识就写led3
![](http://imgsrc.baidu.com/forum/w%3D580/sign=01542002f3f2b211e42e8546fa816511/3ad0262442a7d933d9f9a202a54bd11372f001d4.jpg)

第四，点击“智能物联”，点击 控制命令管理 ，新建两个命令
![](http://imgsrc.baidu.com/forum/w%3D580/sign=eee4f667c7fc1e17fdbf8c397a91f67c/8c5bb2504fc2d5622878919cef1190ef76c66c36.jpg)

![](http://imgsrc.baidu.com/forum/w%3D580/sign=0b5d3ed1fe03738dde4a0c2a831ab073/d0bece1190ef76c615b3ba5a9516fdfaae5167c5.jpg)

其中标题和方法名框中的都可以自己定义

第五
添加执行单元
执行单元管理新建两个
![](http://imgsrc.baidu.com/forum/w%3D580/sign=dbb0085fda1b0ef46ce89856edc551a1/6ed6e0ea15ce36d3aa4bc34132f33a87e850b1d3.jpg)

![](http://imgsrc.baidu.com/forum/w%3D580/sign=a6a11863474a20a4311e3ccfa0539847/4a5d4e09c93d70cfde70ea7cf0dcd100bba12b98.jpg)

![](http://imgsrc.baidu.com/forum/w%3D580/sign=130f4392dd39b6004dce0fbfd9513526/e5752024ab18972bd2c640bbeecd7b899f510aa1.jpg)

![](http://imgsrc.baidu.com/forum/w%3D580/sign=0a36750e70f0f736d8fe4c093a54b382/49baa41001e93901806dce4f73ec54e736d19633.jpg)

第六
自定义微信命令
![](http://imgsrc.baidu.com/forum/w%3D580/sign=845ebafe6481800a6ee58906813533d6/c260b88fa0ec08fa043b50d651ee3d6d55fbda6f.jpg)

![](http://imgsrc.baidu.com/forum/w%3D580/sign=0b86ce4f73ec54e741ec1a1689399bfd/bfe190014a90f6035934df363112b31bb151ed9a.jpg)

第七

关键的一步来了，首先下载乐为的库文件，我整理了一下在这里 [http://pan.baidu.com/s/1nv92pvj](http://jump.bdimg.com/safecheck/index?url=x+Z5mMbGPAvVIlwZePSt0B3tEqEFWbC4tOatFxkC6cKxk439RfyFfMzjP89TiPYiXRDu7QJYkbWECKDoAhi0YiQg5Mc6dC0DBwl6yKPBk+ofrNsJLaxdGaKJF8obA7ltosrBkJqtQ7J2Pah4egTNMg==)

下载完成以后在 ![](http://imgsrc.baidu.com/forum/w%3D580/sign=afb1f0d5acc27d1ea5263bcc2bd4adaf/01f82a3b5bb5c9ea6e404192dd39b6003bf3b3f7.jpg)

这个文件夹新建一个leweiclient的文件夹把下载的文件复制到里面
第八

打开arduino IDE
点 文件，示例 ![](http://imgsrc.baidu.com/forum/w%3D580/sign=cbee7b7a53b5c9ea62f303ebe538b622/b4a810dbb6fd52662f637165a318972bd50736de.jpg)

打开以后修改自己的API，把下面的代码下载以后就可以试试了，微信也可以控制，有什么不明白的地方再联系我了扣扣三六九吧腰吧四六吧

![](http://imgsrc.baidu.com/forum/w%3D580/sign=7f64084f04f3d7ca0cf63f7ec21fbe3c/e46393a1cd11728ba056c353c0fcc3cec3fd2c2f.jpg)
![](http://imgsrc.baidu.com/forum/w%3D580/sign=9743f195bb1c8701d6b6b2ee177f9e6e/c57c13292df5e0fe2015c670546034a85edf7211.jpg)

#include &lt;SPI.h>
#include &lt;Ethernet.h>
#include &lt;LeweiTcpClient.h>
#include &lt;EEPROM.h>

#define LW_USERKEY "你的API"
#define LW_GATEWAY "01"

#define LED_PIN 4//plug led in the d3,gnd->gnd// 我发现LED接在数字口3会断线，后来改到4口就好了，其他的端口还没试过

//byte mac[] = {0x74,0x69,0x69,0x2D,0x30,0x31};
//IPAddress ip(192,168,1, 15);
//IPAddress mydns(8,8,8,8);
//IPAddress gw(192,168,1,1);
//IPAddress subnet(255,255,255,0);

LeweiTcpClient *client;

void setup()
{
pinMode(LED_PIN, OUTPUT);
//digitalWrite(3,LOW);

Serial.begin(57600);
//you can use 3 ways to init your network
//1.simplest
client = new LeweiTcpClient(LW_USERKEY, LW_GATEWAY);
//2.full setting for your network
//client = new LeweiTcpClient(LW_USERKEY, LW_GATEWAY,mac,ip,mydns,gw,subnet);

//test1 is the function you write below to handle your program
//"testFunction" is the function name you set on website: [http://www.lewei50.com/](http://jump.bdimg.com/safecheck/index?url=x+Z5mMbGPAvE9iZcxuq5DzyPat3fA+S2EnAODBieKkrY7nCoCP8AfPgYO8TwLUwo1o9Qk+WDn6dLUGHYnkhxVR7FOdJLd7VaeDlxNLaznq5UEqcRZo44vHnPwGfiBcHEMDxm7iZ2BjQ=)
//on "controll command manager" menu
//we test transfer 1-5 para from website(you defined on it) to your arduino
//enjoy it

// UserFunction uf1(functionIWrote,"functionNameDefinedOnWeb");
//client->addUserFunction(uf1);
UserFunction uf2 (ledOn,"ON");
client->addUserFunction(uf2);
UserFunction uf3 (ledOff,"OFF");
client->addUserFunction(uf3);

/*
enable easySetupMode will open the port 80 of this board,
you can setup your apikey and gateway number via  [http://your_arduino_ip/](http://jump.bdimg.com/safecheck/index?url=x+Z5mMbGPAsTLDKhf4r0BSYPu8G2Cg9nMCZGZfGIZGPY7nCoCP8AfPgYO8TwLUwo1o9Qk+WDn6dLUGHYnkhxVR7FOdJLd7VaeDlxNLaznq5UEqcRZo44vHnPwGfiBcHEMDxm7iZ2BjQ=)
the key and number will be burned into board's eeprom
after setting you need to restart your arduino.
after reboot,you can comment this line for fasten your board.
this library will will use apikey and gateway number in eeprom FIRST,if it exsit.
you can send empty value from the browser to wipe the data in eeprom.
*/
//client->easySetupMode(true);
;
}

void loop()
{
client->keepOnline();
// client->setRevCtrlMsg("true","on");
//digitalWrite(12,HIGH);
// client->setRevCtrlMsg("true","off");
//digitalWrite(12,LOW);

}

//function functionIWrote use 1 parameter,on the website,it point to "p1"
void functionIWrote(char * p1)
{
client->setRevCtrlMsg("true","message to server");
// client->sendSensorValue("tcp1",pi);
Serial.println(p1);
}

//function without parameter
void ledOn()
{
client->setRevCtrlMsg("true","on");
digitalWrite(LED_PIN,HIGH);
}
void ledOff()
{
client->setRevCtrlMsg("true","off");
digitalWrite(LED_PIN,LOW);
}

---

Source: https://maker.wiznet.io/chen/projects/%E5%85%A5%E6%89%8Barduino%E5%92%8Cw5100%E5%92%8C%E4%B9%90%E4%B8%BA%E7%89%A9%E8%81%94/
