How to create your own custom AT command in ESP8266 Module?
First of all I'll brief you about what I'm doing:
My project includes a device which will act as AP server(Access Point and Server) to which other device can connect and through UDP share some status messages to the AP server. However, number of devices in the vicinity will be quite high, can be more than 100 and all of them will try to connect to AP server simultaneously.
As a AP server, I'm using ESP8266. Since, we know that ESP8266 module has limitation in connecting to client devices(Max 4~5 clients can connect at a time), my first question is how to connect multiple clients to AP server, share some message and then disconnect the connection to allow other clients.
To this question, I'm thinking that if I can disconnect the clients from AP itself using deAuth() once the messages are shared then I can allow other Clients to connect. But there is no AT commands to force a client to disconnect by deAuth or through any other mode. That brings to my main question, how to create custom AT commands in ESP module?
EDIT To explain the scenario a bit more, the ESP device will be placed in the SHOP. Users coming in to the SHOP will connect to the ESP module through their mobile App automatically and share some data. Since, random amount of users may come to the shop and if I do not disconnect them from ESP, other users won't be able to share the info.作者: aksonlyaks 的来源 发布者： 2017 年 9 月 15 日
Well, your fundamental problem is that you want to connect 100 devices to your ESP8266, which will only ever be able to handle 4 at a time (source: http://espressif.com/sites/default/files/documentation/2c-esp8266_non_os_sdk_api_reference_en.pdf, p.151). Two ways to solve it: Either change your strategy so that e.g. only every 1 client connects to your AP which has all the results of the other 100, or let them connect one-by-one. Note that connecting, sending data and disconnecting will take about 5 seconds per device (optimistically), so your 100 devices will take 8:20 minutes to all send 1 piece of data.
To the solution: You can actually create your own AT commands. As is seems the AT Firmware is "open-source" and you can your own commands in the list of commands, as described here: http://www.verelec.nl/?page_id=557. But if you only need certain functionalities and not everything the AT firmware has to offer, it is probably the best if you program the ESP8266 directly, e.g. by using the Espressif Non-OS or RTOS or esp-open-rtos SDKs. From there you have total control, you can open the AP, the UDP server, and implement deauthentication.
There is however no built-in function to disconnect a client. However, the exists the possibility to mount a WiFi De-Auth attack against your own clients. There are multiple projects which demonstrate a deauthentication attack against arbitrary networks -- just make sure you run the attack only against your own network, everything else is illegal. Project links: https://github.com/spacehuhn/esp8266_deauther, https://github.com/RandDruid/esp8266-deauth. They all use the
wifi_pkt_freedom() function to send arbitrary WiFi packets into the air. But I don't reallysee the purpose of it -- why have the AP disconnect clients if the clients disconnect automatically after they sent the data?
Another idea is to coordinate the connection order of your clients somehow. This can be done by e.g. using a global clock time (acquired from a RTC e.g.). You can e.g. say that device #1 upto #4 can only ever send between minutes 0 and 5 of the current hour, device #5 to #8 between minutes 5 and 10, etc. A different approach would be to implement some kind of ALOHA like protocol; This is a (general) mechanism with which multiple parties can access a resource (e.g. a radio channel) when only 1 of them can only be using it at time. You can find an explanation of that at http://ecomputernotes.com/computernetworkingnotes/communication-networks/what-is-aloha.
I hope this gives you some ideas.作者: Maximilian Gerhardt 发布者: 2017 年 9 月 15 日