This is how to make a beer name generator using the Wia Cloud Platform and display it on your Wia TFT module.
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!