Biswajit Roy
Published © GPL3+

Lastleaf – IoT Service for Vehicles During Accidents

Lastleaf rescues from road accidents by sending automated SOS using Raspberry Pi, Android application, Soracom service and Internet.
  • Difficulty: Intermediate
  • Type: tutorial
  • Duration: 4 hours
  • Views: 1016
Lastleaf – IoT Service for Vehicles During Accidents

Things used in this project

Hardware components

Android device Android device × 1
Raspberry Pi Zero Wireless Raspberry Pi Zero Wireless × 1
Ultrasonic Sensor - HC-SR04 (Generic) Ultrasonic Sensor - HC-SR04 (Generic) × 1
SORACOM Air Global IoT SIM SORACOM Air Global IoT SIM × 1
USB Connector, OTG USB Connector, OTG × 1
Huawei MS2131i-8 × 1
USB-A to Mini-USB Cable USB-A to Mini-USB Cable × 1

Software apps and online services

Raspbian Raspbian × 1
SORACOM Air IoT Connectivity Platform SORACOM Air IoT Connectivity Platform × 1
Firebase Firebase × 1

Story

Introduction to Lastleaf

There are lots of accidents occurring in national highways especially during cold and foggy climate and there are some services available that help prevent such accidents but what if the accident has occurred late night or there is heavy snow. "Lastleaf" will address the solution using cloud services and IoT technology that will alert nearby police stations, hospitals and even relatives of such emergency situation. There shall not be any manual triggering required since the service will sense accidents and hazards.

How does this work?

While boarding a vehicle, we turn on the Lastleaf android application that transmits GPS data using beacons. Due to impact during an accident, the HCSR04 moves closer to the wall of the setup box via rails recording a lower distance which triggers SORACOM AIR messaging and logging in server with the GPS co-ordinates captured from the nearby android device.

Building up the service

We have three modules for Lastleaf:1. The software that runs on Lastleaf setup. (Lastleaf iBeacon Transponder)2. An Android application. (Lastleaf Application)3. A cloud service utility. (Lastleaf Harvest)

Let's build them one by one:

1. The software that runs on Lastleaf setup (Lastleaf iBeacon Transponder)

Set up your Raspberry pi Zero W with Raspbian OS and a configured WLAN. Now, install Putty (if on Windows), Linux users may use the native sshutility to login to Raspberry Pi. Keep it ready, we'll need that soon.

On your machine, make sure to have a proper Golang and Git installation:git clone the repository.

In your go project directory, execute:

env GOOS=linux GOARCH=arm GOARM=5 go build Copy the binary executable to your Raspberry Pi, probably using ssh: scp ./name-of-binary-file pi@raspberrypi.local:~/ Copy Majimak.py to Raspberry pi.Rename the fragment to your executable at line 34 of Majimak.py: subprocess.call(["sudo","./your_lastleaf"]) Run the go executable in sudo mode to check if everything's okay.Setting up Soracom account: Head over here to create your Soracom Account. For international, head here.Register your SIM card and record your API_KEY and API_TOKEN.Plug the Soracom SIM card to your mobile phone.Configuring Majimak.py: Give your device a specific CONST_DEVICE_ID as constant.
  • Plug in your API_KEY and API_TOKEN in the program.
  • Plug in your HC-SR04 sensor with the Raspberry Pi GPIO pins as declared in Majimak.py or customize them.Copy the Lastleaf.service file into your directory.
  • Now, run the following commands inside your Raspberry Pi shell:
  • sudo cp Lastleaf.service /lib/systemd/system sudo chmod 644 /lib/systemd/system/Lastleaf.service sudo systemctl daemon-reload sudo systemctl enable Lastleaf.service
  • Now, sudo reboot your Raspberry Pi.
  • Perform sudo systemctl status Lastleaf.service to check if the service is running !

    Now, we need to head to rest of the modules of Lastleaf.

    2. An Android application (Lastleaf Application)

    git clone the repository.
  • Start Android Studio to compile the project.
  • About the moduleLastleaf (moblie client) is a mobile client application that produces iBeacons and sends GPS data as payload using the Bluetooth LE technology.Supported devicesPlease visit these links to check if your device supports iBeacons:https://en.wikipedia.org/wiki/IBeacon#Compatible_deviceshttps://altbeacon.github.io/android-beacon-library/beacon-transmitter-devices.htmlAbout the applicationLastleaf (moblie client) is an android application that requests for current GPS location from user and generates beacons to broadcast the GPS data (current latitude and longitude) as payload. The beacons released maintains iBeacon standards. More here. Please note that this application does not involve capturing existing beacons in space. The produced iBeacongets captured by a Raspberry pi zero W hardware and triggers events declared in repository here.Libraries and dependenciesPlease make sure to have the following library and dependency before compiling.dependencies {implementation 'org.altbeacon:android-beacon-library:2.16.1'} Screenshots

    3. A cloud service utility (Lastleaf Harvest)

    About the moduleHarvest is a firebase project that works on server side for Lastleaf IOT Service. Harvest is responsible for logging Lastleaf hardware's health, determining application crashes and failures, logging missing hardware information and developing standards for updated versions.Prerequisites
  • Node.js
  • Firebase CLI
  • Firebase Project
  • Up and runninggit clone the repository.Set up your firebase project and deploy the application using : firebase deploy. Let's see Lastleaf in operation: