入手arduino和W5100和乐为物联

转自:http://tieba.baidu.com/p/4673033289

入手arduino和W5100已经有一段时间,朝着物联网的方向努力百度了好几天,试过Yeelink和乐联网均未成功,后来在一个百度贴吧中看到了这个帖子,抱着试一试的心态研究了一下,几经周折终于成功控制LED,在这里感谢http://tieba.baidu.com/p/4500765226这个帖子的楼主给了我重生的希望









下面进入正题






第一先在 http://www.lewei50.com 申请账号,估计这个大家都不用我教了吧
第二步在“我的物联”列表下的“我的设备”中新建设备如图,名字可以自己定义



第三
在“传感器与控制器”新建一个传感器如图,设备选择刚才新建的设备,标识就写led3




第四,点击“智能物联”,点击 控制命令管理 ,新建两个命令




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




第五
添加执行单元
执行单元管理新建两个










第六 
自定义微信命令








第七


关键的一步来了,首先下载乐为的库文件,我整理了一下在这里 http://pan.baidu.com/s/1nv92pvj


下载完成以后在

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


打开arduino IDE
点 文件,示例



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











#include <SPI.h>
#include <Ethernet.h>
#include <LeweiTcpClient.h>
#include <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/
//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/
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);
}
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值