esp8266 code to esp32

i want to put a program on an esp32 that i have written for esp8266. i use some arduino libraries that are designed for my esp8266 what are my options here. these are the libraries i use.

#include <EEPROM.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPUpdateServer.h>
#include <ArduinoOTA.h>
#include <FS.h>   //Include File System HeadersJson.h>

Hi there
ESP32 uses

#include <WiFi.h>
#include <HTTPClient.h>
#include <WebServer.h>
#include <SPIFFS.h>
#include <Update.h>

over

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <FS.h>
#include <ESP8266HTTPUpdateServer.h>

more from here arduino-esp32/libraries at master · espressif/arduino-esp32 · GitHub

I think im having a problem with wifi library. here is my error output,

Arduino: 1.8.12 (Windows 10), Board: "NodeMCU-32S, 80MHz, 921600"
s/sdk/include/tcpip_adapter" "-IC:\\Users\\Laptop\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/ulp" "-IC:\\Users\\Laptop\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/vfs" "-IC:\\Users\\Laptop\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/wear_levelling" "-IC:\\Users\\Laptop\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/wifi_provisioning" "-IC:\\Users\\Laptop\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/wpa_supplicant" "-IC:\\Users\\Laptop\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/xtensa-debug-module" "-IC:\\Users\\Laptop\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/esp-face" "-IC:\\Users\\Laptop\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/esp32-camera" "-IC:\\Users\\Laptop\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/esp-face" "-IC:\\Users\\Laptop\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4/tools/sdk/include/fb_gfx" -std=gnu++11 -Os -g3 -Wpointer-arith -fexceptions -fstack-protector -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib -w -Wno-error=maybe-uninitialized -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-unused-but-set-parameter -Wno-missing-field-initializers -Wno-sign-compare -fno-rtti -c -w -x c++ -E -CC -DF_CPU=240000000L -DARDUINO=10812 -DARDUINO_NodeMCU_32S -DARDUINO_ARCH_ESP32 "-DARDUINO_BOARD=\"NodeMCU_32S\"" "-DARDUINO_VARIANT=\"nodemcu-32s\"" -DESP32 -DCORE_DEBUG_LEVEL=0 "-IC:\\Users\\Laptop\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4\\cores\\esp32" "-IC:\\Users\\Laptop\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4\\variants\\nodemcu-32s" "-IC:\\Users\\Laptop\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4\\libraries\\WiFi\\src" "-IC:\\Users\\Laptop\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4\\libraries\\WebServer\\src" "-IC:\\Users\\Laptop\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4\\libraries\\ESPmDNS\\src" "-IC:\\Users\\Laptop\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4\\libraries\\Update\\src" "-IC:\\Users\\Laptop\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.4\\libraries\\EEPROM\\src" "C:\\ArduinoTemp\\sketch\\sketch_sep13a.ino.cpp" -o nul
Alternatives for ESP8266WiFi.h: []C:\Users\Laptop\Documents\Arduino\sketch_sep13a\mast_nodemcu.ino:2:25: fatal error: ESP8266WiFi.h: No such file or directory


ResolveLibrary(ESP8266WiFi.h)
compilation terminated.

  -> candidates: []
Multiple libraries were found for "WiFi.h"
 Used: C:\Users\Laptop\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi
 Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
 Not used: C:\Users\Laptop\Documents\Arduino\libraries\WiFi
Using library WiFi at version 1.0 in folder: C:\Users\Laptop\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi 
Using library WebServer at version 1.0 in folder: C:\Users\Laptop\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WebServer 
Using library ESPmDNS at version 1.0 in folder: C:\Users\Laptop\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\ESPmDNS 
Using library Update at version 1.0 in folder: C:\Users\Laptop\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\Update 
Using library EEPROM at version 1.0.3 in folder: C:\Users\Laptop\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\EEPROM 
exit status 1
Error compiling for board NodeMCU-32S.

Actually i had a ino file in the directory with the sketch ino.

notsolowki:
Actually i had a ino file in the directory with the sketch ino.

could you post your sketch, or is it too long ?

KASSIMSAMJI:
could you post your sketch, or is it too long ?

well that first error is going but now im gettings error,

C:\ArduinoTemp\sketch\WaterController.h:120:25: error: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]

       Udp.write("CF2TCW");
#include <EEPROM.h>
#include <WiFi.h>
#include <WiFiClient.h>
//#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ESP32WebServer.h>
//#include <ESP8266HTTPUpdateServer.h>
//#include <ArduinoOTA.h>
#include <FS.h>   //Include File System Headers
#include <ArduinoJson.h>


//ESP32WebServer OTA_httpServer(81);
//ESP8266HTTPUpdateServer OTA_httpUpdater;
ESP32WebServer server(80);

IPAddress local_IP(192, 168, 4, 1);
IPAddress subnet(255, 255, 255, 0);

IPAddress Client1(192, 168, 4, 2);
IPAddress Client2(192, 168, 4, 3);
IPAddress Client3(192, 168, 4, 4);
IPAddress Client4(192, 168, 4, 5); //TEMP SENSOR WATER TEMP
IPAddress Client5(192, 168, 4, 6); //TIMER MODULE 1
IPAddress Client6(192, 168, 4, 7); //Water controller
IPAddress Client7(192, 168, 4, 8); //C02 MOINTOR 1

IPAddress sta_local_IP(10, 0, 0, 232);
IPAddress sta_gateway(10, 0, 0, 1);
IPAddress sta_subnet(255, 0, 0, 0);

const char* ssid = "LCS2";
const char* password = "xxxxxxxx";
unsigned long conmillis = 0;

bool waterstatus = 0;
unsigned long now = 0;
unsigned long now2 = 0;
unsigned long  addr = 10;
bool adminEnabled = false;
char incomingPacket[255];  // buffer for incoming packets
WiFiUDP Udp; //ap client port
unsigned int localUdpPort = 4210;  // local port to listen on
unsigned int ServerPort = 4220;
struct {
  char  sta_ssid[15];
  char  sta_password[15];
  char  system_password[15];

} _EEPROM;

void _writeEEPROM () {
  EEPROM.put(addr, _EEPROM);
  EEPROM.commit();    //Store data to EEPROM
  // Serial.println("EEPROM WRITE");
}

void handlereboot() {
  ESP.restart();
}
void sendCommand(IPAddress to, int data[], int size, char delimiter[], char delimiter2[]) {
  Udp.beginPacket(to, ServerPort);
  Udp.write(delimiter);
  Udp.write((byte *)data, size); //cast to bytes
  Udp.write(delimiter2);
  Udp.endPacket();
}
#include "timerModules.h"
#include "tempMonitor.h"
#include "UVcontroller.h"
#include "htmlFunctions.h"
#include "WaterController.h"
#include "co2Modules.h"
#include "packetHelper.h"

void setup() {
  SPIFFS.begin();
  Serial.begin(115200);
  EEPROM.begin(128);  //Initialize EEPROM
  EEPROM.get(addr, _EEPROM);
  Serial.println("hello");
  WiFi.persistent(0);
  WiFi.mode(WIFI_AP_STA);
  WiFi.begin(_EEPROM.sta_ssid, _EEPROM.sta_password);
  WiFi.config(sta_local_IP, sta_subnet, sta_gateway);
  WiFi.softAP(ssid, password, 9, false, 15);
  WiFi.softAPConfig(local_IP, local_IP, subnet);
#include "serverHandles.h"
//#include "OTA.h"
  server.begin();
  Udp.begin(localUdpPort);
}

void loop() {
  if (millis() - conmillis >= 3000) {
    waterstatus = 0;
  } else {
    waterstatus = 1;
  }
  if (adminEnabled) {
 //   OTA_httpServer.handleClient(); //ota server "htt p://x.x.x.x :81/update"
   // ArduinoOTA.handle();
  }
  server.handleClient();//Checks for web server activity
  recPacket();

  if (millis() - now >= 2000) {
    now = millis();
  }
}

Without all the extra scripts just the main sketch i get these errors,

sketch_sep13a:63:22: error: invalid conversion from 'char*' to 'uint8_t {aka unsigned char}' [-fpermissive]

   Udp.write(delimiter);

                      ^

In file included from C:\Users\Laptop\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi\src/WiFi.h:39:0,

                 from C:\Users\Laptop\Documents\Arduino\sketch_sep13a\sketch_sep13a.ino:2:

C:\Users\Laptop\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi\src/WiFiUdp.h:64:10: note:   initializing argument 1 of 'virtual size_t WiFiUDP::write(uint8_t)'

   size_t write(uint8_t);

          ^

sketch_sep13a:65:23: error: invalid conversion from 'char*' to 'uint8_t {aka unsigned char}' [-fpermissive]

   Udp.write(delimiter2);

                       ^

In file included from C:\Users\Laptop\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi\src/WiFi.h:39:0,

                 from C:\Users\Laptop\Documents\Arduino\sketch_sep13a\sketch_sep13a.ino:2:

C:\Users\Laptop\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi\src/WiFiUdp.h:64:10: note:   initializing argument 1 of 'virtual size_t WiFiUDP::write(uint8_t)'

   size_t write(uint8_t);

          ^

C:\Users\Laptop\Documents\Arduino\sketch_sep13a\sketch_sep13a.ino: In function 'void setup()':

sketch_sep13a:77:3: error: 'SPIFFS' was not declared in this scope

   SPIFFS.begin();

   ^

Multiple libraries were found for

notsolowki:
Without all the extra scripts just the main sketch i get these errors,

sketch_sep13a:63:22: error: invalid conversion from 'char*' to 'uint8_t {aka unsigned char}' [-fpermissive]

Udp.write(delimiter);

^

In file included from C:\Users\Laptop\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi\src/WiFi.h:39:0,

from C:\Users\Laptop\Documents\Arduino\sketch_sep13a\sketch_sep13a.ino:2:

C:\Users\Laptop\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi\src/WiFiUdp.h:64:10: note:  initializing argument 1 of ‘virtual size_t WiFiUDP::write(uint8_t)’

size_t write(uint8_t);

^

sketch_sep13a:65:23: error: invalid conversion from ‘char*’ to ‘uint8_t {aka unsigned char}’ [-fpermissive]

Udp.write(delimiter2);

^

In file included from C:\Users\Laptop\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi\src/WiFi.h:39:0,

from C:\Users\Laptop\Documents\Arduino\sketch_sep13a\sketch_sep13a.ino:2:

C:\Users\Laptop\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi\src/WiFiUdp.h:64:10: note:  initializing argument 1 of ‘virtual size_t WiFiUDP::write(uint8_t)’

size_t write(uint8_t);

^

C:\Users\Laptop\Documents\Arduino\sketch_sep13a\sketch_sep13a.ino: In function ‘void setup()’:

sketch_sep13a:77:3: error: ‘SPIFFS’ was not declared in this scope

SPIFFS.begin();

^

Multiple libraries were found for

this one compiles just fine

#include <EEPROM.h>
#include <WiFi.h>
#include <WiFiClient.h>
//#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <WebServer.h>
//#include <ESP8266HTTPUpdateServer.h>
//#include <ArduinoOTA.h>
#include <FS.h>   //Include File System Headers
//#include <ArduinoJson.h>


//ESP32WebServer OTA_httpServer(81);
//ESP8266HTTPUpdateServer OTA_httpUpdater;
WebServer server(80);

IPAddress local_IP(192, 168, 4, 1);
IPAddress subnet(255, 255, 255, 0);

IPAddress Client1(192, 168, 4, 2);
IPAddress Client2(192, 168, 4, 3);
IPAddress Client3(192, 168, 4, 4);
IPAddress Client4(192, 168, 4, 5); //TEMP SENSOR WATER TEMP
IPAddress Client5(192, 168, 4, 6); //TIMER MODULE 1
IPAddress Client6(192, 168, 4, 7); //Water controller
IPAddress Client7(192, 168, 4, 8); //C02 MOINTOR 1

IPAddress sta_local_IP(10, 0, 0, 232);
IPAddress sta_gateway(10, 0, 0, 1);
IPAddress sta_subnet(255, 0, 0, 0);

const char* ssid = "LCS2";
const char* password = "xxxxxxxx";
unsigned long conmillis = 0;

bool waterstatus = 0;
unsigned long now = 0;
unsigned long now2 = 0;
unsigned long  addr = 10;
bool adminEnabled = false;
char incomingPacket[255];  // buffer for incoming packets
WiFiUDP Udp; //ap client port
unsigned int localUdpPort = 4210;  // local port to listen on
unsigned int ServerPort = 4220;
struct {
  char  sta_ssid[15];
  char  sta_password[15];
  char  system_password[15];

} _EEPROM;

void _writeEEPROM () {
  EEPROM.put(addr, _EEPROM);
  EEPROM.commit();    //Store data to EEPROM
  // Serial.println("EEPROM WRITE");
}

void handlereboot() {
  ESP.restart();
}
void sendCommand(IPAddress to, int data[], int size, char delimiter[], char delimiter2[]) {
  Udp.beginPacket(to, ServerPort);
  Udp.printf("%s%d%s", delimiter, data, delimiter2);
  Udp.endPacket();
}


void setup() {
  //  SPIFFS.begin();
  Serial.begin(115200);
  EEPROM.begin(128);  //Initialize EEPROM
  EEPROM.get(addr, _EEPROM);
  Serial.println("hello");
  WiFi.persistent(0);
  WiFi.mode(WIFI_AP_STA);
  WiFi.begin(_EEPROM.sta_ssid, _EEPROM.sta_password);
  WiFi.config(sta_local_IP, sta_subnet, sta_gateway);
  WiFi.softAP(ssid, password, 9, false, 15);
  WiFi.softAPConfig(local_IP, local_IP, subnet);
  //#include "serverHandles.h"
  //#include "OTA.h"
  server.begin();
  Udp.begin(localUdpPort);
}

void loop() {
  if (millis() - conmillis >= 3000) {
    waterstatus = 0;
  } else {
    waterstatus = 1;
  }
  if (adminEnabled) {
    //   OTA_httpServer.handleClient(); //ota server "htt p://x.x.x.x :81/update"
    // ArduinoOTA.handle();
  }
  server.handleClient();//Checks for web server activity
  //  recPacket();

  if (millis() - now >= 2000) {
    now = millis();
  }
}

for SPIFFS, please check out this ESP32 Arduino SPIFFS: Writing a file - techtutorialsx

and for OT Update, see this ESP32 Over-the-air (OTA) Programming | Random Nerd Tutorials

GoodLuck

okay i got the code uploaded but my wifi client node esp8266 wont connect if i assign static ip address to the client. dynamic clinet will connect?

KASSIMSAMJI:
this one compiles just fine

GoodLuck

[/quote]

is there a way to force the softap on the esp32 into wireless b mode?