Using APP to Reverse Control Arduino+W5100

details

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 ).

LED与Arduino连线

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

Github下载程序

 

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

.leweiclient里面文件

 

3.2 Change usrkey

Run Arduino.exe,open File-Examples-Leweiclient-control

Arduino打开control(1)

userkey

 

First, you need to register a account in lewei (http://www.lewei50.com/).Then, get a unique  userkey from it.

define_userkey

 

Change the userkey with your own userkey.

动态和静态IP

 

“#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

DNS IP设置

3.3 Choose different control method

(1) lwc = new LeWeiClient(LW_USERKEY, LW_GATEWAY,MY_NAME, MY_DESC, my_addr, (LeWeiClient::flag)((LeWeiClient::isControlled)|(LeWeiClient::internetAvailable)));
(2) lwc = new LeWeiClient(LW_USERKEY, LW_GATEWAY,MY_NAME, MY_DESC, my_addr, (LeWeiClient::flag)(LeWeiClient::isControlled));
(3) lwc = new LeWeiClient(LW_USERKEY, LW_GATEWAY,MY_NAME, MY_DESC, my_addr, (LeWeiClient::flag)(LeWeiClient::none));
3.3.1 If set the gateway can’t control back,run the following sentence:
lwc = new LeWeiClient(LW_USERKEY, LW_GATEWAY,MY_NAME, MY_DESC, my_addr, (LeWeiClient::flag)(LeWeiClient::none));
At the same time,mask the other sentences.
Then the gateway configs like follows:
不控制网关
It shows that the gateway is uncontrolled.
3.3.2 Phone is at the same segment with Arduino+W5100
Run the following sentence:
lwc = new LeWeiClient(LW_USERKEY, LW_GATEWAY,MY_NAME, MY_DESC, my_addr, (LeWeiClient::flag)(LeWeiClient::isControlled));
“LeWeiClient::isControlled”means the gateway can be controlled.
同网段控制网关
3.3.3 Phone isn’t at the same segment with Arduino+W5500
Run the following sentence:
lwc = new LeWeiClient(LW_USERKEY, LW_GATEWAY,MY_NAME, MY_DESC, my_addr, (LeWeiClient::flag)((LeWeiClient::isControlled)|(LeWeiClient::internetAvailable)));
跨网段控制网关
In this way,you should map your Arduino+W5100 with your router.
NAT映射
3.4 Change the code
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;
        }
};

 

3.5 Control the Arduino+W5100 through APP
Download the Lewei app.
The same segment:
Enter the controlling interface,it should shows like this:
 同网段APP
The different segment:
跨网段APP
Now,you can control the LED switch with APP.

 

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 ).

LED与Arduino连线

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

Github下载程序

 

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

.leweiclient里面文件

 

3.2 Change usrkey

Run Arduino.exe,open File-Examples-Leweiclient-control

Arduino打开control(1)

userkey

 

First, you need to register a account in lewei (http://www.lewei50.com/).Then, get a unique  userkey from it.

define_userkey

 

Change the userkey with your own userkey.

动态和静态IP

 

“#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

DNS IP设置

3.3 Choose different control method

(1) lwc = new LeWeiClient(LW_USERKEY, LW_GATEWAY,MY_NAME, MY_DESC, my_addr, (LeWeiClient::flag)((LeWeiClient::isControlled)|(LeWeiClient::internetAvailable)));
(2) lwc = new LeWeiClient(LW_USERKEY, LW_GATEWAY,MY_NAME, MY_DESC, my_addr, (LeWeiClient::flag)(LeWeiClient::isControlled));
(3) lwc = new LeWeiClient(LW_USERKEY, LW_GATEWAY,MY_NAME, MY_DESC, my_addr, (LeWeiClient::flag)(LeWeiClient::none));
3.3.1 If set the gateway can’t control back,run the following sentence:
lwc = new LeWeiClient(LW_USERKEY, LW_GATEWAY,MY_NAME, MY_DESC, my_addr, (LeWeiClient::flag)(LeWeiClient::none));
At the same time,mask the other sentences.
Then the gateway configs like follows:
不控制网关
It shows that the gateway is uncontrolled.
3.3.2 Phone is at the same segment with Arduino+W5100
Run the following sentence:
lwc = new LeWeiClient(LW_USERKEY, LW_GATEWAY,MY_NAME, MY_DESC, my_addr, (LeWeiClient::flag)(LeWeiClient::isControlled));
“LeWeiClient::isControlled”means the gateway can be controlled.
同网段控制网关
3.3.3 Phone isn’t at the same segment with Arduino+W5500
Run the following sentence:
lwc = new LeWeiClient(LW_USERKEY, LW_GATEWAY,MY_NAME, MY_DESC, my_addr, (LeWeiClient::flag)((LeWeiClient::isControlled)|(LeWeiClient::internetAvailable)));
跨网段控制网关
In this way,you should map your Arduino+W5100 with your router.
NAT映射
3.4 Change the code
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;
        }
};

 

3.5 Control the Arduino+W5100 through APP
Download the Lewei app.
The same segment:
Enter the controlling interface,it should shows like this:
 同网段APP
The different segment:
跨网段APP
Now,you can control the LED switch with APP.

 

COMMENTS

Please Login to comment
  Subscribe  
Notify of