This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| en:iot-open:remotelab:sut:generalpurpose2:u1 [2018/10/31 11:21] – created pczekalski | en:iot-open:remotelab:sut:generalpurpose2:u1 [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ==== Visualisation of the Temperature and Humidity | + | ==== U1: Connecting to the network in STA mode ==== |
| - | //Give few words about this scenario. Provide some objectives | + | Most IoT (if not all of them) require your device to communicate via a network. Here we connect to the existing WiFi network, 2.4GHz. All laboratory nodes can access common access point and require credentials to connect to it (see laboratory description section for the credentials and latest updates). ESP 8266 has a built-in WiFi interface, so you're using it to connect to the network. Every ESP has an individual MAC address. An IP address is assigned to the ESP via DHCP server, automatically, |
| === Target group === | === Target group === | ||
| - | //This hands-on lab guide is intended for the Beginners/ | + | Undergraduate |
| === Prerequisites === | === Prerequisites === | ||
| - | //Provide prerequisite readings/ | + | You will need to know the credentials of the network - see node description for details. Mind, those may be different than in the code chunks presented below. You need to know how to handle 4x20 characters LCD screen. In case of doubt re-work on scenarios B1 and B2. |
| === Scenario === | === Scenario === | ||
| - | // | + | In this scenario, you will create a WiFi client |
| + | While attempting to connect, the first line of the LCD should present | ||
| + | When connected, the first line of the LCD should present information "WiFi connected" | ||
| + | We suggest putting connection and information code into the separate function that you will call from the '' | ||
| === Result === | === Result === | ||
| - | //Describe expected result when scenario is finished.// | + | The LCD screen should present the current situation and all the necessary information. Once connected, observe the IP address assigned by the DHCP server and device' |
| === Start === | === Start === | ||
| - | //Write starting conditions, i.e. what to do at the beginning, what to pay attention before beginning, how the mechanical part should look like, etc.// | + | Define some identifiers to separate and update AP's SSID and passphrase easily. To format lines for the LCD, we suggest using a '' |
| === Steps === | === Steps === | ||
| - | // Write some extra information if i.e. some steps are optional otherwise cancel this paragraph (but do not remove header).// | + | Following |
| - | == Step 1 == | + | |
| - | //Describe activities done in Step 1.// | + | |
| + | == Step 1 == | ||
| + | Include all necessary libraries. The minimum set here is: | ||
| + | <code c> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| ... | ... | ||
| + | </ | ||
| + | == Step 2 == | ||
| + | Give it some definitions as identifiers for cleaner code: | ||
| + | <code c> | ||
| + | #define wifi_ssid " | ||
| + | #define wifi_password " | ||
| + | </ | ||
| + | <note important> | ||
| + | |||
| + | == Step 3 == | ||
| + | Print some information about starting connecting to WiFi, configure network interface as a WiFi client and give it a try to connect to the AP: | ||
| + | <code c> | ||
| + | delay(10); | ||
| + | WiFi.mode(WIFI_STA); | ||
| + | WiFi.begin(wifi_ssid, | ||
| + | n=0; | ||
| + | </ | ||
| + | <note important>'' | ||
| + | <note tip>'' | ||
| + | <note warning> | ||
| + | |||
| + | == Step 4 == | ||
| + | Check if connected, if not, give it next attempt: | ||
| + | <code c> | ||
| + | while (WiFi.status() != WL_CONNECTED) { | ||
| + | lcd.setCursor(0, | ||
| + | n++; | ||
| + | sprintf(buffer," | ||
| + | lcd.print(buffer); | ||
| + | delay(1000); | ||
| + | </ | ||
| - | == Step n == | + | == Step 5 == |
| - | //Describe activities done in Step n.// | + | When connected, show details to the camera: |
| + | <code c> | ||
| + | lcd.clear(); | ||
| + | lcd.home(); | ||
| + | lcd.print(" | ||
| + | | ||
| + | String s = WiFi.localIP().toString(); | ||
| + | sprintf(buffer," | ||
| + | lcd.setCursor(0, | ||
| + | lcd.print(buffer); | ||
| + | | ||
| + | lcd.setCursor(0, | ||
| + | lcd.print(" | ||
| + | s = WiFi.macAddress(); | ||
| + | lcd.setCursor(0, | ||
| + | lcd.print(s.c_str()); | ||
| + | </ | ||
| + | <note tip>IP address returned by the WiFi.localIP() function of the WiFi manager returns '' | ||
| + | == Step 6 == | ||
| + | In the loop() function present ticker in the 3rd line, right side of the LCD. The 4th line is all occupied by the MAC address, if you followed 1:1 the guide. In case your UI looks different, handle coordinates appropriatelly. | ||
| === Result validation === | === Result validation === | ||
| - | //Provide some result validation methods, for self assesment.// | + | Run your code and observe LCD presenting information on connection progress, IP and MAC addresses. |
| === FAQ === | === FAQ === | ||
| - | This section | + | **Does IP address change over time?**: Yes. First of all, IP is given automatically by the DHCP server. There is no strict rule saying, your IP is always going to be the same. Second, IP address reservation is done for some period of time and then DHCP server may assign you other IP so it may change over runtime, not necessarily between restarts only.\\ |
| - | When using the printed version of this manual please refer to the latest online version of this document to obtain the valid and up-to-date list of the FAQ. | + | **Does MAC address change**: No. It is a factory given one and should be unique worldwide. Anyway, you can programmatically change it - this technique is commonly used by hackers |
| - | //Provide some FAQs in the following form:\\ | + | **Do I need to use '' |
| - | **Question?**: Answer. | + | |
| - | // | + | |