General area when it fits no where else

Moderator: Mmiscool

User avatar
By andylomb
#80864 hi I can not turn this program into ACCESS POINT, can you help me?

Code: Select all#include <ESP8266WiFi.h>
#include "indexl.h"

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

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

int dac = 0;
int DigitalPin[] = {4, 12, 13};
int DacPin = 5;


// Auxiliary variables to store selected mode and settings
int selectedMode = 0;
int timer = 0;
int ldrThreshold = 0;
int armMotion = 0;
int armLdr = 0;
String modes[4] = { "Manual", "Auto PIR", "Auto LDR", "Auto PIR and LDR" };

// Decode HTTP GET value
String valueString = "0";
int pos1 = 0;
int pos2 = 0;
// Variable to store the HTTP request
String header;
// Set web server port number to 80


void setup() {
  Serial.begin(115200);
  delay(10);


pinMode(4,INPUT);
pinMode(4, INPUT_PULLUP);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
 
  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  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() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
 
  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
 
  // Read the first line of the request
  String command1 = client.readStringUntil('/');
  String command = client.readStringUntil('/');
  Serial.println(command1);
  Serial.println(command);


 client.println("<body><h1>ESP8266 Web Server</h1>");
            // Drop down menu to select mode
            client.println("<p><strong>Mode selected:</strong> " + modes[selectedMode] + "</p>");
            client.println("<select id=\"mySelect\" onchange=\"setMode(this.value)\">");
            client.println("<option>Change mode");
            client.println("<option value=\"0\">Manual");
            client.println("<option value=\"1\">Auto PIR");
            client.println("<option value=\"2\">Auto LDR");
            client.println("<option value=\"3\">Auto PIR and LDR</select>");






 

if (command == "digital") {
int pin, value;
pin = client.parseInt();
  Serial.println(pin);
if (client.read() == '/') {
value = client.parseInt();
digitalWrite(pin, value);
}
else {
value = digitalRead(pin);
}
client.print(F("digital,"));
client.print(pin);
client.print(F(","));
client.println(value);
}
else if (command == "dac"){
  int pin, value;
pin = client.parseInt();
if (client.read() == '/') {
value = client.parseInt();
dac = value;
analogWrite(pin, value);
}
else {
value = dac;
}
client.print(F("dac,"));
client.print(pin);
client.print(F(","));
client.println(value);
}
else if (command == "status") {
int pin, value;
client.print(F("status"));
for (int thisPin = 0; thisPin < 3; thisPin++) {
pin = DigitalPin[thisPin];
value = digitalRead(pin);
client.print(F("#"));
client.print(pin);
client.print(F("="));
client.print(value);
}
{
pin = DacPin;
value = dac;
client.print(F("#"));
client.print(pin);
client.print(F("="));
client.print(value);
}
{
value = analogRead(A0);
float lux=value;
client.print(F("#A0"));
client.print(F("="));
client.print(lux);
}
client.println("");
}
else {  // Prepare the response
  String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
  s += file1; 
  client.flush();


 


  // Send the response to the client
while(s.length()>2000)
{
  String dummy = s.substring(0,2000);
  client.print(dummy);
  s.replace(dummy," ");
}
 
  client.print(s);
  delay(1);
  Serial.println("Client disconnected");

  // The client will actually be disconnected
  // when the function returns and 'client' object is destroyed
}
}
User avatar
By Oldbod
#80948 Hi.

I hope you've already been successful in sorting this, but if not it would perhaps be better to post it in an area of the forum that deals with programs written in c++. This section is for esp8266basic (which is a lot easier to work with if you're new to programming!).
User avatar
By schufti
#80950 in setup() try replacing
Code: Select all  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");


with something minimal like
Code: Select allSerial.println(WiFi.softAPConfig("192.168.4.22", "192.168.4.9", "255.255.255.0") ? "Ready" : "Failed!");
Serial.println(WiFi.softAP("your_ssid","your_pass") ? "Ready" : "Failed!");