No ACL setup yet! Denying access to everyone.
en:edu:zmitac:s2:iotn:lab3
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:edu:zmitac:s2:iotn:lab3 [2022/03/18 22:56] – [Software] pczekalski | en:edu:zmitac:s2:iotn:lab3 [2023/04/21 16:46] (current) – administrator | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| Network programming for the IoT Devices using CoAP protocol. | Network programming for the IoT Devices using CoAP protocol. | ||
| - | Following | + | The following |
| - | <note important> | + | <note important> |
| - | <note important> | + | <note important> |
| ==== Hardware ==== | ==== Hardware ==== | ||
| - | We do not use any specific hardware here other than an LCD screen to present visual information. If you intend to extend your project and i.e. use a temperature and humidity sensor, refer to the [[en: | + | We do not use any specific hardware here besides |
| === Hardware-software components and libraries === | === Hardware-software components and libraries === | ||
| - | Interfacing hardware requires the use of particular GPIOs. Laboratory nodes and hardware used needs specific | + | Interfacing hardware requires the use of particular GPIOs. Laboratory nodes and hardware used need specific |
| == LCD display == | == LCD display == | ||
| Line 30: | Line 30: | ||
| </ | </ | ||
| - | To initialise | + | To initialize |
| <code c> | <code c> | ||
| const int rs = 12, en = 13, d4 = 4, d5 = 0, d6 = 2, d7 = 14; | const int rs = 12, en = 13, d4 = 4, d5 = 0, d6 = 2, d7 = 14; | ||
| Line 36: | Line 36: | ||
| </ | </ | ||
| - | It is also necessary to tell the library about the display | + | It is also necessary to tell the library about the display |
| <code c> | <code c> | ||
| ... | ... | ||
| Line 45: | Line 45: | ||
| ==== Software ==== | ==== Software ==== | ||
| - | String formatting may be a challenge. An easy approach is to allocate a character buffer of the size of the LCD or just one display' | + | String formatting may be a challenge. An easy approach is to allocate a character buffer of the size of the LCD or just one display' |
| <code c> | <code c> | ||
| ... | ... | ||
| Line 52: | Line 52: | ||
| </ | </ | ||
| - | To convert float into the string with formatting use '' | + | To convert float into the string with formatting, use '' |
| <code c> | <code c> | ||
| ... | ... | ||
| Line 60: | Line 60: | ||
| ... | ... | ||
| </ | </ | ||
| - | <note tip>'' | + | <note tip>'' |
| <code c> | <code c> | ||
| delay(time) | delay(time) | ||
| Line 66: | Line 66: | ||
| === Software libraries === | === Software libraries === | ||
| - | Software libraries are needed to handle communication | + | Software libraries are needed to communicate |
| - | The great feature of the CoAP is, you do not need to take care of the instant connection to the service on the application-level protocol. Just reconnecting WiFi, if the connection is dropped, is quite enough. UDP is a " | + | The outstanding |
| == WIFI and UDP == | == WIFI and UDP == | ||
| - | A WiFi library is already included in the ESP8266 framework for the Arduino programming model, so there is no need to use library manager to add it. All is necessary is to include | + | A WiFi library is already included in the ESP8266 framework for the Arduino programming model, so there is no need to use a library manager to add it. All that is necessary is to have a header |
| <code c> | <code c> | ||
| ... | ... | ||
| Line 78: | Line 78: | ||
| </ | </ | ||
| - | Then create some constant variables or declare token string identifiers (as below) with '' | + | Then create some constant variables or declare token string identifiers (as below) with '' |
| <code c> | <code c> | ||
| ... | ... | ||
| Line 85: | Line 85: | ||
| ... | ... | ||
| </ | </ | ||
| - | The '' | + | The '' |
| <code c> | <code c> | ||
| ... | ... | ||
| Line 94: | Line 94: | ||
| Some useful code snippets are below.\\ | Some useful code snippets are below.\\ | ||
| - | Checking if WiFi connection is successful: | + | Checking if the WiFi connection is successful: |
| <code c> | <code c> | ||
| ... | ... | ||
| Line 118: | Line 118: | ||
| ... | ... | ||
| </ | </ | ||
| - | Note, this object becomes automatically active and bound to the '' | + | Note this object becomes automatically active and bound to the '' |
| <code c> | <code c> | ||
| Line 137: | Line 137: | ||
| </ | </ | ||
| - | <note important> | + | <note important> |
| - | CoAP client or server both require to be instantiated using WiFi UDP connection (aforeinitialised | + | CoAP client or server both require to be instantiated using WiFi UDP connection (afore initialized |
| <code c> | <code c> | ||
| ... | ... | ||
| Line 146: | Line 146: | ||
| </ | </ | ||
| - | Because UDP is asynchronous due to its nature, each transaction (sending a request and waiting for the response) must be handled | + | Because UDP is asynchronous due to its nature, each transaction (sending a request and waiting for the response) must be handled |
| The sample callback function may have the following parameters: | The sample callback function may have the following parameters: | ||
| <code c> | <code c> | ||
| Line 154: | Line 154: | ||
| </ | </ | ||
| - | As code runs asynchronously and many messages may come one by one, you should not process the '' | + | As code runs asynchronously and many messages may come one by one, you should not process the '' |
| <code c> | <code c> | ||
| ... | ... | ||
| Line 167: | Line 167: | ||
| </ | </ | ||
| - | <note tip>You may have a variety of frames received but the common is to " | + | <note tip>You may have a variety of frames received, but the common is to " |
| <code c> | <code c> | ||
| ... | ... | ||
| Line 177: | Line 177: | ||
| </ | </ | ||
| - | Once your callback function is ready it is time to send a request and wait for the callback function to be triggered when the response comes. | + | Once your callback function is ready, send a request and wait for the callback function to be triggered when the response comes. |
| <note warning> | <note warning> | ||
| <code c> | <code c> | ||
| Line 187: | Line 187: | ||
| - | Once the infrastructure is ready you can send a request and observe a response, i.e. in a '' | + | Once the infrastructure is ready, you can send a request and observe a response, i.e., in a '' |
| <code c> | <code c> | ||
| int msgid = coap.get(ip, | int msgid = coap.get(ip, | ||
| Line 195: | Line 195: | ||
| - IP address of the server you want to connect to ('' | - IP address of the server you want to connect to ('' | ||
| - port number ('' | - port number ('' | ||
| - | - URL, or actually its part coming AFTER the IP section of the URL. | + | - URL, or actually, its part coming AFTER the IP section of the URL. |
| - | Regarding last parameter, ''""'' | + | Regarding |
| ==== Networking ==== | ==== Networking ==== | ||
| - | There is a WiFi 2.4GHz, IPv4 network available to the students. This is a PRIVATE network. This network is separated from the Internet but all connected devices | + | There is a WiFi 2.4GHz, IPv4 network available to the students. This is a PRIVATE network. This network is separated from the Internet, but all connected devices can talk to one another. There is a DHCP server with networking addressing scope 192.168.90.10-192.168.90.254. In this laboratory scenario, you work ONLY on the PRIVATE network. |
| - | <note warning> | + | <note warning> |
| To connect to the wireless network, use the following credentials: | To connect to the wireless network, use the following credentials: | ||
| Line 213: | Line 213: | ||
| There is a CoAP server awaiting you. | There is a CoAP server awaiting you. | ||
| - | You can also access it from the aforementioned PRIVATE network, using the following configuration and credentials: | + | You can also access it from the aforementioned PRIVATE network using the following configuration and credentials: |
| * Address: 192.168.90.5 | * Address: 192.168.90.5 | ||
| * Port: 5683, coaps is not implemented | * Port: 5683, coaps is not implemented | ||
| Line 224: | Line 224: | ||
| ==== Laboratory scenarios ==== | ==== Laboratory scenarios ==== | ||
| You will implement two scenarios that you can bind into one code (or implement it as separate solutions) | You will implement two scenarios that you can bind into one code (or implement it as separate solutions) | ||
| - | <note tip>Mind keeping your code between meetings. It is regular that every next laboratory meeting you will extend your code by something extra.</ | ||
| - | < | ||
| === Scenario 1 === | === Scenario 1 === | ||
| Line 231: | Line 229: | ||
| Connect to the CoAP server for the hello world URI and display returned text messages in the Serial console. | Connect to the CoAP server for the hello world URI and display returned text messages in the Serial console. | ||
| - | < | + | Report: |
| + | * Document your code and present an approach towards including CoAP communication protocol into the code. | ||
| === Scenario 2 === | === Scenario 2 === | ||
| Line 238: | Line 237: | ||
| Report: | Report: | ||
| - | * Present results including | + | * Present results, including a photo of the LCD with a message (code). |
| - | < | + | |
en/edu/zmitac/s2/iotn/lab3.1647640599.txt.gz · Last modified: by pczekalski
