Controlling the Fantastic Robot with WiFi

Controlling the Fantastic Robot with WiFi

Citilab Edutec tarafından

Boards
Kartlar:

Citilab ED1

Component/s
Bileşenler:

Yok
This activity is part of the Citilab Course. Check it out!

Controlling the Robot with WiFi

WiFi connection

  • To connect the board to a WiFi network or create one of your own, you need to import the WiFi library that is inside the Network folder.

WiFi Library

  • Once the library is open, we will use the corresponding block to connect to a Wi-Fi network by entering both the name of this network and the password.

connect to WiFi bllock

  • If we want to see the IP address assigned by the network to the board, we can use the IP address block.

IP address block

Challenge 1: Make a program that displays the IP address on the screen

Challenge

Solution to challenge 1

Web server

-To start a web server, you need to import the HTTP Server library which is also in the Network folder.

HTTP Server

  • The basic blocks to be able to manage requests to the server and to send responses are those of "HTTP request to the server", "path of the request []" and "reply [] to the HTTP request".

HTTP server blocks

Receiving requests

  • When a client connects to the HTTP server, its request is recorded in the "HTTP request …" block.

  • As they are actually text strings, one way to see if there is a request or not is to check that this block returns an empty result.

Receive requests 1

If you also want to respond with a text, click on the arrow in the "respond …" block and then change the text of the content.

Receive requests 2

Receive requests 3

Challenge 2: Run a web server on the board that responds with text to any request

Challenge

Solution to challenge 2

Application path

  • For a web server to perform different actions according to the request received, routes or paths are used.

Paths 1

  • The path of a web request is the text that we put after the name of an IP address or web domain in the browser bar, including the slash (/).

Paths 2

  • It is important to know that the "request …" block is emptied every time it is used, so you need to save its result to be able to work with it (for example with a variable).

Paths 3 Paths 4

Challenge 3: Make a web server that acts as an "echo", answering the same path text

Challenge

Solution to challenge 3

Manage requests

  • Now that we know how to identify the path used in the request we can make the board do things besides respond via web.

  • For example we can turn on or off the integrated LED of the sending board by specifying the "on" and "off" commands through the path to the request.

  • It's important to add a block that responds with something by default if you don't use any of the established paths, otherwise the browser will hang waiting for a response.

LED controlled with HTTP

Challenge 4: Make the robot move by sending commands through the browser

Challenge

Solution to challenge 4

CC-BY-SA

© Citilab Edutec tarafından 2019-2022.
This work is licensed under a CC-BY-SA 4.0 license.