What is your project about?
The Australian postal network has an opportunity to be disrupted. Based on the Australian Pitney Bowes Parcel Shipping Index parcel “shipping market grew by 8.8 per cent in volume and 8.2 per cent in spend at AU$9.6 billion – the most growth in the Asia-Pacific region in 2015.”, thus meaning that people getting parcels is growing with the Index forecasting that parcel shipping volume to grow annually at 5 to 7 per cent for a total increase of 20 per cent by 2018, with cross border shipping leading the way.
Android things empowers a legacy industry to become the largest interconnected network in the country enabling it to act as the as the eyes, ears and sensor grid for a smart country, linking smart homes and smart cities.
Why did you decide to make it?
Australians are global leaders when it comes to online shopping according to the Pitney Bowes Global Online Shopping Survey:
· 88 per cent of Australians shop online with almost half (47 per cent) shopping online monthly.
· 86 per cent of Australians purchased products online from retailers in a different country within the last year – second only to Singapore.
· 78 per cent of Australians bought online cross-border in the last month and the last year – the most in the world.
We saw this as an opportunity to work on a solution that will disrupt the postal industry.
Who are we?
A group of talented and passionate developers, designers, and a product owner that work in the postage industry in Australia got together and looked at how they can make an impact on the issues the postage industry currently faces.
After careful analysis of the delivery process, the team identified key operational and customer pain points that occur throughout the postal journey.
The team then went into an ideation session in which they were asked to draft up a solution without any limitations.
After sifting through all the designs and options the team chose the most feasible and viable idea that was achievable in the timeframe they had left. The team have chosen to address not just one of the competition criteria rather two key categories, Smart Home and Smart City, using one
What does it do?SMART CITY
SMART Postal Box
The Smart Post Box uses sensors and smart devices to detect if there has been mail or any parcel left in postal boxes. It uses the Android things platform and allows users to see if the postal box has anything inside it.
This allows postal drivers to optimise routes and makes postal pick up efficient, removing the need for postal drivers to stop at boxes that are empty.
SMART PO BOX
The Smart PO Box allows users that have private mailboxes to know if they have received any mail or parcels. Alerting them when something has been delivered to their private mail boxes.
SMART HOME
SMART LETTERBOX
The Smart letterbox hack allows users to know when they receive any mail or a parcel in their letterboxes. Using Android things, the team hacked together an idea that allows users to know when they receive mail in their own letterbox, without the need for a new physical letterbox. With this system, you never have to worry about soggy mail ever again, and can even keep track of the typical times that mail arrives in your letter box.
All three hacked solutions allow integration with existing infrastructure, making dumb devices SMART.
FUTURE USES
If this hack is successful and selected to be implemented we have come up with some other key uses of the Android Things technology.
Postal Boxes: as a key contributor to the Smart City – adding sensors to detect foot traffic, air quality, local weather conditions, noise levels and possible demographic traffic passing postal boxes distributed in the city.
Retail Monitoring: If partnered with a postal service provider using Android things to heat map retail stores using motion sensors
Lodgement: Using weight sensors for parcel lodgement at postal boxes to calculate postage costs
Distribution Centre monitoring: Android things to monitor and collect information and data about parcel distribution centres, such as: area utilisation and foot traffic.
How does it work?Hardware
· Raspberry Pi 3
· Rainbow HAT starter kit Android Things
· PIR motion detector
Setup and Build
The smart letterbox Android Things uses
- Android things to detect letters put in the smart mailbox
- Firebase realtime database to store information
- Firebase realtime database trigger to notify users when there is a letter
Android Things Setup
The following instructions explain how to setup the raspberry PI running on Android Things
To flash the image and connect Wi-Fi follow the detailed instructions on https://developer.android.com/things/hardware/raspberrypi.html
Android Studio - Android Things project
Open Android Studios and create a new Android project
Add the android things drivers as a dependencies to the Android Project
compileOnly 'com.google.android.things:androidthings:+'
implementation 'com.google.android.things.contrib:driver-button:0.3'
implementation 'com.google.android.things.contrib:driver-ht16k33:0.3'
implementation 'com.google.android.things.contrib:driver-bmx280:0.2'
implementation 'com.google.android.things.contrib:driver-apa102:0.3'
RainbowBaseActivity
The RainbowBaseActivity will be used to setup and access all the sensors through the provided drivers and GPIOs. There are number of sensors that we can access on the Rainbow HAT Start Kit for Things
Setup the A B C touch buttons found on the Rainbow HAT
// buttons
private static final String BUTTON_A_GPIO_PIN = "BCM21";
private static final String BUTTON_B_GPIO_PIN = "BCM20";
private static final String BUTTON_C_GPIO_PIN = "BCM16";
private Button buttonA;
private Button buttonB;
private Button buttonC;
private void setupAllButton() {
try {
buttonA = new Button(BUTTON_A_GPIO_PIN, Button.LogicState.PRESSED_WHEN_HIGH);
buttonA.setOnButtonEventListener(this);
buttonB = new Button(BUTTON_B_GPIO_PIN, Button.LogicState.PRESSED_WHEN_HIGH);
buttonB.setOnButtonEventListener(this);
buttonC = new Button(BUTTON_C_GPIO_PIN, Button.LogicState.PRESSED_WHEN_HIGH);
buttonC.setOnButtonEventListener(this);
} catch (IOException e) {
e.printStackTrace();
}
}
Setup the alphanumberic display found on the Rainbow HAT
// display
private static final String DISPLAY_I2C_BUS = "I2C1";
private AlphanumericDisplay display;
private void setupAlphanumericDisplay() {
try {
display = new AlphanumericDisplay(DISPLAY_I2C_BUS);
display.setBrightness(1.0f);
display.setEnabled(true);
display("");
} catch (IOException e) {
e.printStackTrace();
}
}
Setup LED Strip found on the Rainbow HAT
// LED strip
private static final String LED_STRIP = "SPI0.0";
Apa102 ledStrip;
private void setupLedStrip() {
try {
ledStrip = new Apa102(LED_STRIP, Apa102.Mode.BGR);
ledStrip.setBrightness(2);
} catch (IOException e) {
e.printStackTrace();
}
Setup LED lights found on the Rainbow HAT
// led lights
private static final String LED_LEFT = "BCM6";
private static final String LED_MID = "BCM19";
private static final String LED_RIGHT = "BCM26";
private Gpio ledRed;
private Gpio ledGreen;
private Gpio ledBlue;
private void setupAllLedLights() {
try {
ledRed = pioService.openGpio(LED_LEFT);
ledRed.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
ledGreen = pioService.openGpio(LED_MID);
ledGreen.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
ledBlue = pioService.openGpio(LED_RIGHT);
ledBlue.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
} catch (IOException e) {
e.printStackTrace();
}
}
Create PIR motion sensor by using GPIO “BCM18”
public class PirMotionSensor implements MotionSensor {
private final Gpio bus;
private final MotionSensor.Listener listener;
public PirMotionSensor(Gpio bus, Listener listener) {
this.bus = bus;
this.listener = listener;
}
@Override
public void startup() {
try {
bus.setDirection(Gpio.DIRECTION_IN);
bus.setActiveType(Gpio.ACTIVE_HIGH);
bus.setEdgeTriggerType(Gpio.EDGE_RISING);
} catch (IOException e) {
throw new IllegalStateException("Sensor can't start", e);
}
try {
bus.registerGpioCallback(callback);
} catch (IOException e) {
throw new IllegalStateException("Sensor can't register callback", e);
}
}
private final GpioCallback callback = new GpioCallback() {
@Override
public boolean onGpioEdge(Gpio gpio) {
Log.d("PirMotionSensor", "motion detected");
listener.onMovement();
return true; // True to continue listening
}
};
@Override
public void shutdown() {
bus.unregisterGpioCallback(callback);
try {
bus.close();
} catch (IOException e) {
Log.e("TUT", "Failed to shut down.", e);
}
}
}
Create a Temperature service using Bmx280SensorDriver to monitor temperature changes
public class TemperaturePressureService extends Service {
private static final String TAG = "TempPressureService";
private static final String I2C_BUS = "I2C1";
private Bmx280SensorDriver mTemperatureSensorDriver;
@Override
public void onCreate() {
setupTemperaturePressureSensor();
}
@Override
public void onDestroy() {
super.onDestroy();
destroyTemperaturePressureSensor();
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_NOT_STICKY;
}
private void setupTemperaturePressureSensor() {
try {
mTemperatureSensorDriver = new Bmx280SensorDriver(I2C_BUS);
mTemperatureSensorDriver.registerTemperatureSensor();
} catch (IOException e) {
Log.e(TAG, "Error configuring sensor", e);
}
}
private void destroyTemperaturePressureSensor() {
if (mTemperatureSensorDriver != null) {
mTemperatureSensorDriver.unregisterTemperatureSensor();
try {
mTemperatureSensorDriver.close();
} catch (IOException e) {
Log.e(TAG, "Error closing sensor", e);
} finally {
mTemperatureSensorDriver = null;
}
}
}
}
Register the Temperature service the AndroidManifest.xml
<service android:name="post.com.au.thingsplayground.TemperaturePressureService"/>
Setup all sensors when the activity is created.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setupLedStrip();
setupAllButton();
setupAlphanumericDisplay();
setupAllLedLights();
registerSensor();
setUpMotionSensor();
}
Add the IOT launcher to manifest so that the activity is created after the device is booted
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.IOT_LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
MainActivity
The main activity contain our business logic and implement our smart letter box. It will provide the following features ;
- Send the temperature changes to the firebase
- Send letter count to firebase
- Show a gauge on how full the letterbox is
- Display FULL if the letterbox reaches a maximum number of letters
Add firebase dependencies to the project
compile 'com.google.firebase:firebase-database:11.4.2'
Download the google-services.json file from the Firebase console and add to the Android project.
Send temperature changes to firebase
@Override
protected void onTemperatureChange(float temperature) {
// sync new temperature to firebase
DatabaseReference database = FirebaseDatabase.getInstance().getReference();
database.child("postboxes").child("0").child("degree").setValue(String.format("%.1fC",temperature));
}
Light up the LED lights when A B or C buttons are pressed. If the A button is pressed show the Red LED light, B pressed show Green LED light, C pressed show Blue LED light. Also increment the A button when it is pressed and decrement the counter when the C button is pressed. Pressing the C button resets the counter to zero, this would be used when you collect the mail.
@Override
protected void onButtonEvent(WhichButton which, boolean pressed) {
switch (which) {
case A:
// press button A to increase the counter
if(pressed) {
light(WhichLed.RED, false);
} else {
light(WhichLed.RED, true);
increaseCounter();
}
break;
case B:
// press button B to reset the counter
if(pressed) {
light(WhichLed.GREEN, false);
} else {
light(WhichLed.GREEN, true);
counter = 0;
display(counter);
syncCounter();
}
break;
case C:
// press button C to decrease the counter
if(pressed) {
light(WhichLed.BLUE, false);
} else {
light(WhichLed.BLUE, true);
decreaseCounter();
}
break;
}
}
The sync counter method is used to send the letter count to firebase. It is also used to show a gauge on how full the letter box is. When the letterbox has lots of capacity the green lights are displayed on the LED light strip. When the letterbox is 1/3 full the yellow lights are displayed on the yellow LED light strip and when the letterbox is more than 2/3 full red lights are shown on the red LED light strip.
private void syncCounter() {
DatabaseReference db = FirebaseDatabase.getInstance().getReference();
db.child("postboxes").child("0").child("lettercount").setValue(counter);
int color ;
if (counter >= MAX_COUNTER_NUMBER * 2 / 3) {
color = Color.RED;
} else if (counter >= MAX_COUNTER_NUMBER / 3) {
color = Color.YELLOW;
} else {
color = Color.GREEN;
}
setLedStrip(color, color, color, color, color, color, color);
}
When the letterbox fills FULL is displayed on alphanumeric display.
@Override
protected void display(int number) {
super.display(number);
// if current counter is larger than max value, show text "FULL" instead
// of actual counter value
if (counter > MAX_COUNTER_NUMBER) {
display("FULL");
}
}
Create Firebase project
Go to https://console.firebase.google.com/ Log in and “Add Project".
Select the new project and navigate to “Database” and import the database json file.
Firebase Cloud Functions Deployment:
In order to do this, navigate into the firebase_function/functions folder within the repository.
For installing firebase CLI refer to https://firebase.google.com/docs/functions/get-started
To deploy cloud function:
- Run firebase login to log in via the browser and authenticate the firebase tool.
- Run firebase deploy --only functions under firebase_function /functions folder.
You should then see "Deploy complete" with a link to the project console for you to view the deployed functions like below
You should then be able to view the function in the Firebase Console online:
To enable email notification on database triggering
Navigate to index.js in the firebase_function/functions folder and filling in your email and password.
Fill in the from and to email address
Refer to this to turn on “Less secure app” so cloud function can use your gmail account to send emails.
Photoshttps://www.pitneybowes.com/au/newsroom/press-releases/shipping-index.html
http://www.zdnet.com/article/how-the-u-s-postal-service-could-enable-smart-cities/
https://www.wired.com/story/google-sidewalk-labs-toronto-quayside/
Images used by https://www.flaticon.com/
Comments