-->
Page 1 of 3

Change sketch to access point

PostPosted: Tue Sep 19, 2017 11:35 am
by MrMU
Hi there,

For some reason I can't find out how to edit a sketch so the ESP01 that I use behaves like an access point.

I found a sketch that works fine when connected to my router.
But I want this ESP project to work for a long time, and don't want it to edit when something on my router changes.
My idea was to make the ESP an access point so it will work for a long time without interference..

I will cut a piece of the sketch, my only question is what do I have to edit to accomplish what I want.

Code: Select all#include <DHT.h>
#include <DHT_U.h>

#include <ESP8266WiFi.h>
#include "espipswitchtoggle.h"

const char* ssid = "MySSID";
const char* password = "MyPass";

// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);

unsigned long timer = 0;
unsigned long firstMillis = 0;
void setup() {
  Serial.begin(115200);
  delay(10);
  pinMode(0, OUTPUT);
  pinMode(2,INPUT);
  pinMode(2, INPUT_PULLUP);   
 
  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.hostname("verw");
  WiFi.begin(ssid, password);
 
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
   
  }
  Serial.println("");
  Serial.println("WiFi connected");
 
  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.println(WiFi.localIP());
}

void loop() {
unsigned long currentMillis = millis();
if(currentMillis - firstMillis > (timer*60000)) { 
  digitalWrite(0, 0);

Re: Change sketch to access point

PostPosted: Tue Sep 19, 2017 1:47 pm
by martinayotte

Re: Change sketch to access point

PostPosted: Tue Sep 19, 2017 4:15 pm
by MrMU
martinayotte wrote:Did you look at this example ?
https://github.com/esp8266/Arduino/blob ... sPoint.ino


Hey thank you,

But I'm more an hardware guy then a software guy.
The thing is that I tried so many things, but sometimes I corrupt the INO I'm working on with my changes.

The only thing I need to change is that the ESP acts like a access point.
And that's the thing, I always change things and then the INO doesn't compile or the ESP doesn't work anymore..

So what do I change if I can ask this on this forum?

Re: Change sketch to access point

PostPosted: Tue Sep 19, 2017 4:44 pm
by martinayotte
The example above is pretty straight forward.
Instead of doing WiFi.begin() and WiFi.status(), simply do the following as in the example :
Code: Select allWiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);