Could Iranian Sanctions Boost the Price of Gold?

Secretary of State Mike Pompano recently announced the US will impose the “strongest sanctions in history” on Iran. This follows Trump’s decision to pull the US out of a nuclear deal agreed to during…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Hover As An Offline Fallback

This post explores how Hover + USSD can be used as a data fallback when internet connectivity is unavailable.

A fallback is defined as a contingency option to be taken if the preferred choice is unavailable. Hover is an Android SDK that automates existing USSD sessions in the background of Android applications. We will set up a USSD channel (with a USSD backend), configure an action on the Hover dashboard and integrate the action as an offline fallback in an Android app.

USSD has two modes of operation, USSD PULL, which is mobile initiated and USSD PUSH, which is network initiated. For this fallback use-case, we’ll be using the mobile initiated mode to communicate data between the app and server. The USSD protocol will serve as a transport layer and USSD messages will be the data packets communicated between the app and the server. Hover will be the “USSD client” for the Android app, capable of sending and receiving USSD messages.

image 1.1

The maximum number of characters in a USSD message varies between carriers. Safaricom (KE) has a limit of 160 characters sent from the network from the user and a user input limit of 80 characters. Similarly, USSD session length varies between 90–180 seconds, depending on the carrier.

image 1.2

For the purpose of this demonstration, we’ll be sending a set of key/value pairs to the server. The flow involves four messages sent between the mobile app and the server:
1. Mobile dials USSD code, initiating a USSD session
2. Server responds with the message `send data`, awaiting input
3. Mobile sends url query string
4. Server receives and persists the data; responds with a final success message

We’ll use the Hover SDK to automate these four steps.

That’s because we haven’t set up the callback function that will read and respond to USSD requests. USSD response messages are in plain text beginning with the keyword `CON` if the session is ongoing. If the response message is the last for the session, begin with the keyword `END`. A simple USSD callback function that responds request with the message `Welcome to Hover` would look like this:

The complete callback function for the architecture described above (image 1.2) looks like this:

Dialing * 384 *94# now gives you the following messages:

image 1.3 Offline Fallback Action

The image above is an action configuration for our USSD interface. There’s one step configured, a variable that’s a direct response to the `send data` prompt.

image 1.4

The action has two parsers; a success parser and a failure parser. The success parser matches the message success, denoting a successful end of the USSD session. Similarly, the failure parser matches the message bad request, denoting a failed session.

The example above is in Kotlin and it demonstrated how you can run the action we created before with a valid payload. In this specific case, a valid payload means a URL encoded key/value pairs separated by a semicolon. Example:

Running the action described above (on an Android phone with no internet connectivity) will result in the following screens:

This demonstration shows how you can send data from an offline phone to your server but since the flow of data is bidirectional, you can also send a payload from your server to your app.

Due to the restrictions in message size and session length, you can only send lean data via USSD. I used the query string schema because of the limited payload size but any schema/encoding can be used as long as the payload size is not exceeded. You can send multiple messages in sequence as long as the session is still valid. This means that you can implement a chunking algorithm to send data in sequence.

Add a comment

Related posts:

Insurance for a Subaru Impreza for a 37 year old driver

Insurance for a Subaru Impreza Hatchback, sedan,WRX STI, Limited for a 37 year old driver Hatchback, sedan,WRX STI, Limited ANSWER: I might suggest you to visit this web page where you can compare…