This is a "host-free" project because the Notecard itself can be configured to monitor the motion of whatever it is connected to using its built-in accelerometer. It may sound simple, but this is a big deal. Typically, a host microcontroller is necessary to interface with sensors and
determine when data should be sent over the network to a cloud service. The fact that Notecard can do this without a host means big savings in terms of necessary hardware and power usage, as microcontrollers tend to be resource intensive.
This section will guide you through creating a reusable Notecard configuration script which can be executed through the Notecard CLI or through the online webREPL available on the Blues Developer Experience site.
There are two main ways to program a standalone Notecard that will not be controlled by a host microcontroller:
This executes each command on your connected Notecard, one at a time. When the setup completes, your Notecard's configuration is complete.
To confirm your Notecard is now attached to your project in Notehub, navigate to the project in the browser, click the Devices tab and see if your Notecard has appeared. Once the Notecard connects to Notehub, you'll see a device with the preferred name of your Notecard (provided by the setup script) under the Best ID column.
If you'd prefer to upload this script using the in-browser Notecard Playground instead of downloading the CLI, connect your Notecarrier to your computer via the USB-A to micro USB connector, pair it via serial port in your browser by clicking the USB Notecard button in the Notecard Playground, and copy/paste the whole config file. (Don't forget to add your product key in the script before copy/pasting.)
Let's take a look at each request in the configuration script for this app. First, an env.default request to set a pump_jack_configuration_version environment variable. This optional request allows you to version your configuration script through an environment variable that is synchronized and visible from the Notehub's Device Environment Variable UI.
Next is hub.set, and you'll want to edit this request to include your Product UID in a product key-value pair, and optionally set a serial number with the sn key and value. voutbound and vinbound are voltage-variable values that you can use to configure the sync behavior of the Notecard based on the state of its battery. voutbound corresponds to periodic syncs from the Notecard to Notehub, while vinbound corresponds to syncs from Notehub to Notecard.
The card.voltage request's mode key is used to set voltage thresholds based on how the Notecard will be powered, and which impacts the voltage-variable settings above.
Next, we'll configure the motion detection and tracking aspects of the app, starting with card.motion.mode. This request is used to set-up some of the motion monitoring parameters that will be used with card.motion.track below. "start":true turns on the accelerometer and tracking, sensitivity is used to tune the accelerometer sample rate, and seconds is used to specify the period to use for bucketing movements together for automated motion tracking. More on that in a minute.
Since we're not using a host, we need to configure the Notecard to automatically capture motion data with card.motion.track. "start":true starts automated motion tracking, which will send a motion Note in the default _motion.qo Notefile at least every 20 minutes ("minutes":20) and by examining the last 20 buckets ("count":20) of 60 seconds each (as set in card.motion.mode above). The threshold key sets the number of buckets that need to have at least one movement in order for a tracking note to be added.
The card.motion.sync request is used to automatically sync motion-triggered Notefiles on an interval specified with the minutes key. Here, we're setting the sync interval to once an hour and using "start":true to kick off automated syncs.
Since this application will be deployed on oil fields, we also want to use GPS/GNSS to send the location of the pump jack. But the pump jack is not a mobile asset, so we can use seconds with a high value of 86400 to send a heartbeat location once a day.
Finally, another env.default request, this time to set the Notehub-reserved _log name. Setting this variable will log network registration failures so that we can debug whether we have deployed devices in an area with spotty connectivity.
Once your Notecard has been configured, powered, deployed, and shows up online, you can view events in Notehub to confirm that everything has been set-up correctly. Using the script above, you can expect to see something like the following as events from the _motion.qo notefile.
motion corresponds to the total number of motion events captured in the configured period of 20 minutes.
movements is a string of base-36 characters, where each character represents the number of movements in each bucket during the sample duration. Each character will be a digit 0-9, A-Z to indicate a count of 10-35, or * to indicate a count greater than 35. Since we configured the bucket duration to be 60 seconds above, the example below shows the number of movements detected during each 60 second period.
Finally, orientation is the position of the Notecard at the time this Note was captured.
Additionally, because you set up your project for GPS/GNSS tracking, every 24 hours you'll see a _track.qo event that contains the pump's location in the payload.
This project features a Datacake dashboard to utilize event processing with the built-in payload decoder feature.
You'll first want to set-up a free account with Datacake, and then follow this guide to create a Notehub Route that sends your project's data to your Datacake dashboard.
Once created navigate to the Configuration tab of your Datacake project and paste the contents of the pumpjack-payload-decoder.js file into the HTTP Payload Decoder section, and then click the Save button. As data flows into Datacake from your Notehub project, you can construct a dashboard to show current
and historical information like in the screenshot below.