Skip to content
Permalink
5b7d41317b
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time

Code Samples

To help you develop your sensor project you can make use of these code samples adapted from the samples provided by the Arduino IDE.

Connecting to the Internet

One of the first tasks you will need to do is connect your ESP8266 to the internet by connecting to an access point.

Connecting in the Lab

Unfortunately IoT devices such as NodeMCU (and Lego!) can't connect to the Main University WiFi and so we have set up a network for you to use.

The ECL-LEGO-ROBOTS network is setup to allow internet on ports 1883 and 8883 and so you should connect to this and make sure you only use these ports to communicate.

The code below will connect you to the

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

ESP8266WiFiMulti WiFiMulti;

void setup() {
    Serial.begin(115200);
    delay(10);

    // We start by connecting to a WiFi network
    WiFiMulti.addAP("ssid", "password");

    Serial.println();
    Serial.println();
    Serial.print("Wait for WiFi... ");

    while(WiFiMulti.run() != WL_CONNECTED) {
        Serial.print(".");
        delay(500);
    }

    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());

    delay(500);
}


void loop() {
    
}

Connecting at Home

You should be able to connect to your home Wifi network without any issues by changing the ssid and password. If you are having problems check the security settings and, if available, choose WPA/WPA2-PSK (mixed mode). If you discover any more information that might be useful to others, edit this document and file a merge request.

You should see the NodeMCU listed under connected devices on your router admin page, with the name ESP_XXXXXX where XXXXXX is part of the Mac Address.