1. Introduction
This example is an application of LeWei Website using Arduino+W5100. Author uses an APP on phone to control a switch connected with Arduino+W5100.
Hardware: Arduino UNO W5100 shield
APP: Lewei APP open.lewei50.com/home/sitecontent/ydkhd
System: Lewei Open Platform
2. Hardware connection
Connect the two pins of LED to ports 6 and 7 on the Arduino Board(these two ports are defined in Arduino program, you can choose other ports,but these new ports must be connected with the LED pins ).
3.Get and correct the Arduino formwork program.
3.1 Click the URL and click “ZIP”button to download the doc named “master.zip”.
https://github.com/lewei50/leweiclient
Then,unzip it and open the file of Arduino IDE/libraries.Build a file named “leweiclient”,then copy the docs in “LeweiClient-master” to the new file
3.2 Change usrkey
Run Arduino.exe,open File-Examples-Leweiclient-control
First, you need to register a account in lewei (http://www.lewei50.com/).Then, get a unique userkey from it.
Change the userkey with your own userkey.
“#if 0″means DHCP, “#if 1” means Static IP .
IP Address myip :Config Arduino IP manually,and it should be the same with “my_addr[50]”
IPAddress dnsip: Input the DNS IP address.It could be found on your router of WAN port status.
IPAddress gateway
3.3 Choose different control method
dummy_act the_act("DA", "dummy actuator", "dummy2"); dummy_act the_act2("DA2", "dummy actuator", "dummy1"); class dummy_act: public LeWeiActuator { private:char led; public: dummy_act( const char *id, const char *type, const char *name) : LeWeiActuator(id, type, name) {}; virtual bool updateValue(char* id,int val) { Serial.print("dev id = "); Serial.println(id); if(!strcmp(id,"DA")) { Serial.println("handle da routin"); digitalWrite(ledPin_da, val); } if(!strcmp(id,"DA2")) { Serial.println("handle da2 routin"); digitalWrite(ledPin_da2, val); } Serial.print("update actuator "); Serial.println(val); led=val; return val; } virtual bool getValue(int *val) { static int i = 0; *val = led; return true; } };
COMMENTS