Home » Espruino and ESP32 wifi examples

Espruino and ESP32 wifi examples

by shedboy71

In this example we will show a couple of Wifi examples using Espruino firmware flashed on an ESP32, we used the Espruino web ide

Code examples

This example simple connects to your Wifi and an IP address will be assigned

[javascript]

var ssid = ‘username';
var password = ‘password';

var wifi = require(‘Wifi');
wifi.connect(ssid, {password: password}, function() {
console.log(‘Connected to Wifi. IP address is:', wifi.getIP().ip);
wifi.save(); // Next reboot will auto-connect
});

[/javascript]

This next example is a basic web server, here is the code

[javascript]

var ssid = ‘username';
var password = ‘password';
var port = 80;

function processRequest (req, res) {
res.writeHead(200);
res.end(‘Hello from ESP32');
}

var wifi = require(‘Wifi');
wifi.connect(ssid, {password: password}, function() {
var http = require(‘http');
http.createServer(processRequest).listen(port);
console.log(‘Web server running : IP address is ‘, wifi.getIP().ip);
});

[/javascript]

Upload the code and you should see something like this in the IDE

Now we have an IP address assigned you can navigate to that IP address in your favourite browser, here you can see my example

You may also like

Leave a Comment

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.