Connecting the Espruino-powered NodeMCU to WiFi

Connect to the WiFi network

  • Ensure that the wifi.save() command is run so that the NodeMCU will reconnect to the WiFi after next startup.
var ssid     = 'xxxxxxxxx';
var password = 'yyyyyyyyy';
 
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
});

Get status about the WiFi on the NodeMCU

  • getIp, getDetails, and getStatus will display all the details about the WiFi network status we need.
  • The Wireless network password will be displayed in plaintext. From a certain point of view that could be considered a security vulnerability, so be warned.
var wifi = require('Wifi');

console.log(wifi.getIP());
{
  "ip":      "x.x.x.x",
  "netmask": "255.255.255.0",
  "gw":      "x.x.x.1",
  "mac":     "84:f3:eb:81:4e:39"
 }

console.log(wifi.getDetails());
{
  "status":    "connected",
  "ssid":      "xxxxxxxx",
  "password":  "xxxxxxxx",
  "rssi": -55, "savedSsid": null }

console.log(wifi.getStatus());

{
  "mode":      "sta+ap",
  "station":   "connected",
  "ap":        "enabled",
  "phy":       "11n",
  "powersave": "ps-poll",
  "savedMode": "sta+ap"
 }
categories: espruino | esp8266 | nodemcu |