

With a time stamp connected to each data point, we can show a webpage with the temperature and when it was measured. Our web API accepts data points, but it would be nice to see a time stamp of when the temperature was measured. read temp API Call Invalid The URL entered does not contain a valid API key or mac address TO HOME Adding time stamps It is a good practice to keep these sorts of private keys in a separate file and out of version control. This file will contain the API_key and mac address that is acceptable. On the server, create a new file called config.py. Now we need to program our flask IoT server to only accept URL's like the URL above, with a set of unique API_key's, mac addresses and limits on the field and data portions of the URL. If we put these 4 identifiers as part of our URL, our IoT server will provide the functionality the WiFi weather stations need.īelow is the general form of a web API url that is valid: This is a float, but can be limited by length.

Each of the ESP8266-based WiFi weather stations has a different mac address. A mac address: A mac address is a unique address assigned to each piece of hardware.I can set a unique API key that only I know. A user: Each WiFi weather station has a user.There are a couple unique aspects to each of the ESP8266-based WiFi weather stations. The data coming into our IoT server is only from two specific from ESP8266-based WiFi weather stations. This means that our flask IoT server will only accept certain API_key= and mac= strings as part of a web API URL. To build in a bit more security into our server, we'll utilize a form of data validation. Since an arbitrary string can be inserted as API_key or mac, that arbitrary string will be read by our flask IoT server.
PYTHON MAC ADDRESS BASED SERVER CODE
This allows anyone with an internet connection upload data to the server and potentially upload malicious code to the server. Right now, any string following API_key= and mac= can be inserted into the URL. data = 72.3 (to specify the temperature is 72.3 degrees).field = 1 (to specify this is a temperature data point, not a humidity data point).mac = 6c:rf:7f:2b:0e:g8 (to identify the ESP8255-based WiFi weather station).API_key = ASCIISTR (to identify the user).
PYTHON MAC ADDRESS BASED SERVER UPDATE

That's a fancy way of saying a server that saves input or produces output based on the URL someone types into their web browser. Why data validation?Ī web API is a web-based Application Programming Interface. We don't want just any WiFi weather station to upload data. What's not to like? Well right now any string added to the URL specified by our web API will get through. Now that we have a web API, we can make GET requests using a web browser and see the output in the web page flask sends back. Restart the flask app and view the changes.
