The last time that I wrote, the wifi team had been struggling with where and how to send our data since we were no longer using dweepy. We had just launched our flask app on a raspberry pi that modeled a web server that we could send data to. The code that we were interested in using for the arduino was from an instructables and it was using an http post request instead of a get request. This was our main problem. Javier and I stayed after class today to work with Dr. Jadud and try and sort out the issues that we were having.

We knew that our send data function would have to take in the data struct that would be sent to us from the sensing team. This struct contained a key, tag, and value that we would need to send to the server. After inspecting the post request Dr. Jadud realized that it would only take a slight change to make our code work. Since he was familiar with the structure of Get Requests (the protocol), we were able to make the changes necessary in order to actually send our data. Because we were manipulating the uri to send the data using a get request, we stored the data.key, data.tag, and data.value inside the uri in their respective cases. We were monitoring any “pings” from outside machines to our flask app on the raspberry pi. At first we were unsure of what we were seeing, but after we changed the values inside the uri, we could see that we were making connections with the raspberry pi every time that we ran the code (or sent the get request).

The main part of our code looks like this:

  • First we make sure that we have a TCP connection to our server
  • Then we define our uri from the data struct:
    • String uri = “/” + data.key + “/” + data.tag + “/” + data.value + “/”;
  • Then we define our get request based on the correct protocol
    • String getRequest =
      • “GET ” + uri + ” HTTP/1.1\r\n” +
      • “Host: ” + server + “\r\n” +
      • “Connection: close\r\n” +
      • “\r\n”;
  • Next we send an AT command stating that we will send data and of what length
    • String sendCmd = “AT+CIPSEND=”;
    • esp.print(sendCmd);
    • esp.println(getRequest.length() );
    • delay(500);
  • Lastly we use the println() function to execute the get request
    • if(esp.find(“>”)) { Serial.println(“Sending..”); esp.print(getRequest);

We also finally figured out the breadboard setup that we need to follow and Chris has designed a diagram in fritzing to show the connections. We connected tx and rx to specific pins instead of the tx and rx on the arduino because we want the arduino to actually communicate with them rather than us communicate with the chip through the arduino ide. The setup looks like this: