Need help with ESP8266 Wifi/webserver conversion to ESP32

zebu14
Posts: 1
Joined: Fri Aug 17, 2018 7:31 am

Need help with ESP8266 Wifi/webserver conversion to ESP32

Postby zebu14 » Fri Aug 17, 2018 7:54 am

Hello,

I am quite new to the ESP32 and was using ESP8266 chip before.

I found an Arduino project done on ESP8266 that I want to use on an ESP32 Thing (sparkfun board).
I started to convert the code with ESP32 libraries but I'm stuck on the Client handle method.


Here is the source code (ESP8266) : https://cassiopeia.hk/lantern/
I removed the "mode" management code part (no need for auto animation without webserver)

Here is my code (in progress) :

Code: Select all

#include <WiFi.h>
#include <DNSServer.h>
#include <Adafruit_NeoPixel.h>

Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, 12, NEO_GRB + NEO_KHZ800);

const byte DNS_PORT = 53;
IPAddress apIP(192, 168, 1, 1);
DNSServer dnsServer;
WiFiServer server(80);

const byte brightness = 120;

String responseHTML = ""
 "<!DOCTYPE html><html><head><title>Neopixel control</title><meta name='mobile-web-app-capable' content='yes' />"
 
// [...] Removed HTML code in order to shorten the displayed code
 
 "</script></html>";

void setup() {

strip.begin();
 strip.show(); // Initialize all pixels to 'off'
 strip.setBrightness(brightness); // 0-255 range
 
  WiFi.mode(WIFI_AP);
  WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
  WiFi.softAP("RGB CaptivePortal");

  // if DNSServer is started with "*" for domain name, it will reply with
  // provided IP to all DNS request
  dnsServer.start(DNS_PORT, "*", apIP);

server.on("/", handleRGB);
  server.begin();

  Serial.begin(115200);
  Serial.println("Server DNS started");
  Serial.println();
  Serial.print("IP address: ");
  Serial.println(WiFi.softAPIP());

introRed(); // knightrider
 strip.setPixelColor(0, 255, 0, 0);
 strip.setPixelColor(3, 255, 0, 0);
 strip.setPixelColor(4, 255, 0, 0);
 strip.setPixelColor(7, 255, 0, 0);
 strip.show();

 
}

void handleRGB() {
 Serial.println("handle RGB..");

server.send(200, "text/html", responseHTML);

String red = server.arg(0); // read RGB arguments
 String green = server.arg(1);
 String blue = server.arg(2);

allRGB(255 - red.toInt() / 4, 255 - green.toInt() / 4, 255 - blue.toInt() / 4);
 }


void loop() {

  dnsServer.processNextRequest();
  server.available();
  
  // Missing the client management ?
  
}

void introRed() {
 for (int u = 0; u < 3; u++) {
 for (int i = 0; i < strip.numPixels(); i++) {
 oneRed(i);
 delay(100);
 }
 for (int i = strip.numPixels() - 2; i > 0 ; i--) {
 oneRed(i);
 delay(100);
 }
 }
 oneRed(strip.numPixels()); // switch all off (switch on only 8, but beyond range)
 }

void oneRed(int u) {
 for (int i = 0; i < strip.numPixels(); i++) {
 strip.setPixelColor(i, 0, 0, 0);
 }
 strip.setPixelColor(u, 255, 0, 0);
 strip.show();
 }

void allRGB(int r, int g, int b) {
 for (int i = 0; i < strip.numPixels(); i++) {
 strip.setPixelColor(i, r, g, b);
 }
 strip.show();
 }
Code elements preventing compilation ==> need to be "converted"/corrected

error: 'class WiFiServer' has no member named 'on'

Code: Select all

server.on("/", handleRGB);
error: 'class WiFiServer' has no member named 'arg'

Code: Select all

String red = server.arg(0); // read RGB arguments
 String green = server.arg(1);
 String blue = server.arg(2);
error: 'class WiFiServer' has no member named 'send'

Code: Select all

server.send(200, "text/html", responseHTML);

Any help is welcome :)

Who is online

Users browsing this forum: No registered users and 24 guests