入手arduino和W5100和乐为物联
2017-07-26 23:15
375 查看
转自: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);
}
入手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);
}
相关文章推荐
- Arduino 入手
- [转]Arduino学习笔记:2560+W5100试验实时室温对Pachubbe.com推送
- Arduino上传数据至贝壳物联并与FPGA进行交互
- 如何用arduino+ethernet shield(W5100)与yeelink结合5分钟实现传感器数据web上传
- 【故障解决】W5100在Arduino的软件及驱动更新
- 手机app 控制 arduino(w5100)教程(step by step)
- ARDUINO W5100 WebClient 测试
- ARDUINO W5100 WebServer测试
- 用Arduino Uno和W5100做一个iphone推送提醒装置
- (升级版)arduino uno + dht11 + 舵机 +w5100网络模块 温度 网络控制舵机
- 指示灯组与3个复位按钮的介绍Arduino Yun快速入门教程
- 物联12:射频识别距离-耦合类型
- 物联12:rfid超高频和微波天线技术
- Arduino中LED灯实现256中颜色的渐变
- Arduino可穿戴开发入门教程(大学霸内部资料)
- structs2快速入手
- Arduino入门套件 Arduino UNO R3
- Scratch源码使用ArduinoConnector.ane与串口通信
- arduino 与 703n openwrt的故事
- cocos2dx 3.4 入手cocos2dx 第一次总结