Android Development-Smart home series "(ii): Configure the WiFi module with your phone

Source: Internet
Author: User

In the actual development, I developed this app is used to connect the thermostat, and the thermostat control. There is a picture of the card, haha.
  

Previous article "Android Development-smart home series" (a): The principle of smart home in the end of the text to write:
Mobile app control smart thermostat on two steps: One is through the mobile phone, let WiFi module access to the network, but through the network, using mobile phone to send instructions to the module. In this article, let's cover the first step.

"Timing Diagram"

  

"Concept" "two modes":

AP: The wireless access point, which is the central node of a wireless network. The wireless router that is usually used is an AP, and other wireless terminals can be connected to each other via the AP.

STA: The wireless station, which is the terminal of a wireless network. such as notebook computers, PDAs and so on.

"Two Ports"

48899 Port: The port of the WiFi module (usr-wifi232-s) I use
49000 port: Remove my WiFi (usr-wifi232-s) module, other WiFi module port

"IP Address"

Broadcast address: x.x.x.255 (for example: 255.255.255.255)
WiFi module Default ip:10.10.100.254
After access to the router, the IP is dynamically assigned by the router.

"Implementation Process description"

Searching for WiFi modules using UDP broadcast mode

    • The first stage is to search the WiFi module in AP mode.
    • The second stage is to search the WiFi module in STA mode.

First Stage :
When the module is operating in AP mode, a UDP port for receiving the "Fast Networking protocol Command" is turned on, with a port number of 48999 (default IP of factory setting is 10.10.100.254)

    1. Via UDP broadcast (broadcast address: x.x.x.255, Port 48899), send Hf-a11assisthread (this password can be set by AT+ASWD command)
      (This can also be a unicast search, the destination address: 10.10.10.254, Port 48899, command unchanged)
    2. After the module receives the instruction, if the password is correct, the IP address, MAC address, and module name are sent to the source address (unicast: Port 48899).
    3. After receiving the IP address and MAC address returned by the module, send back a "+ok" immediately after receiving the module and enter the connection status.
    4. After entering the connection state, the module can receive the network at instruction normally. For example: Set network protocol parameters: at+netp=tcp,client,30000,x.x.x.x set STA network parameters: AT+WANN=DHCP

Transition phase:

    1. UDP Broadcast (port: 49000) Send instruction FF 00 01 01 02 (Hex)
    2. The module returns the routing list after receiving the instruction
    3. Sends the user-selected SSID (route name) and key to the module (port: 49000), the module connects to this route, turns into STA mode, and echoes an instruction FF 00 03 82 01 01 87

Phase II:
  
In STA mode, we want to find this WiFi module and send it on, off and other operating instructions. Step is the same as the first stage, but the IP address returned will be different. Module as the STA link to the route, thought that the IP address of the module is assigned by the router, not to determine the IP address, so the phone can not establish a connection with the module, it is necessary to use a broadcast search, to obtain the module in the STA mode address.

Summary

With basic ideas, understanding and familiarity with the entire connection and communication process, the next step is to have a simpler and more basic part, including the basics of UDP communication and conversion between characters and hexadecimal. Throughout the development process, the above content of the understanding is 1.1, just started to tell me that the leader of what do not understand, gave me a pile of information and tools do not know how to use, but the development of the development is clear. The development process also consulted the WiFi module production company engineers, solve my problem. When encountering a problem, still want to think more ways, there will always be a solution to see if you have the determination and confidence to solve it.

Android Development-Smart home series "(ii): Configure the WiFi module with your phone

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.