Software apps and online services
Earth is made up of 71% of water and has vast oceans with a lot of water. Oceans help us a lot but also cause lot of damage to life and property, mainly in the form of tsunamis. The Title... yes we are observing the ocean surface movements but not controlling it as it is IMPOSSIBLE to go against the force of nature! Back to problem. The problem is that the tsunamis are unpredictable. After their occurrence we just estimate the time required to come to shore based on its initial velocity, but as it develops and moves the velocity may increase; accelerates and the direction may also change which can make the predictions incorrect.
The solution to the problem is that we can get the movement of waters in real time. Currently the way they see the upcoming wave is by use of satellites and/or boats which is slow and also not so real time. The way it can be easily identified and recognized is with the help of some devices which stay at the place of starting i.e., epicenter and calculate and send the data to a server. We can have the device in a barrel or "any such static structure" in middle of the ocean at various locations especially in places where tsunamis are predicted to start. Also the devices can be placed where there are no tsunamis but they can still help to determine ocean currents and other research indicated things as they may also contain some other useful sensors.
The project works by using the Sony's new Spresense board to find the coordinates of the device in the ocean and based on the changes in it i.e., as the coordinates change; we find the acceleration and velocity of wave. This is done by using haversine formula according to which we can find distance between places based on co-ordinal points (logic below). So, if we take GPS measurements in very small time (here 1 sec), then we can find distance traveled in particular time interval and its direction also. Then we can easily find the acceleration of the wave. Ideally the data needs to be transferred by satellite communication as there is no GSM/WiFi in middle of ocean, but for proof of concept, here we are using WiFi to communicate with server.
We can also use the new tech of sending some short messages with GNSS (mostly disaster related, but data can also be sent?!) to the connected satellites like with the Japanese QZSS Michibiki, which's GNSS devices can receive disaster (disaster / crisis) reports such as disaster information and crisis management information. (So, other way may also be possible?)!
Spresense is a compact development board based on Sony’s power-efficient multicore microcontroller CXD5602. It allows developers to create IoT applications in a very short time and is supported by the Arduino IDE as well as the more advanced NuttX based SDK.
- Integrated GPS- The embedded GNSS with support for GPS, QZSS and GLONASS enables applications where tracking is required.
- Hi-res audio output and multi mic inputs- Advanced 192kHz/24 bit audio codec and amplifier for audio output, and support for up to 8 mic input channels.
- Multicore microcontroller- Spresense is powered by Sony's CXD5602 microcontroller (ARM® Cortex®-M4F × 6 cores), with a clock speed of 156 MHz.
To code the Spresense board we are using the Spresense SDK based on NuttX RTOS (Real-Time Operating System).
The main reason for using it is the ability for multi core programming. For this project it is very important to send the data in real time without any delay and for that if we use a single core then, one task is stopped while executing other. So, when we are sending data (which takes time), the GNSS signal is lost and the code restarts not fulfilling the purpose and sending the data in real time also with skipping to send some data bits.
It is very much recommended to see the Get Started with Spresemse SDK to code the Spresense board and also flash the boot-loader. I had to make a virtual machine of Ubuntu to use the SDK on my Windows machine, which hopefully gets updated in future. Also reading SDK guide is recommended. As by just looking at examples, It is not possible to understand anything due to very little or no comments about the specific block of code.
The Spresense ASMP framework is designed for multi-core architecture processors, based on NuttX. It defines two tasks:
- Supervisor task (runs on the main CPU)
- Worker task (runs on the coprocessor)
The Worker task executes on the co processor, independently from the main CPU.
I combined the Spresense ASMP code with the GNSS code with my very little pure C knowledge for it to work. To keep things simple I just used two cores, the main takes GNSS readings and passes the data to other core which sends it via serial (which takes time) and it can also operate GSM or other satellite communication (but with very little knowledge on encryption and etc, and lack of libraries, I just sent the raw data via serial). It is though recommended to not use any other print statements except the one sending data in worker code otherwise the other board once connected will not receive proper data. Although for debugging they can be used. The statements from GNSS sample code have also been kept which must be commented. We can also use other cores (out of remaining 4) to just dedicate one in collecting GPS data and other core getting sensor readings (if any), etc.
The code is very simple in "theory", it just takes Global Position and sends the data to other core which sends it via serial. Here we are using the MP mutex memory sharing framework which the ASMP provides. The data is in specific format as
HR;MIN;SEC;LAT;LON which are the only main parts I added after combining the programs. You need different codes though for all cores and arranged in format and made in format from Spresense Git repo.
I hope that future support and more documentation for beginners is provided to use more than 2 cores as I couldn't figure out how we can.
The code is found below
Google Firebase is Google's mobile platform that helps you quickly develop high-quality apps and grow your business. But, we are using it to store our data as it is free for one database. To get started with it>
- Open Firebase Console and login or register if you have never used it.
- Create New Project and fill the details.
- Then go to database and create new database. Make sure you use RealTime database. Also use test mode as it is easy for prototyping, but using locked mode is also possible.
- You will be able to see the data in the fields. Also the data is stored in JSON format.
- Just take a not of your database URL. Hidden in red in upper image.
- Then you need to find the your API key. Go to settings icon in project settings. Record the API key you see.
- That's it. You can now play around with it.
NodeMCU is an open source IoT platform. It includes firmware which runs on the ESP8266 Wi-Fi SoC from Espressif Systems, and hardware which is based on the ESP-12 module. We are using it to only receive data from the Spresense board and then sending it to our database, which here is Google's Firebase. We are using the Arduino FireBase library.
In the code we take the serial input from Spresense main board and then parse it. It also has code to find distance between two places with haversine formula mentioned ahead. We need the baud rate for serial to be 115200 as Spresense sends to serial at 115200 so without doing any mods in Spresense board, we can get the data.
The code can be found below. Don't forget to change SSID, Pass of WiFi and credentials for Firebase.
The finished Arrangement
This is a sample of data collected in backyard while I was moving.
Here you can see that data is sent with label as
HR:M:S, all is as GMT though. So, the data that you get is according to Greenwich time and you need to find yours by adding/subtracting time difference. Also it is in format of
So, from two consecutive data streams you can find the distance which for me cam to be 0.0012KM (approx) as I moved outside. This is very small but in high velocities waves, it can be easily seen. Also the GPS accuracy is very good but the distance is not correct due to the fact that the way measure the distance is for perfect sphere. But earth is not a perfect sphere but also has different land forms, etc. But at MSL (mean sea level) it can be quite accurate.
It is an interesting project and can probably be very helpful. I did not get any chance or way I could test it in a practical realistic situation, except just walking near WiFi AP.
I also wanted to predict the devastation of tsunamis and the direction of flow of water based on data and public available collected data. For that I planned to use Neural Network Console Cloud option from Sony. But it is sadly only available in Japan and the DNNRT library is only for Arduino. Hopefully the Cloud option is available across the globe as my machine was very slow in even downloading and executing first layer of convolution that I stopped based on predicted time.
There are a lot of ways the project can be improved>
- By getting the distance in the database itself. This is very easy but GFirebase free plan cannot permit more than one DB, which needs another server?
- Use a dedicated personal DB rather than some cloud. Ex: InfluxDB or mySQL.
- Make an android/web app that can see the approaching wave and tell you its velocity and direction. The app also tells the different other such devices deployed and it can stimulate and show the direction of the wave with the data from all devices combined.
- Use Satellite communication of some kind
- Find some way to power it in middle of ocean rather than a charged power bank. Mostly Solar Energy.
- Think of a proper way it can move to a certain distance with the wave but also return to its original position.
It will also be great if Sony could add a lot more comments in their code and also do something for Windows users as it will be great for beginners. Also, if there is multi core support in Arduino IDE (like ESP32) it will be great as it can use full potential of the board and also have the advantage of vast majority of libraries. And the Neural Network Console available globally.