LoRa is great when there’s a network available, but for in-person water quality readings I thought it’d be convenient to add Bluetooth.

I had a spare BLE Nano v2 sitting around, so decided to wire that in. It acts as a relay, broadcasting everything that the Water Quality sensor outputs over serial, and pushing it out via Bluetooth.

Because this is the same setup as my air quality sensor project, I could clone the Air Quality iOS app to become a Water Quality iOS app. The app saves all of the data to my iPhone/iPad’s Core Database, and there’s an export to CSV function too.

It’s pretty snug on the mini breadboard, and I cheated a bit by adding in the 3.3v BLE board on the wrong side of the power isolator to avoid having to drop down the 5v TX pin from the Arduino side to 3.3v, but it all still fits in the waterproof enclosure and functions very nicely.

The Bluetooth BLE board is the red one on the right.

Next step is to update my Rails site to be able to include water quality data, add some API authentication, and host it. Then all of the data the iOS apps are getting will be posted to a database and graphed nicely, both on a linear graph, and on a map.

I’d tried five different locations across two states, so was getting pretty paranoid that it was either something I’d done in my Arduino water quality sensor reading code (I was using Software Serial).

So I asked Leo from TTN Adelaide if it might be possible for him to send me a known working Uno so that I could try it here using stock software. His setup was identical to the one I had been trying, but at least we could rule out hardware failure, and it’d tell me a lot more about trusting my code.

As soon as it arrived I plugged it into my USB power brick so that my laptop couldn’t do anything weird to it (super paranoid), but it didn’t connect successfully. So after a couple of minutes I plugged it into my laptop so I could read the serial monitor output. Same output as mine.

So at this point I could at least feel a little better about my code and hardware, but it was still a bit of a mystery why all of the locations I’d tried didn’t work.

I wandered around the Melbourne CBD with it switched on, monitoring TTN console on my phone for uploads… still nothing.

In a last ditch effort to find some signal, I got myself onto a 38th floor rooftop, switched it on, and almost instantly the join confirmation and payloads started streaming in.

So it was just blackspots all over the Melbourne CBD, East St Kilda, Southbank, Adelaide CBD and Port Willunga.

Test the payload

Next thing to do was to test the payload to see if I was sending a readable byte array.

It turns out that it wasn’t only the range that might have been causing my connection problems to The Things Network – Andrew Sargent from OpenSensing spotted that in my logs the LoRaWAN RN2903 chip was reporting a firmware version 0.9.5 whereas the version needed to connect is 1.0.3

I’m on macOS, so ideally wanted to use my mac to upgrade the firmware. Here are the steps that I followed:

Unfortunately clicking the ‘Select File:’ button causes a Java exception on the mac:

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
...
Caused by: java.lang.IllegalArgumentException: Folder parameter must be a valid folder
at com.sun.glass.ui.CommonDialogs.convertFolder(CommonDialogs.java:238)
at com.sun.glass.ui.CommonDialogs.showFileChooser(CommonDialogs.java:190)
at com.sun.javafx.tk.quantum.QuantumToolkit.showFileChooser(QuantumToolkit.java:1496)
at javafx.stage.FileChooser.showDialog(FileChooser.java:416)
at javafx.stage.FileChooser.showOpenDialog(FileChooser.java:350)
at fed.FEDFXMLController.onFileBrowse(FEDFXMLController.java:7049)
... 83 more

Add a ‘String’ entry for FilePath with the value /Users/<your username>/ under fed/ and dfu/

Save and close.

Adding default FilePath values for Java on macOS

Now you should be able to run the Microchip utility and select the firmware to upload: $ /Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home/bin/java -jar LoRaDevUtility.jar

Don’t do what I did and select the unzipped folder, instead copy the file RN2903_Parser.production.unified.hex to the Desktop and select it from there.

If you did try and flash the folder and it failed and won’t connect anymore, fear not – you can select Module > Boot Load Recover. And select the other hex file: RN2903_Parser.production.hex to recover. 😊

Finding a spare breadboard, I wired the EZO board to the voltage isolator (which is optional so that any other devices don’t interfere with the conductivity sensor), and then to an Arduino Mega. I thought it better to test it with a plain Arduino before migrating over to The Things Uno, as I haven’t looked into whether the standard serial pins are still usable or not.

Atlas Scientific Conductivity K 1.0 connected to an EZO board, via a power isolation board, to an Arduino Mega.

With everything connected I uploaded the sample code to the Arduino, opened the serial monitor and out came my first data!

EC:0.00
TDS:
SAL:
GRAV:

Noticing that the TDS (total dissolved solids), SAL (salinity) and GRAV (specific gravity) values were all blank, I followed the guide a little longer to see that they’re all off by default. Setting these to return values is as simple as sending the following commands via the Arduino IDE serial monitor:

I really love the setup process of The Things Network – straight forward guide, and sample code that all works perfectly. 😊

Update: Once I reached Adelaide CBD I plugged in The Things Uno again in the hope it would connect to the many close gateways… but unfortunately I had the same problem.

A quick chat in the #Adelaide channel on thethingsnetwork.slack.com and Andrew noticed that my Uno’s LoRaWAN firmware on the Microchip RN2903 is running old firmware (Version 0.9.5), and apparently it needs to be running Version 1.0.3 to connect.

Six months ago I moved to Williamstown Beach just outside of Melbourne. It’s a nice beachside town about 15km from the centre of the city. The beach is a couple of blocks away via a walk through the botanic gardens – a pretty ideal place to replenish after long days in front of computers (my day jobs include being a software developer for ACMI and New Internationalist).

The beach here has a really diverse crowd – many countries of Africa are represented, as well as a large portion of southern Europe and Asia. It’s a really popular place for both families with young kids and pets, as well as groups of teenage and 20-something friends.

But there is one blot on this otherwise idyllic bay, and that’s a big waste water drain that exits right next to the swimming beach. A waste water drain wouldn’t be so much of a big deal on its own, but Williamstown’s proximity to a large shipping port, industrial area, and oil refinery made me curious to see whether the output of it is at all tainted.

That curiosity peaked after a recent factory fire and subsequent rains forced the local council to put up signs warning that the water was unfit to swim in or even for pets to play in.

EPA Victoria has a twitter account that tweets water quality for beaches, but it doesn’t seem to have an entry for Williamstown and some of the alerts are based on historical data.

So I decided to start building my own monitoring system, to see what the cost would be to setup alerts of my own.

My first stop was the Public Lab Water Quality Sensor project. Being five years old there are a lot of broken links, but there was one that was useful – the link to Atlas Scientific sensors.

$400 is about double my comfortable limit for hobby projects, so I put the feelers out on the Hackerspace Adelaide list & Twitter to see if anyone wanted to share the cost and the sensors.

I’m wanting to do some basic water quality analysis of the tap water and beach water around Australia. This Arduino/Raspberry Pi compatible water conductivity kit is ~AUD$415 delivered. Is anyone keen to chip in to share use? Data would be public. https://t.co/YpQRTwW1Tg

Almost instantly, Jeannine very kindly put me onto Leo and The Things Network, who not only got TTN to donate me a The Things Uno with LoRaWAN (Low power, wide area network with ~15km range), but also agreed to sponsor me $100 towards the costs of the sensors (THANK YOU!).

The TPS would probably work nicely (The Bluelab is seemingly a standalone reader).

But seeing I wanted to open this up as public data, and have the possibility of an easily replicated solution, I decided to go with off-the-shelf products that have great documentation, Arduino sample code, wiring diagram and calibration samples (seriously, how nice is their documentation!!!).

The great unboxing.

Atlas Scientific and Leo from The Things Network were super prompt with their deliveries, they were each really nicely packaged and arrived within a week – a nice start to any project.