Enable Javascript


Last Arduino/ESP project (click to open)

User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active
 

My simpleWiFiFull (ESP32)
STA, AP, STA_AP, ESP-NOW,
Time, Weather and WebSocket Server

Totally free to use and modify.

A very easy to use sWiFiFull.h library. Automatic initialization and connection 'stays alive' control and eight selectable options.
In a Arduino ESP32ino project: change the option parameters and include sWiFiFull.h to your project.
In setup() call setupWiFi() and all the chosen options are ready to use. In loop() insert loopWiFi() all other wifi and options code is handled in sWiFiFull.h.
If using the ESP-NOW option then test in loop()  if (boolean nowVal) then the received data is in String nowBuf (we use a String so do not suffer from a character array length problem). Don't forget to set nowVal = false. Use nowSendData(uint_8 mac, char *msg) to send a message.
If using the WebSocket option then test in loop()  if (boolean wsVal) then the received data is in String wsBuf (we use a String so do not suffer from a character array length problem). Don't forget to set wsVal = false. Use webSocket.broadcastTXT(*char or char[] or "message" or String msg.c_str()) to send a message.
Download my simpleLIB and open the examples folder: sWiFiFull_demo.

In the sWiFiFull example folder you will also find my simple, but very effective, basic model WebMonitor.html and sWS.html (see last picture).
With a WebSocket Server/Client you do not need a third party cloud service.
If using Openweathermap: get a free key from openweathermap (free subscription, 60 calls/minute 1,000,000 calls/month).
If using WebSocketsServer: get the library from: https://hub.com/Links2004/arduinoWebSockets
If using WebSocketsServer: register the localIP as static in your router and, if desired, also port forwarding to make it usable from elsewhere on the WWW.

In sWS.html WebSocket Client edit this code (line 23+).

<script>
/***** EDIT THIS *****/             // networkWWW IP? Get it from "http://kendziorra.nl/mijnip.php"
var networkWWW = 'nnn.xxx.yyy.zzz'; // if using it: port forwarding networkSTA in router
var networkSTA = '192.168.178.172'; // as in ESP32 - static in router
var socketPort =  82;               // " " 
var wsURI      = '/';               // " " 
var wsProtocol = 'sWS';             // " " 
/****** EDIT END ******/
</script>