The iPhone Shortcuts App Script
Shortcuts is a free app included in any iOS device. Usage of Shortcuts app is kind of similar to the Spike Prime Word Block interface where user will select settings for each functional block and join them together.
In our script, we start by performing a Barcode scan to read the code for the program. Once barcode of the product is read, depending the product read, we will issue a different HTTP request to our Virtual Wireless Sensor. In our example:
- Coca Cola has barcode of 4890008100309
- Tonic Water has barcode of 4890008403363
If the scanned product is Coca Cola, we will send a “Force” raw value of 100 to the Virtual force Sensor. (We could use any sensor for our programming. In this example, we have chosen to use a Virtual Sensor.)
If the scanned product is Tonic Water, we will send a “Force” raw value of 10 to the Virtual force Sensor. (We could use any sensor for our programming. In this example, we have chosen to use a Virtual Sensor.)
Note that after the HTTP GET request to set the virtual sensor is sent, we wait 2 seconds to make sure the LEGO hub is able to detect the value, and then we must return the virtual sensor value back to zero so that the robot will not continuously perform the triggered action.
After everything finished, the script will run itself again so that the iPhone is ready to scan another product item.