Aquarium Monitoring with AWS-Seeed-Soracom
Things used in this project
Hardware components
3.7V Lipo battery | × 1 | |
SORACOM Air Global IoT SIM | × 1 | |
Wio LTE US Version - 4G, Cat.1, GNSS, JavaScript(Espruino) Compatible | × 1 | |
Antenna, Cellular / LTE | × 2 | |
Grove - Ultrasonic Ranger | × 1 | |
Grove - 3-Axis Digital Accelerometer ±16g Ultra-low Power (BMA400) | × 1 | |
Grove - Temperature, Humidity, Pressure and Gas Sensor (BME680) | × 1 | |
USB-A to Micro-USB Cable | × 1 |
Software apps and online services
Python 2.7 | × 1 | |
AWS IoT | × 1 | |
AWS IAM | × 1 | |
SORACOM Beam - Data Transfer Support | × 1 | |
Arduino IDE | × 1 | |
Jupyter Notebook | × 1 |
Hand tools and fabrication machines
Aquarium | × 1 | |
Aquarium Air Pump | × 1 |
Story
1. Introduction
An aquarium is a vivarium of any size having at least one transparent side in which aquatic plants or animals are kept and displayed. Fishkeepers use aquaria to keep fish, invertebrates, amphibians, aquatic reptiles such as turtles, and aquatic plants. The term "aquarium", coined by English naturalist Philip Henry Gosse, combines the Latin root aqua, meaning water, with the suffix -arium, meaning "a place for relating to". The aquarium was launched in early Victorian England by Gosse, who created and stocked the first public aquarium at the London Zoo in 1853, and published the first manual, The Aquarium: An Unveiling of the Wonders of the Deep Sea in 1854. An aquarium is a water-filled tank in which fish swim about. Small aquariums are kept in the home by hobbyists. There are larger public aquariums in many cities. This kind of aquarium is a building with fish and other aquatic animals in large tanks. A large aquarium may have otters, turtles, dolphins, and other sea animals.
This project I will carry out in a turtle aquarium of 75x45x35 cm.
Goals:2. Cost
With cellular connectivity, there is a cost associated with the data usage. This submission considered on cost effectiveness and also ability to scale production to 1000s of devices. We are going to associate with the exporter or wholesaler of the commercial aquarium service in our country. In this way we will ensure that our product reaches the consumer. Ornamental fish market linkage exists between buyers and sellers as well as domestic and international market. Wholesaler usually sells the fishes to local retailers and in turn, retailers directly sales to local customers, hobbyists etc. In this direction, in order to develop market for aquarium business service, there is need to studying consumer preference and existing marketing strategies, adopted by aquarists.
3. Hardware
What is Seeed? Seeed is the IoT hardware enabler, offering numerous hardware platforms and sensor modules, as well as customization and manufacturing services based on Shenzhen's extensive and flexible supply chain. Seeed is based in Shenzhen, China with branch offices in the US and Japan.We are going to use the Wio LTE Cat 1 board, and the configuration of our project is the following:As we can see in the figure, we have to connect the humidity sensor DHT11 on the D20 pin, the ultrasound sensor on the D38 pin, and the ADXL345 accelerometer on the 12C pin. And don't forget, connect the battery, LTE antenna to Wio LTE and plug your SIM card to it.
How does it work?4. Software
Examples used:
In the following figure we see how the device manager has detected the virtual port of our Wio LTE board.
When our board is configured in DFT mode, then it is no longer detected.
The used libraries and their download links are shown in the first lines of our code:
#include <WioLTEforArduino.h> // DHT 11 & SRF04 & ADXL345 sensors https://github.com/SeeedDocument/Wio_LTE#include "DHT.h" // DHT 11 sensor https://github.com/Seeed-Studio/Grove_Temperature_And_Humidity_Sensor/#include <Ultrasonic.h> // SRF04 sensor https://github.com/Seeed-Studio/Grove_Ultrasonic_Ranger#include <ADXL345.h> // ADXL345 sensor https://github.com/Seeed-Studio/Accelerometer_ADXL345#include <WioLTEClient.h> // MQTT#include <PubSubClient.h> // MQTT https://github.com/SeeedJP/pubsubclient#include <stdio.h> // MQTTThe important configuration to connect to the Soracom server is shown below:
#define APN "soracom.io" // MQTT#define USERNAME "sora" // MQTT#define PASSWORD "sora" // MQTT#define MQTT_SERVER_HOST "beam.soracom.io" // MQTT#define MQTT_SERVER_PORT (1883) // MQTT#define ID "WioLTE" // MQTT#define OUT_TOPIC "outTopic" // MQTT#define IN_TOPIC "inTopic" // MQTTThe calculations of our sensors (DHT11, ADXL345 and SRF04) are shown in the following lines:
// VARIABLES float h = dht.readHumidity(); // DHT 11 sensor float t = dht.readTemperature(); // DHT 11 sensor long distance; // SRF04 sensor int x; // ADXL345 sensor int y; // ADXL345 sensor int z; // ADXL345 sensor char envDataBuf[100]; //local data buffer // MQTT // SRF04 SENSOR VALUES distance = UltrasonicRanger.MeasureInCentimeters(); // SRF04 sensor SerialUSB.print("Distance: "); // SRF04 sensor SerialUSB.print(distance); // SRF04 sensor SerialUSB.println("[cm]"); // SRF04 sensor // ADXL345 SENSOR VALUES Accel.readXYZ(&x, &y, &z); // ADXL345 sensor SerialUSB.print("Acceleration [x,y,z]: "); // SRF04 sensor SerialUSB.print(x); // ADXL345 sensor SerialUSB.print(' '); // ADXL345 sensor SerialUSB.print(y); // ADXL345 sensor SerialUSB.print(' '); // ADXL345 sensor SerialUSB.println(z); // ADXL345 sensorThe data to be saved on the AWS server and in JSON format are shown below:
sprintf(envDataBuf, "{\"uptime\":%lu,\"temperature\":%f,\"humidity\":%f,\"distance\":%lu,\"accelx\":%lu,\"accely\":%lu}", millis() / 1000, t, h, distance, x, y); // MQTT SerialUSB.print("Publish:"); // MQTT SerialUSB.print(envDataBuf); // MQTT SerialUSB.println(""); // MQTT MqttClient.publish(OUT_TOPIC, envDataBuf); //send data to beam // MQTTYou can get download code on attachments: mqtt_aquarium.ino5. Soracom
What is Soracom? Soracom is a MVNO (mobile virtual network operator), which means it doesn't operate its own network infrastructure, but instead has a partnership with NTT Docomo, one of Japan's largest telecoms, for its 3G and LTE. The Soracom User Console is in: https://console.soracom.io/#/login?return_to=The steps necessary to provision the board are installation of the Wio board drivers, Arduino board manager, Arduino example libraries, and the Wio LTE DFU and enable button sequences necessary to proceed. https://docs.google.com/document/d/1gkRrCF4lvVy_spg2ew1EJV8t7RgtL6Es6zZQoezIZXM/edit?ts=5caa6fe0As part of my work, I show you my activated SIM.
Next, the SORACOM Beam is enabled.
And finally, Soracom Beam fill out. The Host name, we can get in the next chapter.
Also, Soracom register credential we can get in the next chapter.
You can learn more if you follow the instructions in the following video: https://www.youtube.com/watch?v=ofeiX9-qCxA6. AWS
In Soracom Beam fill out, the Host name is getting from: AWS Iot - SettingsTo get the security credentials, we do the following: AWS IoT - Secure - Polices - CreateWe type:
After we created the policy:
We continue with: AWS IoT - Secure - Certificates - CreateWe select. One-click certificate creation
After we download the credentials, we "Activate" the credentials.We "Attach a Policy", and select my IoT policy and click in "Done". Finally, we search our certificate and select "Active".7. IoT Analytics
The main goal of this chapter is to graph the captured data. In AWS IoT Analytics we give a name to the "Resources prefix", and click on "Quick Create"
We´re going to create a rule, so we give a name to our action and fill out the "Rule query statement" as follow: SELECT *FROM ‘outTopic’Click on "Add Action" and select "Send a message to IoT Analytics" and finally click on "Configure action"In "Configure action" click on: Send a message to IoT AnalyticsSelect your channel name and click on "Create Role" and give a nameClick on Create role.Now, we go to: AWS IoT - TestIn my case on "Subscription topic", I typed: outTopic and I can get the data values.When we have finished the test, the data hasn´t yet been loaded into "Content". So, we go to: IoT Analytics - Data setClick on Actions - Run now.On "Content" we can see the same dataYou can get this data on attachments: outTopic.json8. Sage Maker
Type: Amazon SageMaker and we select Create notebook instanceWe fill out the Notebook instance settings as follow:We need to created a role with permissions to share resources between IoT analytics and Sagemaker.
When you finished, click on Create notebook instance and once created, we hope it enters service.Finally, we Save, Run and RefreshThe graphic and averages are calculated with:
fig, ax = plt.subplots()df.temperature.plot(legend=True)df.humidity.plot(legend=True)df.distance.plot(legend=True)df.acceleration.plot(legend=True)plt.show()print('Average Humidity: ', df.humidity.mean())print('Number of samples: ', len(df))print('Average temperature: ', df.temperature.mean())print('Number of samples: ', len(df))print('Average distance: ', df.distance.mean())print('Number of samples: ', len(df))print('Average acceleration: ', df.acceleration.mean())print('Number of samples: ', len(df))You can get download code on attachments: aquarium_graphic.py