his app allows a user to report energy waste by uploading to a server a location and message reporting on energy waste observed in the location. The app uses the Web component to communicate with a server, the LocationSensor component to identify the latitude and longitude of the user's location, and the TinyDB component to save previous messages that can be reused later.
The interface for this app is fairly simple:
The blocks for this app are below, and the aia file is attached at the bottom of the page:
When the screen is initialized a check is performed to see if there is a list called suggestions already in the TinyDB database. If there is not, then a new list will be created and stored in the database. This will only happen the first time the app is run.
The messagePicker is a ListPicker that allows the user to choose a previously entered message. BeforePicking sets the available elements to be the list of elements stored in the database with the tag suggestions.
AfterPicking the chosen message from the ListPicker is entered into the msgTextBox. This saves the user from having to reenter a message he/she has already used.
When the sendButton is clicked, first the URL is constructed. The base URL is http://energywatch.meteor.com/marker?. The BuildRequestData block is used to add the parameters to the URL. Each parameter is stored in a list of two items. The first item is the parameter name ( lat, lng, msg, and user). These names must be specified exactly as the server expects. The second item in each list is the value the parameter should take. In this case, the lat and lng parameters take their values from the LocationSensor readings. The msg and user parameters take their values from whatever the user has entered in the text boxes.
Once the URL is constructed, it is displayed in the Label just for debugging purposes.
Next, the call Web1.Get block is the block that connects to the web server and sends the data.
The call to the storenewmessage procedure will provide one piece of input: the message the user entered in the msgTextBox. The procedure (described below) will store the message in the database if it is not already there.
The clearTextBoxes procedure simply clears the text the user entered.
The storenewmessage procedure takes one piece of input, newmessage, that can be accessed in the procedure block. First, the procedure creates a local variable and sets that variable to be the list of messages stored in the database. It uses the GetValue block to retrieve the list that is store with tag suggestions. The right side of the condition used in the if block makes sure that the message the use entered is not blank. If the message is blank the procedure will do nothing. The left side of the condition makes sure that the message the user entered is not already in the list retrieved from the database. If the message is there then the procedure will do nothing. If the message is not in the list and the new message is not blank, the then instructions will be executed. The first instruction add the new message to the list. The second instruction stores this new list (containing the newest message) back into the database. Skipping the last instruction will mean that the new list is lost and the changes are not reflected in the database.