Medium One Mobile App Quick Start Guide

Getting Started Guide- Mobile App

This guide will get you started on the Medium One IoT Controller App.

 

You will need:

  • The IoT Controller App

 

Important information before you begin:

The mobile app can consume your Medium One credits.  It’s recommended to use it to send commands to Medium One’s cloud.

 

Each visualization widget refreshes every 2 second and will consume credits.

The GPS will transmit coordinates once every 5 seconds

The control widgets will only consume credits when you send an event

 

It is recommended to use the Dashboard for visualization and mobile for control if you have limited credits.

 

Step 1: Create a Medium One Sandbox Account

 

Visit mediumone.com and click “Sign Up” in the top right hand corner, which will take you to another page where you will enter your first and last name, email address, and project name.

1-before-step-2

 

Step 2: Create API user and API key

 

Log into Medium One web account.  Then go to Setup -> Manage Users

2-step-two-after-1-line3-right-after-2

Create an API user, you can use these credentials or your own.  It will need to match the following steps.  Note your username, password, you will need it.

4-you-will-need-it

 

Then click Manage API keys, and + Add New API Key, type any description and Save.

5-click-save

6-right-after-5

Note your API Key, you will need it..

 

Step 3: Let’s create sample data from curl to the cloud

 

This curl example is based on Mac OS linux.  Refer to docs.mediumone.com on Windows example.

 

TIP: Make sure you have write access in your directory, the curl command creates and saves a cookie file.

 

Open terminal and type the following (substitute your username, password and API key from previous step):

 

curl -c cookies.txt -X POST -k -H ‘Content-Type: application/json’ -H ‘Accept: application/json’ -i ‘https://api-sandbox.mediumone.com/v2/login’ -d ‘{“login_id”: “mobile“, “password”: “9243>73kA“, “api_key”: “ABXTEM2R5KCCNZDBXTFBIAJQGQ4DCNRRHA2GENJYGQ3TAMBQ“}’

 

If successful, it will return true at the command line.

 

Next, we are going to send an event.

curl -b cookies.txt -k -i -H “Content-Type: application/json” -H “Accept: application/json” -X POST “https://api-sandbox.mediumone.com/v2/events/raw/mobile” -d ‘{“event_data”:{“gps”:”37.354107 -121.955238″,”temperature”:110,”notification”:”Fire! Fire!”}}’

 

 

There are 3 events created, gps, temperature, and notification.

 

Step 4: Activate Tags in Medium One

 

Go back to Medium One’s web portal and click on Config => Data Streams

7-step-4-data-streams1

Click on “Edit” for raw datastream.

8-raw-datastream

Change gps Extended Type to “GeoPoint Time Series” and active all three tags as shown below.  Save.

9-save

Click in Dashboard  and add the “Single User – Real Time Event Log” widget to your view.

10-to-your-view

Select user “mobile” (or the name of the user you created)

11-you-created

Step 5: Create a New Profile on Mobile

In the Iot Controller app, create a new profile. Click the + in the top righthand corner, then click the new profile created and name it. You will need to create an API Key, Login, and Password (see Steps 2).

12-see-steps-3-and-4

You will create a “new” profile.

13-you-can-create-a-new-profile

Note: You can delete profiles by swiping right.

14-swiping-right

 

 

Open the “new” profile.  Click API login and enter your credentials from above.

15-data-from-above

Click Sandbox and Done.  Remember to click “Save” (only for iOS)

 

Step 6: Adding New Widgets

 

Click the +Add New Widget button on the top, and you will see a scrolling list of 8 Widgets you can enable.

16-can-enable

 

Add a slider widget, then click on the slider icon to configure it.  Enter raw for stream and temperature for tag

17-stream-and-temperature-for-tag

Now add the switch widget.  Enter raw for stream and switch for tag

18-raw-and-switch-for-tag

 

Your screen should look something like this

19-something-like-this

 

Go back to your dashboard and observe the real-time event chart as your toggle the switch and change the slider on the mobile phone.  You should see the events appear.  Congrats! you just sent events to Medium One’s cloud using your mobile device.

20-congrats

 

 

 

Additional notes on the different widgets

 

GPS: This widget will transmit geoPoints once every 5 seconds*

Gauge: This widget will query a stream/tag once every 2 seconds*

Notification: This widget will query a stream/tag once every 2 seconds for a text message*

Log: This widget will query a stream/tag once every 2 seconds for last 10 text message*

Map: This widget will query a stream/tag with type geoPoint to display location on the map*

JSON: This widget will transmit a JSON key value pair

 

* These widget consume a lot of credits and not recommended for Sandbox.

 

Appendix

How to send a push notification

If you allow push notifications on the mobile app, a FCM_token tag and key are created in the raw data stream when the profile is created.  Be sure to activate the FCM_token key.  If you don’t see it, you’ve probably disabled push notifications, or have not created a profile on the mobile app.

21-appendix-not-created-a-profile-on-the-mobile-app

 

 

Next create a workflow to send Push Notification.  Click on Workflow Studio and “Create”

22-and-create

Give your workflow a name like “Push Notification.”

23-like-push-notification

Click on “Tags and Triggers” on the right panel and expand the raw stream.  Drag “temperature” over to the center canvas.

24-over-to-the-center-canvas

Click on Modules on the right panel and under Foundation, drag “Base Python” to the center canvas as well.

25-to-the-center-canvas-as-well

Double click on Base Python.  Expand IONodes to expose “Add Input”, click here to add an addition input to this module.  Click Save.

26-click-save

You will now see two input nodes.  Under Tags and Triggers on the right panel, drag “FCM_token” to the main canvas.  Note, you need to activate the tag in order to see it and use it.

28-see-it-and-use-it

Drag FCM_token to the canvas and connect it to in2 of the module

29-in2-of-the-module

Now we are going to write a simple workflow script.  Double click on Python and add these lines.  It’s important that the temperature and FCM_token trigger are in the same order as described to match the code

 

Code snippet here:

import FCM

temperature = IONode.get_input(‘in1’)[‘event_data’][‘value’]

FCM_token = IONode.get_input(‘in2’)[‘event_data’][‘value’]

FCM.send_fcm_notification_to_m1_application([FCM_token],temperature, sound=”chime”)

 

Explanation:

import FCM  (This is the FCM module library)

 

These are the more recent values for the event triggers

temperature = IONode.get_input(‘in1’)[‘event_data’][‘value’]

FCM_token = IONode.get_input(‘in2’)[‘event_data’][‘value’]

 

This command sends a notification to the Medium One mobile app.

Note: FCM_token must be in an array.

FCM.send_fcm_notification_to_m1_application([FCM_token],temperature, sound=”chime”)

 

Click “Check Syntax” and “Save”.  If syntax fails, check your code again.

30-check-your-code-again

Now you need to activate the workflow. Click on “Revisions” on the right panel and activate the topmost (recent) version.

 

TIP: Medium One has revision control, so you can continue working on your workflow and only activate when ready.

 

When you activate the workflow, it’s instantly live.  In this case, when a temperature or FCM_token event is sent, it will trigger this workflow.

 

TIP: You may want to disable FCM_token as a trigger.  To do so, simple double click on it, and uncheck “trigger.”

31-uncheck-trigger

 

Note let’s trigger the workflow.  Go back to your terminal, send the last curl command once again.

 

curl -b cookies.txt -k -i -H “Content-Type: application/json” -H “Accept: application/json” -X POST “https://api-sandbox.mediumone.com/v2/events/raw/mobile” -d ‘{“event_data”:{“gps”:”37.354107 -121.955238″,”temperature”:110,”notification”:”Fire! Fire!”}}’

 

You should receive a push notification on your phone

32-push-notification-from-your-phone

Author: Rochelle Drenan