Skip to content
Permalink
Browse files
added some sample code
  • Loading branch information
aa7401 committed Dec 21, 2017
1 parent 3be2c09 commit 5b7d41317b5e8794c402d807b615d6ad02b804e2
Showing 1 changed file with 58 additions and 0 deletions.
@@ -0,0 +1,58 @@

# 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

```cpp
#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.

0 comments on commit 5b7d413

Please sign in to comment.