Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By derek bernsen
#29942 Hi all,
I'm trying to program my ESP-01 using the arduino IDE. I'm trying to make a program makes the ESP-01 module a standalone access point... When my phone device connects with the correct WiFi password, the module would then toggle a GPIO pin on for 2 seconds, then off. When my phone disconnects, it should toggle the same GPIO pin on for 2 seconds, then toggle it off.
The circuit would just be a ESP-01, a power source, and a optocoupler/optoisolator connected to a GPIO pin.

I don't have the faintest clue how to code this. I've tried many iterations of my own adaptations of various example code, and I can't seem to get it to work.
I'm so lost by the code, so it would be more optimal if you just tell me what the code should be.
User avatar
By mrburnette
#30450 I have an AP example on my project page, it may be helpful:

https://www.hackster.io/rayburne

Assuming your WiFi device is the only device to connect, you can just get the number of attached stations, if over 0, then you have a connection. Sample calls:
http://www.esp8266.com/viewtopic.php?f=32&t=5669#p29838

Ray
User avatar
By derek bernsen
#30489 Ok, this is my code so far, it's throwing tons of errors when I verify it:



Code: Select all
/* Create a WiFi access point */

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#define WIFI_MODE_AP

/* Set these to your desired credentials. */
const char *ssid = "Proximity Trigger 1";
const char *password = "thereisnospoon";
//Reference as station counter as "devices"
unsigned char devices;

ESP8266WebServer server(80);

/* Just a little test message.  Go to http://192.168.4.1 in a web browser
 * connected to this access point to see it.
 */
void handleRoot() {
   

}

void setup() {
   delay(1000);
   Serial.begin(115200);
   Serial.println();
   Serial.print("Configuring access point...");
   /* You can remove the password parameter if you want the AP to be open. */
   WiFi.softAP(ssid, password);

   IPAddress myIP = WiFi.softAPIP();
   Serial.print("AP IP address: ");
   Serial.println(myIP);
   server.on("/", handleRoot);
   server.begin();
   
  pinMode(2, OUTPUT);
  digitalWrite(2, LOW);
   devices = wifi_softap_get_station_num();
 }

void loop() {
   if (devices)  >= 1;
     digitalWrite(2, HIGH);
      delay(1000);
      digitalWrite(2,LOW);
 
   else if (devices)  <= 1;
     digitalWrite(2,HIGH);
     delay(1000);
     digitalWrite(2,LOW);   
 
   server.handleClient();
}
}
 



And these are the errors I'm getting:

"Arduino: 1.6.5 (Windows 7), Board: "Generic ESP8266 Module, Serial, 80 MHz, 40MHz, DIO, 115200, 512K (64K SPIFFS)"

Proximity_Toggle_10_4_2015.ino: In function 'void setup()':
Proximity_Toggle_10_4_2015:41: error: 'wifi_softap_get_station_num' was not declared in this scope
Proximity_Toggle_10_4_2015.ino: In function 'void loop()':
Proximity_Toggle_10_4_2015:45: error: expected primary-expression before '>=' token
Proximity_Toggle_10_4_2015:50: error: 'else' without a previous 'if'
Proximity_Toggle_10_4_2015:50: error: expected primary-expression before '<=' token
Proximity_Toggle_10_4_2015.ino: At global scope:
Proximity_Toggle_10_4_2015:57: error: expected declaration before '}' token
'wifi_softap_get_station_num' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences."

I still needs some tips please.
User avatar
By martinayotte
#30494 For the "error: 'wifi_softap_get_station_num'", you need to add an include :
Code: Select allextern "C" {
#include "user_interface.h"
}

For the others, you have wrong C/C++ syntax ... :(
Code: Select allif (devices  >= 1) {
  digitalWrite(2, HIGH);
  delay(1000);
  digitalWrite(2,LOW);
}