I am creating a geocache that opens when you connect to it via wifi. I just need to be able to count the number of users connected to the esp8266. I have flashed it using with the latest version of NodeMCU.
Asked
Active
Viewed 2,532 times
0
-
Oh, neat idea :) What exactly do you mean by "latest version of NodeMCU"? Is it relevant for this question? Side note: you should not download any of the old pre-built binaries from the NodeMCU GitHub repository as they're hopelessly outdated. Try http://frightanic.com/nodemcu-custom-build/index.php instead. – Marcel Stör Nov 16 '15 at 12:35
-
I will do that exactly. This is my first shot trying out a 8266 chip. I loaded it with the latest firmware I could find. I have a few ideas for projects but for now I just need that one command. Originally, the cache will only open once you worked a puzzle on the web page, but I cannot figure out how to get my iPhone to pull up the web page. I can however, connect to the esp and get address... maybe I can accomplish the same thing with a "ping" of the connecting item's ip address.... hmmm but if you know the cmd to find out the count connections to the device, that would be great – Jerry H Nov 17 '15 at 03:39
-
I still don't quite get it I think. Is the esp8266 running an HTTP server that people connect to or does it act like a WiFi access point? – Marcel Stör Nov 17 '15 at 07:55
-
Marcel, the esp8226 is running in a AP mode AND serves out a HTTP server. On my first try I found and tweeked a page that would turn on one of the GPIO pins. Worked great but... my ipod could only connect to the ESP. It could not read the HTML. So, I will just make the SSID and password combination the "ANSWER" to the geocache and once you connect, that part of the puzzle will be solved. I am thinking that you will have to do like 3 or 4 more things to complete the puzzle and open the lock. we shall see... I am cacheteam6 if you want to follow my geocaches. Jerry- – Jerry H Nov 18 '15 at 03:26
-
1Sounds like you're building a captive portal. Check this out: https://github.com/robertfoss/esp8266_nodemcu_wifi_setup – Marcel Stör Nov 18 '15 at 07:13
2 Answers
0
Can't remember from the top of my head if NodeMCU has something like that builtin (I'm guessing not) but you can easily keep track of your clients on the .connect event, every time you get that event fired increase your count by 1.

ProgrammerV5
- 1,915
- 2
- 12
- 22
-
I have no clue on how to do that. But.... I will now look up the .connect event and knock this off of my "figure it out" bucket list... Thanks!!! – Jerry H Nov 18 '15 at 03:10
0
So.... I found this after looking ...again:
table={}
table=wifi.ap.getclient()
for mac,ip in pairs(table) do
print(mac,ip)
end
-- or shorter
for mac,ip in pairs(wifi.ap.getclient()) do
print(mac,ip)
end
found it on -- https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en#wifiapgetclient

Marcel Stör
- 22,695
- 19
- 92
- 198

Jerry H
- 1
- 1
- 1
-
this is the latest etteration... some errosr but working on it. wifi.setmode(wifi.SOFTAP) local cfg cfg = { ip = "192.168.1.1", netmask = "255.255.255.0", gateway = "192.168.1.1" } wifi.ap.setip(cfg) cfg = { ssid = "ESPA", pwd = "aaaaaaaa" } wifi.ap.config(cfg) led1 = 3 gpio.mode(led1, gpio.OUTPUT) gpio.write(3, gpio.LOW) local x = 0 while x < 1 do for mac,ip in pairs(wifi.ap.getclient()) do x = x + 1 end gpio.write(3, gpio.HIGH) end – Jerry H Nov 19 '15 at 05:53