forked from A107CEM-1718BTA/TEACHING-MATERIALS
Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |