Preamble


The goal of these exercises is to take the same functionalities as in TP3, but reversing the roles : the Lolin D1 acts as the AP+TCP server.

 

 

Exercise 1 : wifi access point (AP) + TCP server creation

  • According to the summary on the web server ( bases of arduino programming (with esp8266) ), create a sketch to setup the µC into an AP.
  • CAUTIONS :
    • each student must choose a different ssid.
    • the password must be at least 8 characters long or the AP initialization will fail.
  • If you have your own ssid, you can keep 192.168.1.1 as an address for the µC. It will still be in a separate network, because of the different ssid.
  • When your sketch is compiling successfully, plug the D1 to the computer and open the sketch of TP3 that allows to connect to an AP.
  • Modify this sketch to put your own ssid/password.
  • Check with your laptop or your phone that there is effectively an AP with the ssid of your choice that appears and try to connect to it.

 

  • Once you obtain a successful connection, modify the sketch to add a WiFiServer object, using the port 12345.
  • Then, according to the course examples (see section 7.2), add :
    • a function to read lines of text (see template in TP3)
    • a function to wait for a client connection. As soon as the connection is established, the function waits for a line of texte containing only "0". Then, it sends back an id to the client. The id maybe initialized to 0 and incremented each time a new client connects.
    • a function to process the request STOREPOS. It must :
      • wait a first line of text, containing the id of the client.
      • wait for another line, with the format "x,y,z", where x, y, z are floating point number.
      • test if the id sent by the client is equal to the current id. If not, it sends back "ERR ID"
      • test if the second line is effectively composed of three floating point numbers separated by commas. If not, it sends back "ERR PARAM"
      • otherwise, it sends back "OK"
  • Finally, modify the loop() function so that, if a client is connected :
    • it waits for a line of text.
    • if this line is equal to "1" call the function to process STOREPOS request.

 

Exercise 2 : Java client

  • Write a small Java client, that is able to connect to an IP+port given as argument of the program (see templates)
  • After the connection and the creation of the communication streams over the socket, it sends a line of texte containing only "0" and waits for a line containing its id
  • Then, it sends a sequence of three lines, containing respectively :
    • "1"
    • its id
    • "1.2,3.4,5.6"
  • Finally, it reads and print the answer of the server.

 

  • Connect your laptop to the AP provided by the µC,
  • Start the Java client by giving the IP you chose for your server and 12345 for the port.
  • If everything is rightly implemented, you should get an "OK" answer from the server.

 

  • Modify your client to send a faulty third line, e.g. "1.2 3.4 5.6" and see if you obtain "ERR PARAM" as an answer.