Aquarium Monitoring with AWS-Seeed-Soracom

If our pollution adversely affects the environment, then, it's our responsibility to protect the environment, humans, plants, and animals.
Guillermo Guillen
Published © MIT
Aquarium Monitoring with AWS-Seeed-Soracom
Difficulty: Advanced | Type: tutorial | Duration: 72 hours | Views: 409

Things used in this project

Hardware components

SORACOM Air Global IoT SIM SORACOM Air Global IoT SIM × 1
Wio LTE US Version - 4G, Cat.1, GNSS, JavaScript(Espruino) Compatible Wio LTE US Version - 4G, Cat.1, GNSS, JavaScript(Espruino) Compatible × 1
Grove - Ultrasonic Ranger Grove - Ultrasonic Ranger × 1
Grove - 3-Axis Digital Accelerometer ±16g Ultra-low Power (BMA400) Grove - 3-Axis Digital Accelerometer ±16g Ultra-low Power (BMA400) × 1
Grove - Temperature, Humidity, Pressure and Gas Sensor (BME680) Grove - Temperature, Humidity, Pressure and Gas Sensor (BME680) × 1
Antenna, Cellular / LTE Antenna, Cellular / LTE × 2
USB-A to Micro-USB Cable USB-A to Micro-USB Cable × 1
3.7V Lipo battery × 1

Software apps and online services

AWS IoT AWS IoT × 1
AWS IAM AWS IAM × 1
SORACOM Beam - Data Transfer Support SORACOM Beam - Data Transfer Support × 1
Arduino IDE Arduino IDE × 1
Jupyter Notebook Jupyter Notebook × 1
Python 2.7 × 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:
  • The DHT11 sensor, will measures the temperature and humidity of the environment of our aquarium.
  • The SRF04 sensor, will measures the distance from our sensor to the water in our aquarium, and so we can have an idea of the level water.
  • The ADXL345 sensor, will detects the vibrations of our air pump, or when our turtles are in motion.
  • We are going to use Beam method, and the data will transmitt from the Wio LTE board to the end point of Beam on a 3G/4G/LTE closed network, communication encrypted and the data can be safely delivered to the Amazon Web Services.
  • 2. Cost Effectiveness

    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.

    In 2006, according to Food and Agriculture Organization (FAO). Export earnings from ornamental fish trade is US $ 251 million and more than 60% of the production comes from households of developing countries. The wholesale value of the global ornamental fish trade is estimated to be US $ 14 Billion. More than 2500 species of ornamental fishes are traded and some 30-35 species of fresh water dominate the market. The top exporting country is Singapore, followed by Hong Kong, Malaysia, Thailand, Philippines, Sri Lanka, Taiwan, Indonesia and India. The largest importer of ornamental fish is USA. Europe and Japan, China and South Africa are the emerging markets of ornamental fish trade.

    3. Seeed's Hardware

    Seeed Studio + SORACOM Starter KitWhat 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. Seeed Studio + SORACOM Starter Kit

    This project uses the Wio LTE running an Arduino sketch to send data to AWS IoT. There are prerequisites to complete before we can connect and program our cellular device and send data to AWS IoT.

    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?
  • The following sensors capture the data and are sent to the Wio LTE board: DHT11 humidity and temperature sensor, SRF04 ultrasonic sensor and ADXL345 accelerometer.
  • When we uploading data from an IoT device using Beam, the data is transmitted from the Wio LTE board to the end point of Beam on a 3G/4G/LTE closed network, communication is encrypted by Beam on the Internet past Beam, and the data can be safely delivered to the Amazon Web Services (AWS).
  • Before you go ahead, I suggest you read this important information about the Wio LTE board: http://wiki.seeedstudio.com/Wio_LTE_Cat.1

    4. Seeed's Software

    In our project, we used Arduino IDE and have combined the codes of the following manufacturer's examples:

  • Examples - Wio LTE for Arduino - mqtt - mqtt-client
  • Examples - Wio LTE for Arduino - grove - grove-accelerometer
  • Examples - Wio LTE for Arduino - grove - ultrasonic-ranger
  • Examples - Wio LTE for Arduino - grove - temperature-and-humidity-sensor
  • 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> // MQTT

    The 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" // MQTT

    The 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 sensor

    The 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 // MQTT You can get download code on attachments: mqtt_aquarium.ino

    5. Soracom Beam

    Beam is a proxy service that receives data sent from a device equipped with a Soracom Air SIM card, and processes it in the cloud.

    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=Don't forget plug your SIM card to the Wio LTE boardRead and complete the Soracom Wio LTE getting started guide. It includes setting up the Wio LTE cellular development board. 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=5caa6fe0

    As 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.

    For more details, you can learn more if you follow the instructions in the following video: https://www.youtube.com/watch?v=ofeiX9-qCxA

    6. AWS IoT

    In this chapter we're going to create device credentials and a IoT Policy for AWS IoT.

    What is Amazon Web Services? Amazon Web Services (AWS) is a comprehensive, evolving cloud computing platform provided by Amazon. It provides a mix of infrastructure as a service (IaaS), platform as a service (PaaS) and packaged software as a service (SaaS) offerings. The AWS Cloud Computing is in: https://aws.amazon.com/es/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 - Create

    We type:

  • Name:
  • Action: iot:*
  • Resource ARN: *
  • Effect: Allow
  • After we created the policy:

    We continue with: AWS IoT - Secure - Certificates - Create

    We select. One-click certificate creation

    Now we download:

  • A certificate fot this thing
  • A private key
  • A root CA for AWS IoT. After click in download, we select: Amazon Root CA 1
  • 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".For more details, you can consult: https://www.youtube.com/watch?v=sdgXt7Sq2dM

    7. AWS 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"

    Now we go to: IoT Core - Act and click on ActionWe´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 AnalyticsClick on: Manually select IoT Analytics Channel and roleSelect your channel name and click on "Create Role" and give a nameClick on Create role. Click on Add ActionClick on Create ruleand Enabled the rule created.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 setIn my case, I select: analy31b_dataset and I can see that there is nothing in Results previewClick on Actions - Run now.Now on "Details" we can se the dataOn "Content" we can see the same dataYou can get this data on attachments: outTopic.json

    8. Amazon SageMaker

    In the web browser we 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. Go to ‘IAM’ and create a role with access to both services then select that role when you make your Jupyter Notebook instance. https://console.aws.amazon.com/iam/home?#/rolesWhen you finished, click on Create notebook instance and once created, we hope it enters service.Then, we click on: Open Jupiter. Click on: New - conda_chainer_p27 or New - conda_pytorch_p27We insert the code of the file: aquarium_graphic.pyFinally, we Save, Run and Refresh

    The 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

    9. Test and Analysis

    In the following video, we can appreciate all the tests carried out with this system, from the Seeed hardware, later with the Soracom console and finally with Amazon Web Services.Analysis
  • The temperature remained stable (24.5 degree Celcius).
  • The humidity had important variations about 9 units (54% - 63%).
  • The distance from the sensor to the water remained stable (24 cm), except at the end of the test, we can see some wrong data (4 cm).
  • The acceleration remained stable (26), except at the end of the test (35), where it´s seen that the vibrations of the aquarium increased, and this could be because to the turtles movements.
  • You can get this data on attachments: outTopic.json

    10. Conclusions

    We succeeded in measuring the humidity, temperature, vibrations and water level of our aquarium with Seeed hardware. Soracom Beam proved to be very efficient and safe to transmit data to AWS. This project is very practical and we can use it in any aquarium by mean 3G or 4G cellular technology, and remotely we can meassure all the parameters we want. It could even be used in fish farming, lagoons, rivers, beaches, bays, forest and jungle.We are going to associate with the wholesaler of the commercial aquarium service to ensure that our product reaches the consumer, and to reduce the operating costs, we must schedule the time in which we will monitor our aquarium. For example, two or three times a day and for one hour is enough. In my case, I used this method, and I didn´t spend all the credit assigned to me for the project.
  • Limitations of my project, in relationship with Seeeed´s catalog are: 1) I would liked to do tests with more sensors as Multichannel Gas Sensor, Grove Air Quality Sensor and Grove Water Sensor. 2) Propose the manufacture of a sensor that measures the water quality, since it doesn´t exists in it´s catalog.