In this tutorial, we'll be using a Wia Dot One to retrieve a random beer and display the beer name to the TFT.
Tutorial: Beer Of The Day
Resources Needed :
To Get Started:
1. Account at Wia
You will need to be registered and / or logged in to your Wia account at https://www.wia.io/.
2. Create a Blocks Project
Drag over the starting “ Connect to Wifi” block for the Dot One to connect and establish a wifi connection .
Following this drag over the “Print to TFT” Block from the Modules tab in the editor This block is used to print anything to the TFT module and in our case it’s going to print the state of our device which contains the saved beer from our api call.
Configure the necessary settings to print to the TFT as per your wants (eg. background colour , font-size , scrolling ) settings.
Drag over the “get Device State “ block and link it to the text to print part of the “print to TFT “ block and set it to the device key that corresponds to the value where the beer is stored.
NB : Don’t forget to include a “Wait ? milliseconds” block and link it to the end of the “print to TFT” block to ensure the TFT doesn’t reload every second / very fast which creates a wave- like motion that is displayed on the screen
At the end your code project should look something like this :
3. Create a Flow
This flow will do all the back end heavy lifting for us from setting a timer to retrieve a different beer every minute to making an api call , parsing the data and updating the state.
This flow comprises of four nodes:
First drag the “timer” node in the trigger tab to the editor and configure it’s settings by clicking the radio button “every X minutes” . Optional: Change the dropdown to every 24 hours or so .
Next drag the “HTTP Service” node from the service tab to the editor and set the settings as follows
This node just enables us to make an api call to this website and retrieve a response back which we will then parse with our next node .
- Next drag over the “Run Function” node to the editor under the logic tab and configure the code to look like below:
This code just essentially takes our response we received from our previous api call and parses it , passing in a random number from one to 725 to retrieve a random beer from their database . Following this , the code just updates the output.body variable to be that of the random beer name we retrieved.
- Lastly, drag over a “Update State” from the logic tab and set up the options to look something similar to this:
This basically just identifies and picks the device you want to run this code on , inputs the state key you used in the code project that’ll correspond to the stored random beer value and changes the value for the state key to be that of the output.body variable which contains our random beer name.
4. Deploy the Code Project.
This is all the work needed to set up the Tutorial / Project outlined above.
Proceed back to the code project and Go ahead and deploy the code to your Dot One and you should see your TFT printing a random beer name every minute.
Congratulations and Well done , you have now completed the tutorial !