Lesson 5 Cloud Upload What you will need CloudProfessor (CPF) Temperature sensor Arduino Leonardo Arduino Shield USB cable Overview In the previous lessons, students learned how to retrieve data from sensors attached to the CloudProfessor such as light and temperature sensors. In this lesson, students will learn how to upload the value measured by attached sensors to cloud storage. Learning Objectives Use computer-based data logging to automatically record temperature data and upload it to the cloud. Understand and use variables. Understand the benefits and drawbacks of computer-based data logging. Learning Expectations (how learning / progress will be demonstrated) All Upload temperature data taken from the CloudProfessor to the cloud. Most Use variables in their app. Some Explain the benefits and drawbacks of computer-based data logging. Curriculum Links (Computing PoS) Designs simple algorithms using loops, and selection i.e. if statements. (AL) Uses logical reasoning to predict outcomes. (AL) Detects and corrects errors i.e. debugging, in algorithms. (AL) Creates programs that implement algorithms to achieve given goals. (AL) Understands that programming bridges the gap between algorithmic solutions and computers. (AB) Computational Thinking Concepts: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation. Lesson 5: Cloud Upload
Step-by-step instructions. Connect the power of CloudProfessor then press and hold the power button for two seconds; it will turn on and the power indicator will light up.. Insert the Arduino Shield into Arduino Leonardo and use the USB cable to connect the CloudProfessor with Arduino Leonardo. Attach the temperature sensor to port A.. When the CloudProfessor detects the Arduino Leonardo, a notification will appear on your device; click the notification to launch the Arduino Leonardo APP, and then select the CPF Arduino Blockly app. Click on Lesson 5. 4. Press the execute button to enter the control user interface (UI). 5. Press the edit button to enter the program editing page. Edit button Execute button CPF Arduino Blockly app Control user interface (UI) Program editing page Lesson 5: Cloud Upload
Exploring the code (Blockly) Let s explore the code.. Count with:. Set celsius to: The count with block executes the same task repeatedly for a specified number of times. The number of times the code is repeated is specified in the to block (). In this example, the code will be repeated 0 times. The Set celsius to block creates a variable called Celsius and stores the value of the temperature sensor in degrees Celsius.. Set date to: The Set date to block creates a variable called date and stores the current date/ time. 4. If / else: The if / else block is used to conditionally run code depending on whether a Boolean condition is true or false. In this example, a message will be uploaded to the cloud based on the value taken from the temperature sensor. When the value taken from the temperature sensor is greater than 8 degrees Celsius (If() is true), it will generate a Hot! Hot! Hot! message; otherwise, it will generate an I Love CPF message. 5. Set AOPstatus to: The Set AOPstatus to block creates a variable called AOPstatus which is used to store the data received as a JSON object ready for uploading to the cloud. JSON (JavaScript Object Notation) is a standard data exchange format commonly used in web applications. JSON can use lists or objects to write data. In this example, the JSON object will be used to upload the store number, temperature, message and time & date (). 6. Title Panel Set: The Title Panel Set block displays the value taken from the temperature sensor, the generated message and the current date & time on the screen in real-time () as it is uploaded to the cloud. Note: Unlike in previous lessons, there s no cpf.repeat Experiment with different intervals by changing the number in the Delay Time(Sec) block. Try swapping the temperature sensor with a light sensor and change the message based on the value from the light sensor. Lesson 5: Cloud Upload
Exploring the code (JavaScript) Let s explore the code.. for (index=; index<=0; index++) { The for() statement executes the same task repeatedly for a specified number of times. The number of times the code is repeated is specified in the first two sections of the for loop (). In this example, the code will be repeated 0 times.. var value = cpf.get( temperature sensor ); var value = cpf.get( temperature sensor ); returns the reading taken from the temperature sensor and stores the result in a variable called value. var celsius = tocelsius(value); converts the value taken from the temperature sensor to degrees Celsius.. var d = new Date(); The var d = new Date(); statement creates a variable called d and stores the current date/time. 4. If / else: The if / else block is used to conditionally run code depending on whether a Boolean condition is true or false. In this example, a message will be uploaded to the cloud based on the value taken from the temperature sensor. When the value taken from the temperature sensor is greater than 8 degrees Celsius (If() is true), it will generate a Hot! Hot! Hot! message; otherwise, it will generate an I Love CPF message. 5. var str = JSON.stringify(obj); var str = JSON.stringify(obj); creates a variable called obj which is used to store the data received as a JSON object ready for uploading to the cloud. JSON (JavaScript Object Notation) is a standard data exchange format commonly used in web applications. JSON can use lists or objects to write data. In this example, the JSON object will be used to upload the store number, temperature, message and time & date (). aop.setstore() is a CloudProfessor Java Script API; it is used to upload data to the CloudProfessor cloud platform. 6. ui.set( content, JSON content:\n + str); The ui.set statement displays the value taken from the temperature sensor, the generated message and the current date & time on the screen in real-time () as it is uploaded to the cloud Note: Unlike in previous lessons, there s no cpf.repeat(). Instead, the program will end after uploading 0 times. You can change the number of milliseconds in the cpf.sleep(000); line to change the upload time intervals. Experiment with different intervals by changing the number in the cpf.sleep(000); line. Try swapping the temperature sensor with a light sensor and change the message based on the value from the light sensor. 4 Lesson 5: Cloud Upload
4 Extension Students to replace the temperature sensor with a light sensor and re-create the Cookie Jar alarm from the first lesson. Students to program the CloudProfessor to record the exact date and time the cookie jar lid (or box lid) is opened and upload the results to the cloud. 5 Differentiation To support students, provide step by step guides. To stretch students ask them to create a flowchart / pseudocode of their code first or code their solution using JavaScript. 6 Homework Students to write up a summary of what they ve learned; students to include screenshots and snippets of their code in their summary. Students to research the benefits and drawbacks of computer-based data logging. Students can also explore how data is recorded to make weather predictions. 7 Links Sample weather data from weather stations across the UK: http://weather.lgfl.org.uk How cloud storage works: http://computer.howstuffworks.com/cloud-computing/cloud-storage.htm Benefits of data logging: http://www.bbc.co.uk/schools/gcsebitesize/ict/measurecontrol/dataloggingrev.shtml Disclaimer: Use these sites at your own risk. Acer is not responsible for the content of external Internet sites. We recommend that you check the suitability of any recommended websites links before giving them to students. 5 Lesson 5: Cloud Upload