AE-CLOUD2 WITH SYNERGY SSP 1.5.0

LEVEL 2: INTERMEDIATE |

In this guide, you will learn how to set up an AE-CLOUD2 kit with the Medium One Prototyping Sandbox for Renesas Kits with either Ethernet, Wi-Fi, or Cellular connectivity. Then, you’ll login and view temperature, pressure, humidity, vibration, and noise level data on the Dashboard.

HERE’S WHAT YOU NEED TO GET STARTED:

  1. Renesas Synergy AE-CLOUD2 Kit (Order Here)
  2. Computer (tested on Windows and Mac)
  3. Ethernet Cable with Internet access, Wi-Fi (2.4 GHz), or an activated IoT SIM Card

PREREQUISITES:

  • Medium One Prototyping Sandbox for Renesas Kits Getting Start Guide (Optional)
  • AE-CLOUD2 Diagnostics Intelligence binary (download)
  • AE-CLOUD2 Diagnostics Intelligence source code git repository (Optional)

 

OPTIONAL: PROGRAM THE AE-CLOUD2 BOARD

This step is required if you have changed the firmware from the factory image.  Program the AE-CLOUD2 image to the AE-CLOUD2 board following the instructions in the “HOW TO FLASH THE AE-CLOUD2 BOARD TO FACTORY DEFAULT” tutorial. Be sure to download the latest release .srec in the prerequisites above.

 

STEP 1: ACTIVATE KIT IN MEDIUM ONE PROTOTYPING SANDBOX FOR RENESAS KITS

Click here to activate the kit and complete the registration process to create a Medium One Prototyping Sandbox for Renesas Kits project preloaded with the workflows. You must create a new project for this kit, even if you already have other projects on the Medium One Prototyping Sandbox for Renesas Kits. Once activation is completed, you will receive an email with your account credentials needed to provision the kit and access the cloud portal.

Note: This process will automatically create a Sandbox project for you, there will be no need to create an additional project after this step.

This email will include your:

  • Medium One Prototyping Sandbox for Renesas Kits web login
  • API Key
  • MQTT Project ID
  • MQTT Registration User ID
  • Registration User password

The email will also include a .txt attachment that you will drag into your board to auto-enroll in a later next step. To learn more about how auto-enrollment works, view Appendix C.

 

OPTIONAL: CONNECT SHIELD TO ENABLE GPS

If you would like to receive GPS data, connect the cellular Arduino shield (board) to the AE-CLOUD2 kit. Connect the GPS antenna to the GPS antenna SMA connector on the cellular Arduino shield (board).

 

STEP 2: CONNECTING TO CELLULAR, WI-FI, OR ETHERNET

This AE-CLOUD2 kit allows you to choose to connect to the internet via Cellular, Wi-Fi or Ethernet. The mode should be specified by creating a text file called net_cfg.txt on the kit. If this file does not exist, such as with a brand-new kit, the kit will automatically try to connect via Ethernet first, then cellular (it will not attempt to connect via Wi-Fi).

To specify which connection you will use, perform the following steps:

  1. Connect the USB cable from your AE-CLOUD2 MCU board USB port (not DBG) into your computer and after some time it should show up as a USB Drive (can take up to 2 minutes). Open the folder.

Note: There may be other files also in the directory.

2.  Create a new text file net_cfg.txt. Open the file.

3.  Type in one of the following:

a.  For ethernet: “ethernet”

b.  For WiFi: “wifi”

c.  For cellular: “cellular”

4. Save the file.

If you want to connect via Ethernet, connect the Ethernet cable then skip to the next step.

To be able to connect to Wi-Fi, you’ll need a Wi-Fi PMOD module attached to the AE-CLOUD2 MCU board. The following steps will instruct you how to set this up and specify the Wi-Fi credentials.

  1. Connect the Wi-Fi PMOD module to the AE-CLOUD2 MCU board

2. Plug your AE-CLOUD2 MCU board into your computer and it should show up as a USB Drive. Open the folder.

Note: There may be other files also in the directory.

3. Create a new text file ‘wifi_info.txt.’ Open the file

4. Save the file with the following configuration:

SSID
PASSWORD
SECURITY
MODE

Where you must replace each of the above with the following:

SSID – SSID of the Wi-Fi AP
PASSWORD – passphrase for the Wi-Fi AP
SECURITY – OPEN, WEP, WPA, WPA2 (default: WPA2)
MODE – CLIENT (only CLIENT mode is supported)

 

If you decide to use cellular, you will need an AT&T micro-SIM card on an activated IoT plan. Insert the micro-SIM card into the cellular Arduino shield (board) micro-SIM slot and insert the cellular Arduino shield (board) into the AE-CLOUD2 MCU board:

Next, you will connect your AE-CLOUD2 kit to the Medium One Prototyping Sandbox for Renesas Kits project you’ve created earlier in step 1.

If you encounter issues establishing cellular connectivity, please refer to these tips for configuring carrier settings: https://en-support.renesas.com/knowledgeBase/18027787.

 

STEP 3: CONNECT THE AE-CLOUD2 KIT TO THE CLOUD

This step is to connect your AE-CLOUD2 kit to the cloud and auto-enroll an API Basic User in your project.

  1. If you have not already done so, plug your AE-CLOUD2 kit to your computer and it should show up as a USB Drive. Open the folder.
  2. Download the file named “m1config.txt” from your welcome email that you’ve received from Step 2. Do not change the file name. The email should have these credentials on each line:
    1. On the first line, the API Key
    2. On the second line, the MQTT Project ID
    3. On the third line, the MQTT Registration User ID
    4. On the last line, the Registration User Password

 

Sample m1config.txt:

  1. Drag this file into the kit directory. Wait several seconds, then unplug the kit and plug it back in. Make sure it is still connected to the Ethernet cable or Wi-Fi PMOD module or cellular Arduino shield (board).
  2. After a few moments, both the green and yellow LED on the MCU board will turn on. This signifies that the kit is trying to connect to the internet and your Medium One Prototyping Sandbox for Renesas Kits credentials (via m1config.txt file). Once connected, only the green LED light on the MCU board should be on. If the kit can’t connect for some reason, all 3 LED lights (red, yellow, green) on the MCU board will simultaneously blink on and off. If this happens, verify the “m1config.txt” file is correct and your internet source is working.

 

STEP 4: VISUALIZE DATA ON DASHBOARD

Now that your kit is connected to the Medium One Prototyping Sandbox for Renesas Kits, you can view data being sent from the kit to the cloud. Log in to Medium One Prototyping Sandbox for Renesas Kits. Once logged in, make sure you are in the correct project on the upper right-hand corner.

Note, for some data points, you may need to wait up to 15 minutes to see the data on the dashboard.  The board transmits data once every 15 minutes by default.

If you are not in the correct project, click on the drop-down list next to the symbol and select the project name that you just activated in Step 2.

Click on the Dashboard and you should see a preset Dashboard with five widgets. They each have a red-bordered box with ‘Select User’ as pictured:

Click on the drop-down and select your user on all five of the widgets. Your user is generated by each board’s chip unique ID fused onto the silicone. For any given kit, the username is always the same. If you do not see any user listed, there was a problem with auto-enrollment. To debug this, view Appendix C.

Now scroll to the top of the Dashboard and click the save icon:

This is so you can save your Dashboard ‘View’ and not have to re-select your kit’s user each time.

There are two types of events sent from the kit to Medium One Prototyping Sandbox for Renesas Kits:

Summary Events

These events are always sent every 15 minutes by default. A summary event contains the average values from each of the sensor readings within the past 15 minutes. The sensors included are temperature, pressure, humidity, noise level, and vibration stats. To change the frequency of these summary events, view Appendix A.

Threshold Events

These events are sent whenever a sensor reading passes a certain threshold.  To change these thresholds, view the Appendix A

At the top of the Dashboard, you will see a Last Value Table widget. This widget only records the last entered value of that tag, along with the observed at time-stamp (in UTC). You can use this widget to see the last time the board status was ‘on’ and the last values for city, country, firmware version, WAN IP, LAN IP, and MAC address. For this tutorial, first, make sure that your board is connected by seeing the rows filled with the value and time-stamps. If there is nothing in the ‘value’ and ‘last observed at’ columns, your board has had problems connecting to the cloud. You may need to click the refresh icon 

to update the widget with the latest data.

After your kit has been connected for at least 15 minutes, it’s first summary event should be sent in. When this happens, the Real Time Gauge widget on your Dashboard should be updated with values like below. These values are the averages of the sensor for the past 15 minutes. It will continue to be updated every time a summary event is received.

Next, you will see a Table widget. This widget presents all the data from the Humidity, Noise, Pressure, and Temperature sensors sorted by most recent. Using this widget, you can see the sensor value changes over time as well as the last time the kit sent an ‘online event.’ Click the refresh button  to update the table if any new data is received.

Under the table widget is located the Cross Filter Chart widget. This widget displays the analog_channel1 data for the past day. Furthermore, you can add filters based on time range and voltage levels. To refresh the widget and see updated data, click the refresh button. To customize this widget, view the diagram below and the captions that correspond to the numbers.

  1. User selector. Here, you select the unique username for your board. The red box next to it is the Tag selector. By default, it is raw.analog_channel1.avg.
  2. Date selector. By default, it is the past 24 hours. You can customize the date range.
  3. Filter charts. These charts are used to filter your data in the main chart (#4).
  4. Main chart. Your values for the selected tag are displayed in this chart. You can filter the data by time of date, date range, and values by the filter charts (#3)

The last pre-set widget on the Dashboard is the User Input widget. This widget does not display data but instead allows you to send data. For this tutorial, you will use this widget to control the LEDs in the next step.

To learn more about widgets, check out the Widgets Documentation.

 

STEP 5: LED TOGGLE AND BLINK

On the Dashboard, scroll down until you see the User Input widget. Your board’s username on the drop-down should already be selected.

Now we will send events from the cloud to the board to toggle and blink the LED lights.

Blink

On the User Input widget, go to the box that says ‘Blink.’ Type in the number of times you wish to make the red LED3 blink; for demo purposes, pick a number under 10, then click ‘Send Event.’

The red LED3 on the board will blink the number of times you specified. You should also see this event appear in the Real Time Events Stream widget on the dashboard.

Toggle

On the User Input widget, go to the box that says ‘Toggle.’ To turn on the yellow LED (LED2), type in ‘1’.  Click ‘Send Event.’ You should see this event appear in the Real Time Events Stream widget on the dashboard. The yellow LED (LED2) on the MCU board will also turn on. To turn it off, type in ‘0’ and click ‘Send Event.’ If any number other than 0 or 1 is used, it will change states from off to on or vice versa.

To learn more about how toggle and blink works, view the ‘LED Toggle and Blink’ Workflow in Workflow Studio or view Appendix B .

 

STEP 6: NOISE DETECTION WORKFLOW

In this step, you will create a workflow from scratch to be able to detect noise.

First, you’ll need to activate a tag that you will be using in the workflow. Navigate to Config > Data Streams on the left sidebar.

Hovering over the ‘raw’ stream, click on ‘Edit’. This will open up a page that shows all the tags transmitted from the board to the cloud.

Scroll down the list and look for the tag “raw.mic.value”

Verify the tag is selected by making sure the checkbox is checked. Then, scroll to the bottom and click ‘Save Data Stream.’

You will now have access to use that tag throughout Medium One Prototyping Sandbox for Renesas Kits. Now you can build your workflow that will be triggered by this tag.

Navigate to “Workflow Studio” on the left sidebar.

Click on ‘Create.’

This will open a new blank workflow canvas.

In the name text area, type “Noise Detection” and click anywhere else on the canvas to save the name.

Click on the “Tags & Triggers” icon on the right sidebar. This is where you will specify when the workflow will run.

Click on “raw” and then look for “mic.value”. Click and drag “mic.value” onto the white canvas.

Next, click on the “Modules” icon on the right sidebar. Under “Foundation”, click and drag “Base Python” into the canvas.

Connect the nodes between the two boxes by clicking on the output node of the “raw.mic.value” box and dragging to the input node of the “Base Python” box labelled “in1”.

Next, click on Outputs on the right sidebar.

Click on the “Output” drop-down and click and drag “Processed Stream – Single” onto the canvas. Connect the node to the “Base Python” module.

Double click on the “Base Python” blue box. A popup should appear.

Copy and paste the following script into the “script” text area:

# library to get current time for output event and email body
import datetime
# library to store persistent data
import Store
# library to send email
import Email


# Get input data from input named 'in1', in this case mic input level
noise = IONode.get_input('in1')['event_data']['value']

min = 600
noise_detected = 0

if noise > min:
    noise_detected = 1
    
if noise_detected:
    now = datetime.datetime.utcnow().isoformat()
    IONode.set_output("out1", {"last_noise_detected": now})
    # we will only send alerts once a day
    if not Store.get('alert_sent'):
        # build a basic html message
        html = "<html><body>Noise was detected at {}</body></html>".format(now)
        email = Email.Email("support@medium.one", 'My workflow', '<your-email-here>', "Noise Detected")
        email.html_message(html)
        email.send()
        Store.set_data('alert_sent', 'true', 60 * 60 * 24)

Make sure to replace <your-email-here> with your email address.

Click ‘Save and Activate.’

You’ve just created a workflow that will output an event with the tag “last_noise_detected” with the value of the time-stamp whenever your board detects a loud noise. This workflow will also send you an email, no more than once a day, when a loud noise is detected.

To test this workflow, navigate back to the Dashboard. The first widget should be the Last Value Table. Click on the “Tag Config” settings gear icon. Locate “processed:last_noise_detected” and click on the checkbox next to it. Save. If you cannot find the tag, you may need to refresh the page.

A new row should have been added to your Last Value Table widget with the timestamp of the last time noise was detected.

Trigger this workflow by making noise near the board. The mic on the board may not be as sensitive so you may need to make a loud noise.

After a moment, the “processed:last_noise_detected” value should have been updated with a new time-stamp.

Remember to click on the ‘Save’ icon to keep this new addition to your Dashboard.

 

WHAT’S NEXT?

Congratulations! You’ve successfully connected your AE-CLOUD2 kit and sent data to the Medium One Prototyping Sandbox for Renesas Kits. You are now familiar with AE-CLOUD2 Kit, Medium One Prototyping Sandbox for Renesas Kits platform, and just tapped into the possibility of exciting new projects.

 

APPENDIX A:

Changing the Sample Period and Thresholds

Navigate to the ‘Update Sample Period and Thresholds’ Workflow in the Workflow Studio.

Double-click on the ‘Base Python’ box to view the workflow’s code. Follow the directions in the workflow comments to change either the sample period or threshold.

SAMPLE PERIOD

This is the time before a ‘summary event’ is sent from the kit to the cloud. This ‘summary event’ includes the average values across all sensors on the MCU board and will be sent as long as the kit is connected.

THRESHOLDS

This is the threshold a certain sensor much reach before a ‘threshold event’ is sent.

You must reset the kit for any of these changes to take effect.

 

APPENDIX B:

Changing LED Settings

Navigate to the ‘LED Toggle and Blink’ Workflow

Double-click on the ‘Base Python’ box to view the workflow’s code. In this workflow, an event is sent to the board in the format of ‘L2:’ for toggle or ‘B4:’ for blink. The ‘2’ and ‘4’ specify which LED to toggle/blink. Change this number to

the following values to change the LEDs controlled:

These numbers correspond to the following lights:

  • Green: 1
  • Yellow: 2
  • Green + Yellow: 3
  • Red: 4
  • Green + Red: 5
  • Yellow + Red: 6
  • Green + Yellow + Red: 7

Once changed, you will need to ‘Save and Activate’ and your changes should take place immediately.

 

APPENDIX C:

Auto-Enrollment

This kit introduces an auto-enrollment process that connects your board with Medium One Prototyping Sandbox for Renesas Kits and automatically creates an API user specifically for your board. The username is generated by the unique ID on the kit’s chip. The auto-enrollment process takes place in Step 3 of this tutorial when you put the ‘m1config.txt’ file with your credentials onto the kit through USB. The new credentials are stored in the data flash. If erased, auto-provisioning it will reset the password.

What if I lost my welcome email with the ‘m1config.txt’?

You will need to re-create it by creating a new .txt file and pasting the following onto each line. The m1config.txt file is in the format:

  1. On the first line, the API Key
  2. On the second line, the MQTT Project ID
    • The MQTT Project ID can be found by clicking on Setup -> MQTT.
  3. On the third line, the MQTT Registration User ID
  4. On the last line, the Registration User Password
    • The Registration User Password was auto-generated so if you lose the email, you will need to reset that user’s password by going to Setup -> Manage Administrators and clicking ‘Edit’ under the ‘Actions’ column.

What if I accidentally delete my user?

If you accidentally delete your user, you can recreate it by auto-enrolling the user again. It will re-create the user automatically although you will lose all the previous data generated.

What if I accidentally delete the registration user?

If you accidentally delete the registered user, you will need to re-create it again if you want to add a new board to your project. To do this, go to Setup -> Manage Administrators. Here, you can click ‘Add New User’ and specify the registration user’s username and password. Only the MQTT ID and password from this user are needed. Repeat step 3 with these new credentials to auto-enroll a new board.

How do I manually provision my kit instead of auto-enrollment?

To manually provision your kit, complete Step 3 in addition to these next steps. When connecting the kit to your Windows PC, it should show up as a USB. Click on the USB folder and create a new .txt file called ‘m1user.txt’. Open this text file. This text file will have a total of two lines:

Line 1 will be the User MQTT ID

Line 2 will be the User Password

See below on how to get these two values.

Sign onto the Medium One Prototyping Sandbox for Renesas Kits and click on Setup > Manage Users. Click on ‘Add new user’ and type in a username and password then click ‘Save’. The password that you specified to create this user will be Line 2 of ‘m1user.txt’.

Back on the Manage Users page, a new row should’ve shown up. Copy the text highlighted where the red box is. This is the User MQTT ID. This will be on Line 2 of ‘m1user.txt’.

Save the file and wait 2 seconds. Unplug the board and plug it back in. It should now connect. Be sure to select this user’s username in the widgets for the Dashboard.

 

APPENDIX D:

GPIO

Interrupt driven GPIO input will be transmitted to the cloud to enable external peripherals such as buttons to be easily connected to the MCU board GPIO output: The cloud can control a GPIO pin. On both grove connectors, pin 1 is an interrupt-input, and pin 2 is a controllable output.

#G = GPIO

#G<port>:<pin>:<level>

# for example:

MQTT.publish_event_to_client(‘s5d9’, ‘G4:11:1;G1:1:1’) # sets pin 4_11 high and pin 1_01 high

MQTT.publish_event_to_client(‘s5d9’, ‘G4:11:0;G1:1:0’) # sets pin 4_11 low and pin 1_01 low