Successful “Real Time” Data Logging (Finally!) – A Step by Step Walk Through

Author: Tom DeBell

Update 10/3/18

The description of process of using PushingBox and the Google scripts was updated 10/3/18 (primarily with regards to the usage and interfacing with the Google Script). The most up to date and comprehensive tutorial is now maintained here.

Abstract

Connecting… Connecting… Transmission Received!

After months of prototyping, experimenting and redesigning we have successfully deployed our first, “fully open source” transmitter and receiver with near real time updates to a google spreadsheet.  This post will give a step by step procedure on how to set up all the software and web interfaces for this project.

Step One – Creating and Deploying your Google Sheet

A) Log in to your free Google account and create a new “Google Sheet,” this is the spreadsheet which will be populated by the sensor data received by the Ethernet Featherwing data logger. At this point, you will need to copy and save your spreadsheets URL key for use in your Arduino code. This key is listed in the URL between the “/d/ ” and the “/edit ” of your new spreadsheet (see red box).


IDID

B) Name your Spreadsheet something original like “Environmental Data,” now we must create our Google App Script (similar to JavaScript) which will process our data and populate our spreadsheet correctly. To insert our Google App Script we first navigate from our spreadsheet to the Script Editor, found under the Tools tab:

Tools →Script Editor

We will now be on the Google Script Editor page. Now we can name our Gscript something extra-creative like “My Environmental GScript”, but do not have to. Fortunately, we do not have much that we have to do on the Script editor page.

1) Copy and Paste the Google Script code into the Editor. (link to GitHub with all needed codes here)

2) Save the script: File→Save All

3) Deploy as a web App: Publish-→ Deploy as web App…

C)  Our final Step for setting up our Google sheet will involve configuring the Web deployment parameters. It is important you set all these fields correctly. If you don’t set all four fields exactly your spreadsheet won’t work properly (trust me…). This step takes place immedietly after clicking “Deploy as Web App”.


Field 1) Copy and Save the “Current web app URL:“ which has just been generated, we will need this later when we configure our API in PushingBox.

Field 2) Save a project version as “new” on each iteration, it’s important to note that if you don’t make a new project version for each script revision you make (if you decide to make any revisions), your script revisions won’t be updated on the web. This is counter-intuitive, and easy to neglect, but this is currently how Google has this system configured.

Field 3) “Execute the app as: “ set this to “me(your GMail here) ”.

Field 4) “Who has access to the app: “ set this to “anyone, even anonymous.” *This is important, and allows Pushingbox access the spreadsheet.* 


Step Two – PushingBox API

Pushingbox.com serves as simple, free, and easy Application Programming Interface (API) middleman in allowing our Evaporometer data to be palatable to Google Sheets. The need for using the PushingBox API intermediary is to turn our HTTP Ethernet transmitted data into Google compliant HTTPS encrypted data. Although other programmers have found workarounds to this system (found here) using PushingBox is easier, and we are given up to 1,000 requests (Data Transmissions) a day.

*1,000 push requests is more than enough for updates every 2 minutes in a 24-hour cycle but not enough for minute by minute updates (thus the “” around real time) but this service is completely free.*

Below are the steps for configuring Pushingbox to work with our data:

1. Create a PushingBox account using your Gmail.

2. At the top click on “My Services”

3. While now in “My Services” go to the “Add a service” box and click on “Add a service”.

4. The service you will want to create is the last item on the list of services and is called: ”CustomURL, Set your own service !”. Now select this CustomUrl service.

5. A box will open up and ask for three items. Fill them out as below, then hit submit

Name of your CustomURL configuration:

Root URL: This url will start with https://script.google.com… as this is your Google Script address saved from Part 1


6. After submitting your service you must now create a scenario for the service. To do this select “My Scenarios” at the top of the page.

7. Enter an appropriate name for your scenario in the “Create a scenario or add a device” box. After you name your service click the “add” button to the right.

8. Now it will ask to “Add an action for your scenario” You should now choose the “Add an action to this service” button listed next to the service name you created in the previous step. This assigns your new scenario to your new service.

9. A data box will open asking you for your “Get” or “Post” method (we use the Get method although this seems counter-intuitive). For recording all our Evaporometer data into your Google sheet you need to link your variable names listed in your Google App Script to the names listed in our Arduino sketch. Formatting the names correctly in the Pushingbox API will accomplish this linking task.

Copy and paste the following string into your box.

?key0=$key0

amp;val0=$val0

amp;key1=$key1

amp;val1=$val1

amp;key2=$key2

amp;val2=$val2

amp;key3=$key3

amp;val3=$val3

amp;key4=$key4

amp;val4=$val4

amp;key5=$key5

amp;val5=$val5

amp;key6=$key6

amp;val6=$val6

amp;key7=$key7

amp;val7=$val7

amp;key8=$key8

amp;val8=$val8

amp;key9=$key9

amp;val9=$val9

amp;key10=$key10

amp;val10=$val10

amp;key11=$key11

amp;val11=$val11

amp;key12=$key12

amp;val12=$val12

amp;key13=$key13

amp;val13=$val13

amp;key14=$key14

amp;val14=$val14

amp;key15=$key15

amp;val15=$val15$ 

Note: STATEMENT BEGINS WITH ” ” TO INDICATE “GET”

The result should look like as follows (roughly, as the data string shown in the image is slightly out of date, but the rest is correct), but with your own scenario name and Device ID number:


*Make sure to copy your “DeviceID” string that will be generated after setting up the service, you will need it for both preliminary testing in the next step, and later for the Arduino Sketch in Part 4.*

Step Three- Testing API and Google Spreadsheet

Before we move on to the last step, in which we program the Adafruit Feather 32u4 with LoRa Radio Module and complimentary Ethernet Feather Wing which will log data through the web, it would be helpful to test that everything we have done thus far is correct. If we wait to complete the hardware portion then the cause of any errors may be more difficult to track down. Fortunately, we have a simple method of testing our code so far. We can just directly enter some hard-coded pseudo-data into our web browsers address bar and check that our Google sheet is being updated correctly. Here is an example of what you might copy and paste into your browsers address bar.

http://api.pushingbox.com/pushingbox?devid=<<YOUR-PUSHINGBOX-DEVICEID>>&key0=sheetID&val0=<<SPREADSHEET-ID>>&key1=tabID&val1=<<SHEET/TAB-OF-SPREADSHEET>>&key2=deviceID&val2=<<NAME-GIVEN-TO-ARDUINO>>&key3=TimeStamp&val3=50&key4=TempC&val4=200&key5=Humid&val5=80&key6=LoadCell&val6=1000&key7=IRLight&val7=2000&key8=FullLight&val8=3000&key9=BatVolt&val9=4.2
 

If you like you can even re-enter new fake data with different values for subsequent rows, however, remember you only have a 1,000 requests per day from Pushingbox.com so don’t go crazy! If this procedure did not update your spreadsheet then go back and review Parts 1 -3 of this instructional for errors before attempting Part 4. Congratulations if you have made it this far, the worst is over! (it took me about a dozen times to get all the previous steps correct) Update – the modification of this process and the Google Script since the initial writing of this blog post were primarily to simplify these steps


Step Four – Hardware Set-up and Arduino Sketches

After confirming you were able to push some hard-coded pseudo-data directly from your browser onto your Google Sheet you are now ready for the next step which involves sending data directly from the Feather 32u4 and complimentary Ethernet Feather Wing to Google via Pushingbox over an Ethernet connection. Before you can upload and run the included Arduino sketch to the Feather Board you must complete the following three steps.

Hardware

1. Wiring the Feather 32u4 board to the Ethernet FeatherWing:  a guide on how to do this can be found on the adafruit website here, as well as one of my previous posts, found here.

Software(1):

2. There are a few steps to set up your Arduino IDE to work with your Feather 32u4 board.. These steps include downloading the necessary libraries and configuring the Arduino IDE (1.6.4 or later) with the correct Feather Board package. Many of you will have already installed all the software you need, for those that have not, below are links to retrieve the needed libraries and the Feather 32u4 board support package.

The two required libraries for our particular sketch:

Two great tutorials to walk you through getting the correct Feather 32u4 board and Ethernet FeatherWing package installed into the Arduino IDE if you haven’t done this already:

Software(2):

3. You are now ready for the final step of the project, you need to copy and paste the included Arduino sketch, customize it for your device, and then upload the sketch onto your Feather 32u4 board and Ethernet FeatherWing. Update – that sketch is now out of date, refer to the Loom Library instead for the corresponding updated code and process.

A) Your MAC Address (Found in Ethernet packaging)

B) Your Static IP address (May need to be given by IT admins)

C) Your Pushing box Device ID (devid)

That’s it, you’re done! If everything was completed correctly your output will look something like the picture below:


Populated Google Spreadsheet (left) and Ardiuno IDE with example code.Populated Google Spreadsheet (left) and Ardiuno IDE with example code.

Populated Google Spreadsheet (left) and Ardiuno IDE with example code.


Final Receiver and Ethernet data logger set-up.Final Receiver and Ethernet data logger set-up.

Final Receiver and Ethernet data logger set-up.

– Tom DeBell, Beginning Researcher Support Program Researcher

More Testing with the nRF08001 Bluetooth LE

Note: The nRF8001 sends out packets of data, 20 bytes at time. Keep this in mind if you want to send a lot of data it will be packetized into chunks of 20. You can of course send less than 20 bytes.

Exploring Mobile Interface

After initial setup and software tests, I was able to explore the Adafruit developer smart phone application found in the android market, “BlueFruit LE”. (APK file linked here

Much like Serial you can use the .write and .print functions allow us to send data out to the connected device:

Features included in Bluefruit LE App

 


Home screen of the "Bluefruit LE" smartphone applicationHome screen of the "Bluefruit LE" smartphone application

Home screen of the “Bluefruit LE” smartphone application


Display after connection with Bluetooth moduleDisplay after connection with Bluetooth module

Display after connection with Bluetooth module

Info

Displays MAC address and other relevant Device Information


Screenshot_20170412-101741.pngScreenshot_20170412-101741.png

 

UART


Screenshot showing a message being transmitted to the Arduino from my smartphone&nbsp;Screenshot showing a message being transmitted to the Arduino from my smartphone&nbsp;

Screenshot showing a message being transmitted to the Arduino from my smartphone 

The “UART” function allows a basic text message interface from smartphone to the Arduino Series monitor. However, after testing it was apparent that although the application allows infinite characters of transmission, the messages are broken apart into 20 character fragments due to the data transmitting capabilities of the bluetooth chip.


Snip showing successful reception of the message from my smartphone to the Arduino seriel monitorSnip showing successful reception of the message from my smartphone to the Arduino seriel monitor

Snip showing successful reception of the message from my smartphone to the Arduino seriel monitor

 

 

Pin I/O

The Pin I/O section of the mobile phone application allows the user to control input and output of pins (both analog and digital) on Arduino shield. However, this particular function required significant code modification in order to allow functionality on Android enabled devices. Once the code is finalized it will be published and linked here. In order to display this faciniating functionality a small demo was contructed in order to deminstate the smart phone interfaces capabilities. 


With just a slide of my finger I am able to modify the signal strength being admitted from the Arduino&nbsp;With just a slide of my finger I am able to modify the signal strength being admitted from the Arduino&nbsp;

With just a slide of my finger I am able to modify the signal strength being admitted from the Arduino 


The Blue LED is only lightly illuminated due to low PWM signal as specified by the photo on the left&nbsp;The Blue LED is only lightly illuminated due to low PWM signal as specified by the photo on the left&nbsp;

The Blue LED is only lightly illuminated due to low PWM signal as specified by the photo on the left 


The PWM slider was moved all the way to right to allow for maximum signal strengthThe PWM slider was moved all the way to right to allow for maximum signal strength

The PWM slider was moved all the way to right to allow for maximum signal strength


The increased signal strength as shown on the left caused the LED to shine brightlyThe increased signal strength as shown on the left caused the LED to shine brightly

The increased signal strength as shown on the left caused the LED to shine brightly

This section of the Bluefruit LE application appears to be very useful, unstable and will require further explanation.

Controller

Streams sensor data from smart phone sensors (Quaternion (6-axis accelerometer), Accelerometer, Gyro, Magnetometer, Location)

Beacon

Puts smartphone in a state to receive pop-up text messages from serial monitor up to 20 characters  


Snip from the Arduino Serial Monitor during transmission testingSnip from the Arduino Serial Monitor during transmission testing

Snip from the Arduino Serial Monitor during transmission testing


Screenshot of the recived message from the Ardiuno&nbsp;Screenshot of the recived message from the Ardiuno&nbsp;

Screenshot of the recived message from the Ardiuno 


&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Messages are restricted to only 20 characters&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Messages are restricted to only 20 characters&nbsp;

          Messages are restricted to only 20 characters 

Neopixel

Needs further exploration.

 

Conclusions

**Initial testing of connectivity shows an approximate range of 20 feet for reliable signal strength.**

After initial testing it would appear that  the Pin I/O will have the most practical capabilities and research of its functionality will continue. 

 

– Tom DeBell, Beginning Researcher Support Program researcher

Getting Started with the nRF08001 Bluetooth LE chip

 

Initial setup for this project began early this week starting with soldering header pins onto the nRF08001 Bluetooth LE (Low Energy) breakout board so that a physical connection could be made with an Arduino Uno module to begin testing. A valuable resource that helped getting started can be found at adafruit.

The wiring of the Bluetooth board to the arduino was done as follows. 

Wiring Schematic


Wiring Schematic via Adafruit&nbsp;Wiring Schematic via Adafruit&nbsp;

Wiring Schematic via Adafruit 


Wiring completed on April 5th to begin testingWiring completed on April 5th to begin testing

Wiring completed on April 5th to begin testing

  • VIN connects to the Arduino 5V pin (Red Wire)
  • GND connects to Arduino ground (Black Wire)
  • SCK connects to SPI clock.  (Blue Wire)
    On Arduino Uno/Duemilanove/328-based, thats Digital 13
    On Mega’s, its Digital 52 and on
    Leonardo/Micro its ICSP-3 (See SPI Connections for more details)
  • MISO connects to SPI MISO. (Yellow Wire)
    On Arduino Uno/Duemilanove/328-based, thats Digital 12
    On Mega’s, its Digital 50 and on
    Leonardo/Micro its ICSP-1 (See SPI Connections for more details)
  • MOSI connects to SPI MOSI. (Teal Wire)
    On Arduino Uno/Duemilanove/328-based, thats Digital 11
    On Mega’s, its Digital 51 and on
    Leonardo/Micro its ICSP-4 (See SPI Connections for more details)
  • REQ connects to our SPI Chip Select pin. We’ll be using Digital 10 but you can later change this to any pin. (Grey Wire)
  • RST connects to Digital 9 – this is for resetting the board when we start up, you can later change this to any pin. (Orange Wire)
  • RDY is the interrupt out from the nRF8001, we’ll connect to Digital 2 but be aware that if you want to change it, it must connect to an interrupt capable pin (see this Arduino page for which pins are interrupt-capable. Digital 2 is OK on Uno/Leonardo/Micro/Mega/etc.) (White Wire)
  • Note: Wire colors refer to first wiring diegram

Initial Testing

After wiring was completed testing of bluetooth transmissions and functionality began with positive initial results. By running a sample arduino code found on GitHub we were able to communicate to the arduino via the “Bluefruit LE” android application and likewise was able to transmit data from the command line of the arduino workspace directly to a smart phone via the bluetooth module.  Further Testing will contiuno next week.


Snip from the Arduino Serial Monitor during testingSnip from the Arduino Serial Monitor during testing

Snip from the Arduino Serial Monitor during testing

– Tom DeBell, Beginning Researcher Support Program researcher