Summary of the invention
In view of the above drawbacks of the prior art, the technical problems to be solved by the present invention are: Internet of Things Wi-Fi module
A problem of router can only be connected, and can not be automatically switched.
To achieve the above object, the present invention provides a kind of Internet of Things Wi-Fi module network self-adapting switching method:
Mobile terminal is established the link with Internet of Things Wi-Fi module;
Acquisition for mobile terminal and the information for saving router carry out data combination to the route-map of acquisition, and by group
It closes information and is sent to Internet of Things Wi-Fi module;
Internet of Things Wi-Fi module receives the combined information that mobile terminal issues, and judges the signal strength of router, according to
Signal strength connects router.
The mobile terminal is established the link with Internet of Things Wi-Fi module and is sequentially included the following steps:
A1. Internet of Things Wi-Fi module starts hot spot function, establishes socket server;
A2. the hot spot of mobile terminal connection Internet of Things Wi-Fi module initiates to link to the port of Internet of Things Wi-Fi module
Request;
A3. Internet of Things Wi-Fi module end receives and receives the linking request of mobile terminal.
The acquisition for mobile terminal and the information for saving router carry out data combination to the route-map of acquisition, and
Combined information is sent to Internet of Things Wi-Fi module to sequentially include the following steps:
B1. mobile terminal connection obtains the information of router;
B2. mobile terminal carries out data combination to the information of acquisition;
B3. mobile terminal is packaged data splitting and is sent to Internet of Things Wi-Fi module by link.
The Internet of Things Wi-Fi module receives the combined information that mobile terminal issues, and judges the signal strength of router,
Router is connected according to signal strength to sequentially include the following steps:
C1. Internet of Things Wi-Fi module receives the packing data splitting of mobile terminal;
C2. Internet of Things Wi-Fi module scans router and obtains route-map;
C3. Internet of Things Wi-Fi module compares the received route-map for being packaged data splitting and scanning: more when having
The identical route-map of group, then compare the signal strength of multiple groups router, connects router according to signal strength, executes C5;
When there is one group of identical route-map, C4 is executed;When no identical route-map, C2 is executed;
C4. Internet of Things Wi-Fi module connects router;
C5. Internet of Things Wi-Fi module detects the signal strength of itself and the connection status of router and connect router, inspection
Surveying module includes connecting detection module and signal strength detection module.
The connecting detection module is used to detect the connection of Internet of Things Wi-Fi module and router: as Internet of Things Wi-
Fi module and router disconnect, then execute C2;When Internet of Things Wi-Fi module is connect with router, then complete to switch.
The signal strength detection module is for detecting the signal strength that Internet of Things Wi-Fi module is connected with router, side
Method are as follows: setting interval time T, Internet of Things Wi-Fi module execute a Wi-Fi scanning at interval of T;When signal strength is less than
80dbm executes C2;When signal strength be greater than or equal to 80dbm, then complete to switch.
Data combination, which includes mobile terminal, carries out the combination of first time data to the route-map of acquisition, format and suitable
Sequence are as follows: length, BSSID data, the length of password, code data of BSSID.This data is grouped together into data
Rdata, length Rlen.
When packaged data, the random integers of generation 1 to 7 move to left secret value position shape to Rdata datacycle as secret value
At data RdataA, length is Rlen.
The data combination includes second of data combination, and format and sequence are as follows: serial data total length Alen, WiFi
The data length of module I D, the ID of the communication module needed to configure, secret value, RdataA, data check value;By this data group
It is combined to form serial data Adata, total length is Alen;The data for removing last 1 byte in Adata data are carried out
Verification, the value obtained are included in data check value.
Data splitting sending method are as follows: discrete mode is carried out data transmission based on udp protocol, is based on multicast address and multicast
Length transmits data.
The beneficial effects of the present invention are: under the premise of not increasing hardware, acquisition for mobile terminal and the information for saving router,
Data combination is carried out to route-map, and combined information is sent to Internet of Things Wi-Fi module;Internet of Things Wi-Fi module is protected
The information for staying multiple routers, the router for detecting the signal strength of each router, and selecting connection signal intensity good;Internet of Things
Net Wi-Fi module detects itself connection between router simultaneously: disconnecting when with router, then continues to execute scanning step
Suddenly.Internet of Things Wi-Fi module realizes switches over connection between the multiple routers.
It should be understood that above general description and following detailed description be only it is exemplary and explanatory, not
It can the limitation present invention.
Specific embodiment
Present invention will be further explained below with reference to the attached drawings and examples:
As shown in Figs 1-4, a kind of Internet of Things Wi-Fi module network self-adapting switching method: mobile terminal and Internet of Things Wi-
Fi module establishes the link;
Acquisition for mobile terminal and the information for saving router carry out data combination to the route-map of acquisition, and by group
It closes information and is sent to Internet of Things Wi-Fi module;
Internet of Things Wi-Fi module receives the combined information that mobile terminal issues, and judges the signal strength of router, according to
Signal strength connects router.
The mobile terminal is established the link with Internet of Things Wi-Fi module and is sequentially included the following steps:
A1. Internet of Things Wi-Fi module starts hot spot function, establishes socket server;
A2. the hot spot of mobile terminal connection Internet of Things Wi-Fi module initiates to link to the port of Internet of Things Wi-Fi module
Request;
A3. Internet of Things Wi-Fi module end receives and receives the linking request of mobile terminal.
The acquisition for mobile terminal and the information for saving router carry out data combination to the route-map of acquisition, and
Combined information is sent to Internet of Things Wi-Fi module to sequentially include the following steps:
B1. mobile terminal connection obtains the information of router;
B2. mobile terminal carries out data combination to the information of acquisition;
B3. mobile terminal is packaged data splitting and is sent to Internet of Things Wi-Fi module by link.
The Internet of Things Wi-Fi module receives the combined information that mobile terminal issues, and judges the signal strength of router,
Router is connected according to signal strength to sequentially include the following steps:
C1. Internet of Things Wi-Fi module receives the packing data splitting of mobile terminal;
C2. Internet of Things Wi-Fi module scans router and obtains route-map;
C3. Internet of Things Wi-Fi module compares the received route-map for being packaged data splitting and scanning: more when having
The identical route-map of group, then compare the signal strength of multiple groups router, connects router according to signal strength, executes C5;
When there is one group of identical route-map, C4 is executed;When no identical route-map, C2 is executed;
C4. Internet of Things Wi-Fi module connects router;
C5. Internet of Things Wi-Fi module detects the signal strength of itself and the connection status of router and connect router, inspection
Surveying module includes connecting detection module and signal strength detection module.
The connecting detection module is used to detect the connection of Internet of Things Wi-Fi module and router: as Internet of Things Wi-
Fi module and router disconnect, then execute C2;When Internet of Things Wi-Fi module is connect with router, then complete to switch.
The signal strength detection module is for detecting the signal strength that Internet of Things Wi-Fi module is connected with router, side
Method are as follows: setting interval time T, Internet of Things Wi-Fi module execute a Wi-Fi scanning at interval of T;When signal strength is less than
80dbm executes C2;When signal strength be greater than or equal to 80dbm, then complete to switch.
Data combination, which includes mobile terminal, carries out the combination of first time data to the route-map of acquisition, format and suitable
Sequence are as follows: length, BSSID data, the length of password, code data of BSSID.This data is grouped together into data
Rdata, length Rlen.
When packaged data, the random integers of generation 1 to 7 move to left secret value position shape to Rdata datacycle as secret value
At data RdataA, length is Rlen.
The data combination includes second of data combination, and format and sequence are as follows: serial data total length Alen, WiFi mould
The data length of block ID, the ID of the communication module needed to configure, secret value, RdataA, data check value;It combines this data
Serial data Adata is formed together, and total length is Alen;School is carried out to the data for removing last 1 byte in Adata data
It tests, the value obtained is included in data check value.
Data splitting sending method are as follows: discrete mode is carried out data transmission based on udp protocol, is based on multicast address and multicast
Length transmits data.
The information of the router is main are as follows: the SSID and password of router, SSID are Service Set
The abbreviation of Identifier, Chinese mean that service set, and the Chinese of password means that password;The socket
Server is port server, and two on network program realizes the exchange of data by a two-way communication connection, this
One end of connection is known as a socket;The BSSID, also referred to as BSS, BSS are the abbreviations of Basic Service Set, often
A BSS can be endowed a BSSID.The mobile terminal can cooperate APP to obtain, save the information of router, can also lead to
It crosses APP and issues router combined information, naturally it is also possible to the information of router is obtained and issued with other similar approach, this is category
In the prior art, this will not be repeated here.
Specific step is as follows for the present embodiment:
1. Internet of Things Wi-Fi module starts softAP hot spot function, the TCP socket of mono- fixed port of Lian Li
Server, and execute bind and linsten, i.e. the linking request that monitoring client is sent;
2. mobile phone connects the softAP hot spot of Wi-Fi module, APP is opened, the TCP socket of client is established, and
TCP connection request is initiated to fixed port identical with Internet of Things Wi-Fi module end;
3. Internet of Things Wi-Fi module end receives and receives TCP connection request, in this way, Internet of Things Wi-Fi module is built with mobile phone
The connection of TCP is stood;
4. cell phone application obtains the SSID of connected router, and prompts user to input correct password, and to routing
The SSID and password of device carry out encryption according to rule and information combines;
5. cell phone application combines information and is sent to Internet of Things Wi-Fi module end by TCP socket;
6. Internet of Things Wi-Fi module termination receives the information combination of cell phone application, and is solved according to information rule of combination
Analysis to obtain the SSID and password of the router of router, and saves the SSID and password of this group of router
Into memory, directly it can read and use from memory so as to subsequent;
7. Internet of Things Wi-Fi module closes softAP hot spot function, the SSID and password taken using above-mentioned steps
Be connected to corresponding router, meanwhile, the TCP socket server of mono- fixed port of Lian Li, and execute bind and
The linking request that linsten, i.e. monitoring client are sent;
8. mobile phone disconnects the connection with Wi-Fi module softAP, then is connected to same routing with Internet of Things Wi-Fi module
Device forms the local area network of one " Internet of Things Wi-Fi module --- the first router --- mobile phone ", and cell phone application is opened, and establishes
The TCP socket of client, and TCP connection request is initiated to fixed port identical with Internet of Things Wi-Fi module end;
9. Internet of Things Wi-Fi module termination is requested by TCP connection, cell phone application prompt user sequentially inputs the second router
With SSID, password of third router, and to the SSID and password of input carry out encryption and information combine;
10. SSID, password combined information of the second router and third router are passed through TCP by cell phone application
Socket is sent to Internet of Things Wi-Fi module end, and Internet of Things Wi-Fi module receives the information combination of cell phone application, and according to information
Rule of combination is parsed, to obtain SSID, password of the second router and third router, and this two groups of routings
The SSID and password of device are saved in memory.
The Chinese of the bind means that binding;The linsten Chinese means that monitoring;The client Chinese meaning
Think of is: client.
Through the above steps, SSID of the Internet of Things Wi-Fi module the first router, the second router and third router
In the memory being saved in password, the first router SSID, password is the distribution by Internet of Things Wi-Fi module
What function was taken, SSID, password of the second router and third router be by " Internet of Things Wi-Fi module ---
What the local area network of one router --- mobile phone " was taken, it can also be taken by the wide area network in other similar connections cloud.This is existing
There is technology, this will not be repeated here.
As shown in figure 4, steps are as follows for the multiple network self-adapting handover schemes of the Internet of Things Wi-Fi module of the present embodiment:
1. Internet of Things Wi-Fi module powers on;
2. Internet of Things Wi-Fi module reads in memory whether have router SSID and password: if unread arrive, saying
Bright Wi-Fi module does not pass through distribution, executes distribution process;If having read router SSID and password, just hold
The scanning function of row Internet of Things Wi-Fi module scans surrounding hot spot, router SSID, signal strength in preservation scanning result
Information;
3. Internet of Things Wi-Fi module compares the all-router SSID in router SSID and memory in scanning result:
If continuing to execute scanning without identical router SSID;If there is one group of same router SSID in comparison result, connect
Connect this router;If there are more same router SSID in comparison result, compare the signal strength of router in scanning result,
The strong router of select-out signal intensity, is attached;
4. after Internet of Things Wi-Fi module is connected to router, connecting detection module can judge it by existing mechanism
With the connection of router Internet of Things Wi-Fi module can be judged with the primary connection of detection in 1 minute such as without existing mechanism
Whether disconnect the connection with router: as disconnected, then jumping to Wi-Fi module scanning step;Such as connection, then it is not processed;
5. connecting detection module carries out, signal strength detection module executed a Wi-Fi module every 5 minutes
Scanning motion, judge the signal strength of connected router: when signal strength be less than 80dbm, illustrate that signal is very weak, jump
To Wi-Fi module scanning step, the good router of signal strength is found;When signal strength be more than or equal to 80dbm, then do not do and locate
Reason.
The information combination are as follows: the combination of first time data, format and sequence are as follows: the length of BSSID, BSSID number
According to, the length of password, code data, the length of BSSID is 1 byte, and BSSID data length is BSSID len byte, password
Length is 1 byte, and code data length is Password length byte.This data is grouped together into data Rdata,
Length is Rlen.In packaged data, the random integers of generation 1 to 7 are left to Rdata datacycle as secret value KeyType
KeyType formation data RdataA are moved, length is Rlen.Second of data combination, format and sequence are as follows: data overall length
Spend Alen, the data length of WiFi module ID, the ID of the communication module needed to configure, secret value, RdataA, data check value
CH, total length of data Alen length are 1 byte, and the data length of WiFi module ID is 1 byte, the communication module needed to configure
ID length be Dev ID len byte, secret value length be 1 byte, RdataA length be Rlen byte, data check value CH
Length is 1 byte.This data is grouped together into all data Adata, the value of total length Alen is 1+1+Dev ID
len+1+Rlen+1;The data for removing last 1 byte in Adata data are verified, the value obtained is included in data check
Value CH, the check value CH length are 1 byte;Adata is exactly the overall data for needing to transmit, and length Alen, Alen are maximum
Length is 255;The data verification method of data check value CH is generated by being calculated using XOR operation data, illustrates generation
Code is as follows: for (int i=0;i<len;I++) ch^=data [i];CH initial value is 0.Data splitting sending method are as follows: from
It dissipates mode to carry out data transmission based on udp protocol, data, multicast port number is transmitted based on multicast address and multicast length are as follows:
5040.The Adata data packet of mono- group of every 12bit formation one from front to back is sent, each packet has a serial number, and serial number is from 0
Start, is sequentially 0, the serial number of 1,2,3,4 ... the last one packet are as follows: (Alen*2+2)/3-1.Serial number with two numbers replace N1 and
N2 is N1*7+N2, the number that N2 is 0 to 6.For the packet of label first, the N2 of the first packet is 7.Each packet is complete comprising one
Byte data Ai and 4 bit data Bi, when the last one bag data is less than 12bit, insufficient is 0 entirely.To the number of each packet
According to the check code CH for carrying out verification one byte of generation.Verification rule is data Ai and data Bi XOR operation.Assuming that a packet
Serial number N1i, N2i, check code Ci, data Ai are as follows: 8bit), data Bi are as follows: 4bit.Multicast address starts with 229, is
229.x1.x2.x3, data length Len are the length for sending data for a multicast address, utilize x1, x2, x3, Len
To transmit the data of a packet.Highest two of x1 are set as 0, and highest two are as follows: the 8th and the 7th, the 6th record data Ai's
Highest order, the 5th of the 5th record check code Ci;The data of x2 are the 7th of data Ai;The 4th record data Bi's of x3
Data, the value of the 5th, the 6th and the 7th record number N2i;Length Len is N1+1.It only needs to compare when communication module compares
Latter 5 of check code.Here is subpackage example: initial data 0x12 0x34 0x56 0x78 0x9A is divided into 4 bag datas, respectively
For 0x12 0x03,0x56 0x04,0x78 0x09,0x00 0x0A, serial number N1 and serial number N2 respectively correspond 07,01,02,
03。
The preferred embodiment of the present invention has been described in detail above.It should be appreciated that those skilled in the art without
It needs creative work according to the present invention can conceive and makes many modifications and variations.Therefore, all technologies in the art
Personnel are available by logical analysis, reasoning, or a limited experiment on the basis of existing technology under this invention's idea
Technical solution, all should be within the scope of protection determined by the claims.