element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Just Encase
  • Challenges & Projects
  • Design Challenges
  • Just Encase
  • More
  • Cancel
Just Encase
Blog Blog 10 - Part 2 - Software the things - draft
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Just Encase to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: christophesky
  • Date Created: 23 Feb 2022 1:34 PM Date Created
  • Views 739 views
  • Likes 8 likes
  • Comments 0 comments
  • Hammond Manufacturing Enclosures
  • garden pond monitor
  • MKR1300
  • set up
  • just_encase
Related
Recommended

Blog 10 - Part 2 - Software the things - draft

christophesky
christophesky
23 Feb 2022
Blog 10 - Part 2 - Software the things - draft

Blog Content

In this blog entry I will run through the software set up I have used on th instation end of my Just Encase design challenge for remote monitoring of my garden pond, I have split this into two main sections Hardware and Software setup.

Hardware Setup

This is a short and simple one :) I have used the MKR1300 and a single Raspberry Pi (I have used a Model 4b) that was looking for a purpose.

The MKR1300 is connected directly to the raspberry pi using a serial connection on USB. You do not need to seperately power the MKR1300 as it can draw enough from the USB connection (just make sure you are using a good power supply, I am using the USB-C 3A official supply, they do what is needed, are inexpensive and look the part. Function, then form Slight smile

Software Setup

Ubuntu (OS used)

Ubuntu is my day to day OS, we just clicked and its stuck with me. Accordingly my instructions on how to replicate the build are geared towards this.

So many ways to go here, least friction route is to make use of the pi image burner for SD cards, you can find it here: https://www.raspberrypi.com/software/

Next grab yourself a stable Ubuntu image, I went with 20.04, burn your image, connect your pi up and away we go!


Decision Point - Pick One.

  • Do you want a time series database to store your data and then use Grafana to create your dashboards? if Yes --> InfluxDB (Time series database) to use with Grafana if for you.
  • Do you want a time series database to store your data and then use the inbuild UI and dashboard of that database instead of Grafana if Yes --> InfluxDB (Time series database) verion 2 is for you.

I originally started out with Invflux 1.8 and Grafana which i have documented below.

I subsequently forgot about WHY I went with 1.8 and upgraded in place to 2+ (first mistake) and then failed to validate my backup (second mistake).

If I had not forgotten about the conscious design choice, which I had documented, just not read again, I would have stuck with my original apporach. For completeness, I am updating with the you went with the second option. ONLY PICK ONE!! Slight smile

Finally - design choice. InfluxDB changed the query language between 1 -> 2. Currently the new query language is only supported in Beta for grafana, consequently I broke my dashboard.


InfluxDB (Time series database) to use with Grafana

First step is to add the APT key used to authenticate packages for Influxdb and then add the the influxdb repo:

wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add -
source /etc/os-release
echo "deb https://repos.influxdata.com/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/influxdb.list

Update APT and then straight to install influxdb:

sudo apt update 

sudo apt install -y influxdb

Influxdb is now installed, but not yet running. To make sure Influxdb starts up even if the Raspberry Pi is restarted, we need to enable and start the Influx Systemctl service.

//unmask the service so it can run

sudo systemctl unmask influxdb.service

//start influxdb

sudo systemctl start influxdb

//enable the service to start influx on boot

sudo systemctl enable influxdb.service

 and thats it - you now have Influxdb up and running :)

Configuring

Now you have some INfluxDB installed, time to create your first database

//From your terminal

influx

// will 

create database pond

//you then need to select your database

use pond

//as we are going to be connecting to grafana lets add it as a user and set a password

create user grafana with password 'your password here' with all privileges

grant all privileges on pond to grafana

//make sure you have added the user

show users

user admin
---- -----
grafana true

// have a looksey at your new database

show database

name
----
_internal
pond

Remember your credentials for the next step :) (p.s. I kept a single user grafana for the node red and grafana piece, you might want to add seperate users? probably a good idea)

next:

InfluxDB (Time series database) and inbuild Dashboard

Backup all the things (if you have saved data like me)

Then install the the ARM64 Ubuntu flavour of the release as such:

wget -qO- https://repos.influxdata.com/influxdb.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/influxdb.gpg > /dev/null
export DISTRIB_ID=$(lsb_release -si); export DISTRIB_CODENAME=$(lsb_release -sc)
echo "deb [signed-by=/etc/apt/trusted.gpg.d/influxdb.gpg] https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list > /dev/null

sudo apt-get update && sudo apt-get install influxdb2

sudo influxd upgrade

ubuntu@ubuntu:~$ sudo influxd upgrade
{"level":"info","ts":1645701944.5967607,"caller":"upgrade/upgrade.go:402","msg":"Starting InfluxDB 1.x upgrade"}
{"level":"info","ts":1645701944.597043,"caller":"upgrade/upgrade.go:405","msg":"Upgrading config file","file":"/etc/influxdb/influxdb.conf"}
{"level":"info","ts":1645701944.597638,"caller":"upgrade/upgrade.go:409","msg":"Config file upgraded.","1.x config":"/etc/influxdb/influxdb.conf","2.x config":"/root/.influxdbv2/config.toml"}
{"level":"info","ts":1645701944.597724,"caller":"upgrade/upgrade.go:419","msg":"Upgrade source paths","meta":"/var/lib/influxdb/meta","data":"/var/lib/influxdb/data"}
{"level":"info","ts":1645701944.59778,"caller":"upgrade/upgrade.go:420","msg":"Upgrade target paths","bolt":"/root/.influxdbv2/influxd.bolt","engine":"/root/.influxdbv2/engine"}
{"level":"info","ts":1645701944.6292257,"caller":"bolt/bbolt.go:83","msg":"Resources opened","service":"bolt","path":"/root/.influxdbv2/influxd.bolt"}
{"level":"info","ts":1645701944.6325235,"caller":"migration/migration.go:175","msg":"Bringing up metadata migrations","service":"migrations","migration_count":18}
> Welcome to InfluxDB 2.0!
? Please type your primary username admin
? Please type your password *********
? Please type your password again *********
? Please type your primary organization name e14-ham
? Please type your primary bucket name pond_monitoring
? Please type your retention period in hours, or 0 for infinite 0
? Setup with these parameters?
  Username:          admin
  Organization:      e14-ham
  Bucket:            pond_monitoring
  Retention Period:  infinite
 Yes
{"level":"info","ts":1645701969.4598284,"caller":"upgrade/setup.go:73","msg":"CLI config has been stored.","path":"/root/.influxdbv2/configs"}
{"level":"info","ts":1645701969.460073,"caller":"upgrade/database.go:202","msg":"Checking available disk space"}
{"level":"info","ts":1645701969.4712574,"caller":"upgrade/database.go:223","msg":"Computed disk space","free":"23 GB","required":"93 MB"}
? Proceeding will copy all V1 data to "/root/.influxdbv2"
  Space available: 23 GB
  Space required:  93 MB
 Yes
{"level":"info","ts":1645701974.9004018,"caller":"upgrade/database.go:51","msg":"Upgrading databases"}
{"level":"info","ts":1645701975.3185875,"caller":"upgrade/database.go:195","msg":"Database upgrade complete","upgraded_count":1}
{"level":"info","ts":1645701975.3188024,"caller":"upgrade/security.go:45","msg":"Upgrading 1.x users"}
{"level":"warn","ts":1645701975.3189058,"caller":"upgrade/security.go:50","msg":"User is admin and will not be upgraded","username":"admin"}
{"level":"info","ts":1645701975.319021,"caller":"upgrade/security.go:115","msg":"User upgrade complete","upgraded_count":0}
{"level":"info","ts":1645701975.3191135,"caller":"upgrade/upgrade.go:489","msg":"Upgrade successfully completed. Start the influxd service now, then log in","login_url":"http://localhost:8086"}

sudo systemctl start influxdb

//then: <youripaddress>:8086

image

Node Red (Flow development tool)

Node Red is a favourite of mine, it provides you with a very simple and intuitive UI for building logical flows, give it some inputs, some processes or functions and you get your outputs.

Installing:

Node red has a few dependancies and if you spend any time on trying to install from apt ... you are going to be in for a bad time. I did not know this and so share in the hope of saving someone else some time down the track.

So instead to get yourself up and running have a look at this: https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered

This is a bash script to install and setup node red on your Pi, but before you go and bash curl, have a look so you can see what you are running, where it comes from and not take the word of a stranger on the internet Slight smile

OK, welcome back, hopefully you are now happy and see what you are going to be running on your raspberry pi.

bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)

Is one way you could do it, or just pull a copy of the file locally and run this way instead.

Give it a few minutes and you should now have a nice clean install with all dependancies installed and ready for you to go.

At this point node red is not yet running. You can either start / stop manually, or you can take advantage of automatically starting it as a service. (I went with the latter).

//To manually start 

node-red-start

//To manually stop

node-red-stop

//restart

node-red-restart

OR


//To start as a servive and come back up after a reboot / restart:

sudo systemctl enable nodered.service

Configuring your flow:

In the context of my submission, looking at the flow below (left to right)

  1. LoRA Reciever Bridge to Pi is my input. This uses a serial connetion to the Pi:  /dev/ttyACM0 and reads in the recieved LoRA message.
  2. CSV: defines the list of comma seperated values that come in on the LoRA message
  3. Split: defines how the message is split, in this case  Split msg.payload, which gives you a payload topic + value (or Key and value)
  4. Switch: Takes the data and for each topic and value, routes this to the correct write instruction to InfluxDB.

image

You will also see Debugging recieved packets and msg.payload nodes have been used. So i find it really helpful to see what is actually coming in / out as I was putting the flow together. When you toggle the debugging (green square, rightmost on the two nodes), you will see the outputs in the debugging pane of your nodered window.

image

This shows the config for serial connection, to find your own device name (for your Arduinio) open up a console and:

ls /dev/tty*

You should then see /dev/ttyACM0 or if you have more than one USB device attached /dev/ttyACM#, where # might be 1 or another number Slight smile

image

I kept my implementation and use of the LoRa message simple, in fact as simple as could be. I do not serialise, deserialise, I have not elected to encrypt the data (as the MKR1300 has the abillity to do this).

My mesage contains a simple string comprising of comma seperated values, specifically "temp,pressure,humidity,tds,ph,ehumid,etemp,light,temp1,temp2,turbid,LUX,RSSI"

  • temp, from the BME280
  • pressure, from the BME280
  • humidity, from the BME280
  • tds, total disolved solids sensor measurement
  • ph, pH sensor measurement
  • ehumid, DHT22 measurement of enclosure humidity
  • etemp, DHT22 measurement of enclosure temp
  • light, grove light level sensor for the enclosure
  • temp1, - 10cm water depth temp probe
  • temp2, - 30-40cm water depth temp probe
  • turbid, turbidity sensor measurement
  • LUX, ambient light level sensor measurement
  • RSSI - the instation Recieved Signal Strength Indication

Each value name is a topic, which as the string comes in based on the position in the string you know you have values in that order

image

Keeping it simple, topics and values

image

and then connecting using the switch for each topic (or sensor specific measurement), where to write them, as shown below in the final node.

image

and thats it. Nothing more complicated Slight smile I hope this is helpful for someone.

Grafana (Dashboards)

Installing:

Now that you’ve got the Raspberry Pi up and running, the next step is to install Grafana.

First step is to add the APT key used to authenticate packages for Grafana

wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add - 

Next you add the  the Grafana repository:

echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list

Update APT and then straight to install Grafana:

sudo apt-get update

sudo apt-get install -y grafana 

Grafana is now installed, but not yet running. To make sure Grafana starts up even if the Raspberry Pi is restarted, we need to enable and start the Grafana Systemctl service.

//Frist you need enable the Grafana server

sudo /bin/systemctl enable grafana-server

//Then you can start the server

sudo /bin/systemctl start grafana-server

//If you need to restart after any changes

sudo /bin/systemctl restart grafana-server

ALMOST There :)

take your pi address and stick:3000 (the Grafana port number on the end) into your browser and you should arrive and the login page.

Last step - default user / password ... admin/admin, you will need to change these on first log in, make them good and secure :)

Setting up your own dashboard:

image

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube