-
Notifications
You must be signed in to change notification settings - Fork 7
Part 2. Basic HTTP POST
A POST usually consists of a URI and then the "content", which, in our case, is our data.
The way that the hub is designed to receive data, the URI that we post to contains the bucket name we want to send to and the name of our event signal (like temperature, humidity, etc.).
Here is an example POST:
POST http://Hub_IP_Address/Hub_Test/Signal1
Content-Type: text/plain
Content-Length: 2
18
Note: Content-Type and Content-Length are optional.
Returns are very important to the format of the POST, so make sure to always have 2 returns between the request/headers and the body.
In the above example, we are sending Signal1, whose current value is 18, to the bucket named "Hub_Test". You direct the POST to the hub by replacing "Hub_IP_Address" with your hub's IP address (i.e. 10.10.10.1). You can find the Pi's IP address with the command:
$ hostname -I
The hub itself will timestamp your data before sending it to Initial State.
An important thing to note is that the bucket name and signal name are inside of a URI, so they can't contain spaces and can only contain valid URI characters. The data in the body can look however you want!
Sending to the hub's IP address is only half of actually connecting the hub, however. You also need to open some sort of connection (like TCP) to the hub's port (which we set to 8080). The way you accomplish this depends on the device.