S3A7 with Activity Monitor – Quick Start Guide

LEVEL 2: INTERMEDIATE |

This tutorial uses the Renesas S3A7 IoT Fast Prototyping Kit with the Renesas IoT Sandbox to build an Activity Monitor application. This tutorial will show you how to build workflows starting from a S3A7 template project.

In this tutorial, you will:

  • Implement a pedometer based on the accelerometer data from the BMC150 sensor.
  • Visualize recorded data on the board display, as well as, in the Dashboard of Renesas IoT Sandbox.
  • Create a simple workflow to count the total number of steps done in a day.
  • Enter the user’s height and weight via an input widget to personalize the user’s reports.
  • Use the collected data and process it to generate a personalized activity report:
    • Calculate the overall walked distance: calculated off of a average step depending on user’s height
    • Calculate the number of calories burned: calculated based on distance walked  and user’s weight.
    • Calculate total walking time: tracking all individual walk times and adding them together.
  • Receive an email notifications: If (current steps – last reported steps) = 50, the workflow will email current number of steps to user’s specified email address.

Here’s a diagram of 8 workflows we will create in this tutorial:

 

HERE’S WHAT YOU NEED TO GET STARTED:

  1. Renesas Synergy S3A7 IoT Fast Prototyping Kit
  2. Micro USB cable to power up the board (part of the S3A7 IoT Fast Prototyping Kit)
  3. Bosch BMC150 PMOD module (available on the S3A7 IoT Fast Prototyping Kit box)
  4. WiFi Internet Access
  5. S3_IOT_Pedometer_1_1_3.srec image file (Download here)
  6. iOS or Android phone mobile app (Download here)

Estimated Time to Complete:

Prerequisites:

 

STEP 1: PROGRAM S3A7 BOARD WITH PEDOMETER IMAGE

Program the S3_IOT_Pedometer image to the S3A7 board following the instructions in the “How to flash the S3A7 board” tutorial. Be sure to download the latest release .srec file that is specific to this kit. This can be found in the HERE’S WHAT YOU NEED TO GET STARTED section.

 

STEP 2: ACTIVATE NEW S3A7 TEMPLATE PROJECT IN RENESAS IOT SANDBOX

Click here to activate a new S3A7 template project.  Once activation is completed, you will receive an email with your account credentials needed to provision the kit and access the cloud portal.

This email will include your:

  • Renesas IoT Sandbox web login
  • API Key
  • Device username and password
  • Mobile application credentials

You will connect your board to this project in a later step.

 

STEP 3: CONNECT THE S3A7 KIT TO THE CLOUD

Note: The S3A7 kit only works with 2.4GHz WiFi.

To simplify this step, you will first attach the sensor and then provision the board. However, the reverse order of these steps is also possible and acceptable.

Attach sensor:

●      Connect Bosch BMC150 PMOD module to J5 (PMODA) on board on the board.

Provision the Board for WiFi and Renesas IoT Sandbox API:

●      Power up the board by connecting the white microUSB cable found inside the white box into J1 on the board, and then either power with the external battery in this box or by connecting to the USB port to a laptop.  Touch the screen within 10 seconds of powering up the board to boot it up in provisioning mode and the board will become a WiFi Access Point.

●      When you see the screen below, connect to the board from a computer via the WiFi network printed at the top of the screen.  This is a Wifi Access Point served by the board and is a unique SSID.  Important: Lenovo and Dell laptops running Microsoft Windows consistently face trouble connecting with Wireless Module. MacBook, on the other hand, has shown no issues so far. If you’re not using MacBook, your best bet is to use your mobile phone. Note: Keep a copy of your activation email readily available.  Once connected to the board’s Wifi Access Point, you will not have internet access on your computer or mobile device.

●      Once connected, click on the link at the bottom of the activation email you received in Step 1. This autofills the following form with the configuration details specific to your project. Alternatively, you can open the provisioning page served by the board by going to  http://192.168.3.1 on your browser and manually entering the information yourself.

●      On the provisioning page, enter the WiFi information from your home or office network (the router which will be linked to the board). You will need to specify the router’s WiFi authentication mode.  If you’re not sure, most Wifi routers use WPA2, so try that first.  The other possible WiFi authentication modes are Open (non secure), WEP with 40 or 128 key, and WPA.   NOTE:  This is NOT the information from the board’s WiFi Access Point.

●      If you did not use the hyperlink in the email, manually enter the Renesas IoT Sandbox API credentials emailed to you when you activated the kit in Step 2.

●      After entering the information, click Connect.  This will automatically exit out of provision mode and you will see a “Provisioning complete” screen.

●      Log into your Renesas Sandbox Account with the information provided in one of the emails at https://app-renesas-na-sandbox.mediumone.com/login.

●      Next, power down the board by removing the micro USB cable.

 

STEP 4: SWITCH TO PROJECT ON RENESAS IOT SANDBOX

Login to Renesas IoT Sandbox with your web credentials. Select your newly created project in the top right drop down.

In order to switch between projects, click on “Your Project Name” in the top right.  Note, if you have other browser tabs open pointing to other projects, those sessions will be invalidated.

 

STEP 5: OBSERVE DATA ON BOARD’S LCD

In this step, you will observe the recorded number of steps, measured by the BMC150 Sensor attached to the S3A7 IoT Fast Prototyping Kit, on board display. Looking at the board display, you should be able to observe the number of steps equal to zero, as well as, the status to be “Idle”, as shown in the picture below.

Now shake the board for 10 seconds or so to simulate a person ‘walking’; you will be able to observe that the number of steps is increasing, and the status was changed to “Walking”.

As soon as you leave the board motionless, the increase in number of steps stops and the status will switch back to “Idle”.

The same observation can be seen in Real Time Events Log.  Status ‘0’ represents “Idle” while status ‘1’ represents “Walking” status. The number of steps starts increasing once the ‘walking’ status is reached.

 

STEP 6: UPDATE USER’S HEIGHT & WEIGHT

In this step, you will create workflows & input widgets to update the user’s height and weight. Later in this tutorial, you will use these values to adequately calculate the number of calories burned (based on input weight) and the distance walked (based on the input height that defines the length of an average step).

To do so, you will utilize various features of Renesas IoT Sandbox:

  • Create new raw tags “weight” and “height” by utilizing API explorer.
  • Enable newly generated tags.
  • Create input boxes to enter weight and height (via Dashboard’s User Input widget).
  • Create simple workflows to process and record the data.

 

 A. Create raw tags “weight” and “height”

In Renesas IoT Sandbox, go to Resources -> API Explorer.

 

Under Login to API, login with your credentials: username, password and API key.

Note: The credentials were set & emailed to you during Step 2, activation of your kit.

Note: Response code: 200 (true) indicates that you can use this user account to login to MQTT API for the project. If you didn’t get a correct response code, re-verify your user credentials and try again.

Now, you will create new raw tags called “weight” and “height”. Under Create Events, select:

stream_name:             raw

login_id:                       device

event_data:                 {“weight”:””, “height”:””}

Click SEND. If you didn’t observe successful response ‘200’, please correct errors and try again.

For further details on how to generate events, please visit Medium One Documentation Resources.

You just created a new raw tags called “weight” and “height”.  Now, you need to activate these tags.

 

B. Activate tags “weight” and “height”

In Renesas IoT Sandbox, go to Config -> Data Streams. Select raw Events by clicking Edit.

 

Activate the “height” and “weight” tags, then save by clicking on SAVE DATA STREAM.

 

C. Create input boxes to enter weight and height

In Renesas IoT Sandbox, go to Dashboard.  Click on Single User User Input Widget.

 

Select user:     device

Tag config:      raw:height, raw:weight

Note: The following picture shows an example of enabling the “height” tag in Tag Config.

 

You have created a user input box in which height and weight can be updated by user.

 

D. Create workflows to process height and weight

Create the first workflow and name it  “Update Height” by clicking on Workflow Studio and “Create”.

 

Drag the “height” tag from the raw stream into the workflow.

 

Double click on “height” tag and confirm that its Trigger is checked.

 

Drag Base Python from Modules and connect its “in1” input to the “height” tag.

 

Double click on Base Python, then delete and replace the Base Python script with the following code:

import MQTT
import Store

height = IONode.get_input('in1')['event_data']['value']
Store.set_data("height", height, -1)
message = "H" + height
MQTT.publish_event_to_client('s3a7', message)

 

Then click the SAVE AND ACTIVATE button to finish creating the workflow.

Create the second workflow and name it  “Update Weight” by clicking on Workflow Studio and “Create”. Drag the “weight” tag from the raw stream into the workflow. Double click on the “weight” tag and confirm that it’s Trigger is checked.

 

Similarly, drag a Base Python module and connect its “in1” input to the “weight” tag.

Your overall workflow should look as following:

 

Double click on Base Python, then delete and replace the Base Python script with the following code:

import MQTT
import Store

weight = IONode.get_input('in1')['event_data']['value']
Store.set_data("weight", weight, -1)
message = "W" + weight
MQTT.publish_event_to_client('s3a7', message)

 

Then click the SAVE AND ACTIVATE button to finish setting up the workflow.

 

CHECKPOINT

Before continuing to the next section, let’s quickly confirm that the height and weight can be easily updated via User Input widgets in the Dashboard of Renesas IoT Sandbox.

In the Dashboard’s User Input widget, type in ‘178’ for height, and ‘55’ for weight, then click ‘Send Event’ as shown below.

Note: The height unit is in cm, the weight unit is in kg.

 

The Real Time Event Log file shows the JSON format of updated events:

Alternatively, you can observe the change in height and weight directly on the board’s display:

 

STEP 7: STORE APPLICATION DATA

In this step, you will write a simple workflow that allows you to keep record of number of steps walked, the total distance walked, and number of calories burned.  Note: To get more detail on how the amount of calories burned and total distance walked are calculated, please refer to the Renesas App Note.

You will need to generate new tags, activate them and write a workflow to store the data.  All of the steps mentioned have been described in Step 6 in great detail, thus some details are omitted in this description.

Similarly as in Step 6, this section marks steps A – D to allow for better order of required steps.  Note: You will omit creation of input widgets (Step C) as no widget is necessary to store application data.

A. Create new raw tags “step”, “distance”, and “calories”

In Renesas IoT Sandbox, go to API Explorer and create new raw tags “step”, “distance”, and “calories”.

stream_name:             raw

login_id:                       device

event_data:                 {“step”:1, “distance”:1, “calories”:1}

 

Click SEND.  If you didn’t observe successful response ‘200’, please correct errors and try again.

 

B.  Activate new tags

In Renesas IoT Sandbox, activate new tags by going to Config -> Data Streams, select raw Events by clicking Edit.

 

Locate “step”, “distance”, and “calories” tags and if not activated, activate them by checking the box.

Save the activated tags by clicking on SAVE DATA STREAM.

 

D.  Create workflow to store the data

Now, you will create a workflow that stores the last recorded data: step, distance, and calories from the board.

Create a new workflow and name it  “Store App Data” by clicking on Workflow Studio and “Create”.

Drag “step”, “distance”, and “calories” tags from the raw stream into the workflow.

 

Double click on “step” tag and confirm that its Trigger is checked.

 

Similarly, double click on the “distance” and “calories” tags and confirm that its Trigger is checked.

Now, drag in a Base Python module. You will have to increase the number of inputs to Base Python module. To do so, double click on the module, then click Add Input until you have desired number of inputs.

 

 

Click “Save”; then, connect Base Python “in1” input to the “step” tag, “in2” input with the “distance tag, and “in3” input with the “calories” tag, as shown below.

 

Double click on Base Python, then delete and replace the Base Python script with the following code:

import Store
from datetime import datetime

last_step = IONode.get_input('in1')['event_data']['value']
last_distance = IONode.get_input('in2')['event_data']['value']
last_calories = IONode.get_input('in3')['event_data']['value']

Store.set_data("last_day", datetime.now().date().strftime('%d/%m/%Y'))
Store.set_data("last_step", str(last_step), -1)
Store.set_data("last_distance", "{0:.2f}".format(last_distance), -1)
Store.set_data("last_calories", "{0:.2f}".format(last_calories), -1)

Then click the SAVE AND ACTIVATE button to finish setting up the workflow.

 

CHECKPOINT

You have activated a workflow that stores the last received data. To visualize this data, go to Dashboard and select Last Value Table widget. Then, select “device” for user, “raw:step” and “raw:calories”, “raw:distance” in Tag Config.

Click SAVE.

Now you can view the last recorded values for calories, distance, and step. This data gets updated as soon as the new value is detected.

 

STEP 8: CALCULATE WALKING TIME & SYNCHRONIZE DATA

In this step, you will first calculate walking time based on walking status received from the board. If status changes from “walking” to “idle”, the workflow will calculate the delta time and add it to the total walking time. Then, you will create a second workflow to synchronize the following data between the board and the cloud: steps, distance, calories and walking time.

In order to calculate walking time, you need to create a new raw “status” tag, activate this tag, and then write a workflow to calculate walking time. All of the mentioned steps have been described in Step 6 in great detail, thus some details are omitted in this description.

Similarly as in Step 6, this section marks steps A – D to allow for better order of required steps.  Note: You will omit creation of input widgets (Step C) as no widget is necessary to store application data.

Note: The synchronization workflow is based on “connected” tag, which was automatically created during the activation step (Step 2). Thus, there is no need to use API Explorer to generate it.

 

A. Create new raw tag “status”

In Renesas IoT Sandbox, go to API Explorer and create a new raw tag “status”.

stream_name:             raw

login_id:                       device

event_data:                 {“status”:1}

 

Click SEND.  If you didn’t observe successful response ‘200’, please correct errors and try again.

 

B. Activate the new tag

In Renesas IoT Sandbox, activate the new tag by going to Config -> Data Streams, select raw Events by clicking Edit.

 

Locate the “status” tag and activate it by checking the box.

Note: In this tutorial, you will use “status” tag of type Number – Last Value.

Save the activated tag by clicking on SAVE DATA STREAM.

 

D.  Create workflows

Lastly, you will create two workflows; the first one will calculate the walking time, the second worfklow will synchronize data between the board and Renesas IoT Sandbox.

Let’s create the first workflow and name it  “Calculate Walking Time” by clicking on Workflow Studio and “Create”.

Drag the “status” tag from the raw stream into the workflow.

Double click on “status” tag and confirm that it’s Trigger is checked.

 

Similarly, drag a Base Python module and connect its “in1” input to the “status” tag.

Finally, drag a Processed Stream – Single module from Outputs and connect its “in1” to “out1” of Base Python.

 

Your overall workflow should look as following:

 

Double click on Base Python, then delete and replace the Base Python script with the following code:

import Store
import MQTT
from datetime import datetime

def format_seconds_to_hhmmss(seconds):
   hours = seconds // (60*60)
   seconds %= (60*60)
   minutes = seconds // 60
   seconds %= 60
   return "%02i:%02i:%02i" % (hours, minutes, seconds)

fmt = '%H:%M:%S'
current_status = str(IONode.get_input('in1')['event_data']['value'])
last_status = Store.get("last_status")
if (current_status != last_status):
   last_time = Store.get("last_time")
   current_time = datetime.now().time().strftime(fmt)
   tDelta = datetime.strptime(current_time, fmt) - datetime.strptime(last_time, fmt)
   Store.set_data("last_status", str(current_status), -1)
   Store.set_data("last_time", str(current_time), -1)

   if (last_status == "1"):
      walk_time = Store.get("walk_time")
      if walk_time is None:
      walk_time = 0
   else:
      walk_time = int(walk_time)
   walk_time += tDelta.seconds
   Store.set_data("walk_time", str(walk_time), -1)
   IONode.set_output('out1', {"walk_time": format_seconds_to_hhmmss(walk_time)})
   message = "T" + format_seconds_to_hhmmss(walk_time)
   MQTT.publish_event_to_client('s3a7', message)

Then click the SAVE AND ACTIVATE button to finish setting up the workflow.

 

Create the second workflow and name it  “Sync Data” by clicking on Workflow Studio and “Create”.

Drag the “connected” tag from the raw stream into the workflow.

Double click on “connected” tag and confirm that it’s Trigger is checked.

 

Similarly, drag a Base Python module and connect its “in1” input to the “connected” tag.

Your overall workflow should look as following:

Double click on Base Python, then delete and replace the Base Python script with the following code:

import MQTT
import Store
from datetime import datetime

def format_seconds_to_hhmmss(seconds):
   hours = seconds // (60*60)
   seconds %= (60*60)
   minutes = seconds // 60
   seconds %= 60
   return "%02i:%02i:%02i" % (hours, minutes, seconds)

Store.set_data("last_status", "0", -1)
Store.set_data("last_time", datetime.now().time().strftime('%H:%M:%S'))
height = Store.get("height")
weight = Store.get("weight")
last_day = Store.get("last_day")
today = datetime.now().date().strftime('%d/%m/%Y')

if (last_day == today):
   last_step = Store.get("last_step")
   last_distance = Store.get("last_distance")
   last_calories = Store.get("last_calories")
   walk_time = Store.get("walk_time")
   if walk_time is None:
      walk_time = 0
   else:
      Store.set_data("last_day", today)
      last_step = 0
      last_distance = 0
      last_calories = 0
      walk_time = 0
      Store.set_data("last_step", str(last_step), -1)
      Store.set_data("last_distance", str(last_distance), -1)
      Store.set_data("last_calories", str(last_calories), -1)
      Store.set_data("walk_time", str(walk_time), -1)
      Store.set_data("step_record", 0, -1)

   message = "S" + str(height) + "-" + str(weight) + "-" + today + "-" + str(last_step) + "-" + 
   str(last_distance) + "-" + str(last_calories) + "-" + format_seconds_to_hhmmss(int(walk_time))
   MQTT.publish_event_to_client('s3a7', message)

Then click the SAVE AND ACTIVATE button to finish setting up the workflow.

CHECKPOINT

To demonstrate the accumulation of walk time, do multiple, short walking intervals with the board. Every time the status changes from ‘walking’ to ‘idle’, the walk time on the board display will add the latest walking interval to the current value of walk time.

 

STEP 9: UPDATE EMAIL & RECEIVE EMAIL NOTIFICATIONS

In this step, you will create two workflows. The first workflow will allow the user to change/update the email address. You will need to create a new “email” tag for this workflow.

The second workflow will notify the user (via email) every new 50 steps that has been achieved. For this notification, you can use the already created “step” tag.

Similarly as in Step 6, this section marks steps A – D to allow for better order of required steps.

 

A.  Create new raw tag “email”

In Renesas IoT Sandbox, go to API Explorer and create a new raw tag “email”.

stream_name:              raw

login_id:                       device

event_data:                 {“email”:””}

 

Click SEND.  If you didn’t observe successful response ‘200’, please correct errors and try again.

 

B.  Activate new tag

In Renesas IoT Sandbox, activate the new tag by going to Config -> Data Streams, select raw Events by clicking Edit.

 

Locate “email” tag and activate it by checking the box.

 

Save the activated tags by clicking on SAVE DATA STREAM.

 

C.  Create input boxes to enter data

In Renesas IoT Sandbox, go to Dashboard; then click on Single User User Input Widget; then select:

Select user:     device

Tag config:      raw:email

 

Your User Input widget should look similar to this:

 

D.  Create workflows

Now, you will create two workflows; the first workflow will process getting user email from the dashboard widget and store the information in the cloud. The second workflow will send the email notification once a preset number of steps has been achieved.

Create the first workflow and name it  “Update Email” by clicking on Workflow Studio and “Create”.

Drag the “email” tag from the raw stream into the workflow.

Double click on “email” tag and confirm that it’s Trigger is checked.

 

Similarly, drag a Base Python module and connect its “in1” input to the “user_email” tag.

Your overall workflow should look as following:

 

Double click on Base Python, then delete and replace the Base Python script with the following code:

import Store
user_email = IONode.get_input('in1')['event_data']['value']
Store.set_data("user_email", user_email, -1)

Then click the SAVE AND ACTIVATE button to finish setting up the workflow.

Create the second workflow and name it  “Email Notification” by clicking on Workflow Studio and “Create”.

Drag the “step” tag from the raw stream into the workflow.

Double click on “step” tag and confirm that it’s Trigger is checked.

 

Similarly, drag a Base Python module and connect its “in1” input with the celsius tag.

Your overall workflow should look as following:

 

Double click on Base Python, then delete and replace the Base Python script with the following code:

import MQTT
import Store
from datetime import datetime
import Email

step = IONode.get_input('in1')['event_data']['value']
step_record = Store.get("step_record")
if ((step - int(step_record)) >= 50):
    # Step to notification
    step_record = step - (step % 50)
    # Get user email
    user_email = Store.get("user_email")
    # Prepare email content
    message = "Congrats! You reached {0} steps today ({1}).".format(step_record, datetime.now().strftime("%A, %d %b %Y, %I:%M%p"));
    # Send email
    try:
        email = Email.Email("support@medium.one", 'Renesas IoT Sandbox', user_email, 'Activity Monitor Notifications')
        email.html_message(message)
        email.send()
    except Exception:
        log("Unable to send Email")
    # Record step to notification 
    Store.set_data("step_record", str(step_record), -1)

 

Then click the SAVE AND ACTIVATE button to finish setting up the workflow.

 

CHECKPOINT

In Dashboard’s User Input widget, set your email address as shown below; then click on ‘Send Event”.

 

Take a quick note of the number of steps currently located on your board’s display.

Start walking with your board until (current steps – last reported steps) >= 50; then, you should get an email notification similar to below. In this example, the user received two consecutive notifications. First when he walked 50 steps reaching a total number of 700 walked steps.  Second when the user walked another 50 steps reaching the total number of 750 walked steps.

 

STEP 10: RECEIVE DAILY REPORT

In this final step, you will create a workflow to receive a daily email report from your pedometer. The daily report contains total number of steps, walked distance in meters, number of calories burned on this day.  Afterwards, all data are reset to 0.

Create a workflow and name it  “Daily Report” by clicking on Workflow Studio and “Create”.

Drag the “date” tag from the raw stream into the workflow.

Double click on “date” tag and confirm that it’s Trigger is checked.

 

Similarly, drag a Base Python module and connect its “in1” input with the “date” tag.

Your overall workflow should look as following:

 

Double click on Base Python, then delete and replace the Base Python script with the following code:

import MQTT
import Store
import Email
import numbers
from datetime import datetime

def format_seconds_to_hhmmss(seconds):
    hours = seconds // (60*60)
    seconds %= (60*60)
    minutes = seconds // 60
    seconds %= 60
    return "%02i:%02i:%02i" % (hours, minutes, seconds)

# Helper to replace values in the HTML
def replace_vars(h):
    v = globals()
    for name in v:
        val = v[name]
        if (isinstance(val, numbers.Number)):
            if (isinstance(val, (long, float))):
                val = format(val, '0.2f')
            else:
                val = str(val)
        h = h.replace("{{" + name + "}}", str(val))
    return h

# Compare last day with today
date = str(IONode.get_input('in1')['event_data']['value'])
today = datetime.now().date().strftime('%d/%m/%Y')

if (date != today):
    # Read current data
    project_name = 'Activity Monitor'
    last_day = Store.get('last_day')
    last_step = Store.get('last_step')
    last_distance = Store.get('last_distance')
    last_calories = Store.get('last_calories')
    walk_time = format_seconds_to_hhmmss(int(Store.get('walk_time')))

    # Create html report
    html = '''
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=TF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <style type="text/css">
        body, table, td, p, a, li, blockquote {
            -webkit-text-size-adjust: 100%;
            -ms-text-size-adjust: 100%;
        }

        table, td {
            mso-table-lspace: 0pt;
            mso-table-rspace: 0pt;
        }

        /* /\\/\\/\\/\\/\\/\\/\\/\\/ RESET STYLES /\\/\\/\\/\\/\\/\\/\\/\\/ */
        body, #bodyTable, #bodyCell {
            height: 100% !important;
            width: 100% !important;
            margin: 0;
            padding: 0;
        }

        table {
            border-collapse: collapse !important;
        }

        /* /\\/\\/\\/\\/\\/\\/\\/\\/ MOBILE STYLES /\\/\\/\\/\\/\\/\\/\\/\\/ */
        @media only screen and (max-width: 480px) {
            /* /\\/\\/\\/\\/\\/\\/ CLIENT-SPECIFIC STYLES /\\/\\/\\/\\/\\/\\/ */
            body {
                width: 100% !important;
                min-width: 100% !important;
            }

            /* /\\/\\/\\/\\/\\/\\/ RESET STYLES /\\/\\/\\/\\/\\/\\/ */
            td[id="bodyCell"] {
                padding: 30px 0 !important;
            }

            table[id="emailContainer"] {
                max-width: 600px !important;
                width: 100% !important;
            }

            td[class="mobilePadding"], td[class="bodyContent"] {
                padding-right: 20px !important;
                padding-left: 20px !important;
            }

            /* /\\/\\/\\/\\/\\/\\/ ELEMENT STYLES /\\/\\/\\/\\/\\/\\/ */
            h1 {
                font-size: 23px !important;
            }

            td[class="bodyContent"] {
                font-size: 18px !important;
            }

            td[class="footerContent"] {
                font-size: 15px !important;
                padding-right: 15px;
                padding-bottom: 30px;
                padding-left: 15px;
            }

            table[id="utilityLinkBlock"] {
                border-top: 1px solid #E5E5E5;
                max-width: 600px !important;
                width: 100% !important;
            }

            td[class="utilityLink"] {
                background-color: #E1E1E1 !important;
                border-bottom: 10px solid #F2F2F2;
                display: block !important;
                font-size: 15px !important;
                padding: 15px 0 !important;
                text-align: center !important;
                width: 100% !important;
            }

            td[class="utilityLink"] a {
                color: #606060 !important;
                display: block !important;
                text-decoration: none !important;
            }
        }
    </style>
</head>
<body style="background-color:#F2F2F2;">
<center>
    <table border="0" cellpadding="0" cellspacing="0" id="bodyTable" style="background-color:#FFFFFF;">
        <tbody>
        <tr>
            <td align="center" valign="top" id="bodyCell">
                <table border="0" cellpadding="0" cellspacing="0" id="emailContainer" style="width:600px;">
                    <tbody>
                    <tr>
                        <td align="center" valign="top" style="padding-bottom:30px;"><br>
                            <table border="0" cellpadding="0" cellspacing="0" width="100%" id="emailBody"
                                   style="background-color:#FFFFFF; border-collapse:separate !important; border-radius:4px;">
                                <tbody>
                                <tr>
                                    <td align="left" valign="top" class="bodyContent" border-top:1px="" dotted=""
                                        #cccccc;="" color:#606060;="" font-family:raleway,helvetica=""
                                        neue,helvetica,arial,sans-serif;="" font-size:15px;="" line-height:150%;=""
                                        padding-top:40px;="" padding-right:40px;="" padding-bottom:0;=""
                                        padding-left:40px;="" text-align:left;
                                    "="">
                                    <center>
                                        <h1 style="color:#606060 !important; font-family:Raleway,Helvetica Neue,Helvetica,Arial,sans-serif; font-size:26px; font-weight:bold; letter-spacing:-1px; line-height:115%; margin:0; padding:0; text-align:left;">
                                            Daily Report for {{project_name}}
                                        </h1>
                                    </center>
                                    </td>
                                </tr>

                                <tr>
                                    <td align="left" valign="top" class="mobilePadding"
                                        style="padding-top:40px; padding-right:40px; padding-bottom:0; padding-left:40px;">
                                        <table border="0" cellpadding="0" cellspacing="0" width="100%">
                                            <tbody>
                                            <tr>
                                                <td style="border-bottom:1px dotted #CCCCCC; padding-top:10px;padding-bottom:10px;">
                                                    <h2 style="color:#606060 !important; font-family:Raleway,Helvetica Neue,Helvetica,Arial,sans-serif; font-size:26px; font-weight:lighter; letter-spacing:-.5px; line-height:115%; margin:0; padding:0; text-align:left;">
                                                        Last Day Activity
                                                    </h2>
                                                </td>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="left" valign="top" class="bodyContent"
                                        style="color:#606060; font-family:Raleway,Helvetica Neue,Helvetica,Arial,sans-serif; font-size:15px; line-height:150%; padding-top:40px; padding-right:40px; padding-bottom:0px; padding-left:80px; text-align:left;">
                                        <b>Date:</b> {{last_day}}<br>
                                        <b>Step:</b> {{last_step}}<br>
                                        <b>Distance:</b> {{last_distance}} m<br>
                                        <b>Calories:</b> {{last_calories}} cal<br>
                                        <b>Walktime:</b> {{walk_time}}<br>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </td>
        </tr>
        </tbody>
    </table>
</center>
</body>
</html>
'''

    # Replace all variables in the HTML above
    html = replace_vars(html)

    # Send daily report
    try:
        email = Email.Email("support@medium.one", 'Renesas IoT Sandbox', Store.get("user_email"), 'Activity Monitor Daily Report')
        email.html_message(html)
        email.send()
    except Exception:
        log("Unable to send Email")

    # Reset data
    Store.set_data("last_day", today)
    Store.set_data("last_step", str(0), -1)
    Store.set_data("last_distance", str(0), -1)
    Store.set_data("last_calories", str(0), -1)
    Store.set_data("walk_time", str(0), -1)
    Store.set_data("step_record", str(0), -1)
    message = "R" + today
    MQTT.publish_event_to_client('s3a7', message)

 

Then click the SAVE AND ACTIVATE button to finish setting up the workflow.

CHECKPOINT

Congratulations! This concludes the S3A7 Activity Monitor tutorial for Renesas Synergy S3A7 IoT Fast Prototyping Kit. You have implemented a simple pedometer by utilizing the accelerometer data from a BMC150 sensor. The recorded data was used to report total number of steps made in a day, along with the number of calories burned, total distance walked etc.

You have learned how to display and visualize data received in Renesas IoT Sandbox environment, you learned to email notifications, as well as, receive a daily activity monitoring report.

The rest is to your imagination!

 

WHAT’S NEXT?

Try another S3A7 Renesas Synergy IoT Fast Prototyping Kit quick start guide:

S3A7 Sensirion Sensor Tutorial (Level: Intermediate)

S3A7 with Smart Garage Monitoring Demo (Level: Advanced)