Paulo BartolomeuEmanuel Vieira
Published © GPL3+

payIOTA - Internet of Public Transport Payments

payIOTA is the stepping stone proof-of-concept for a seamless and universal public transport payment system.

IntermediateWork in progress1.5 hours916
payIOTA - Internet of Public Transport Payments

Things used in this project

Hardware components

Android device
Android device
×1
Personal Computer with BLE support
×1

Software apps and online services

Node.js
Android Studio
Android Studio

Story

Read more

Code

IOTA Beacon "main.js"

JavaScript
A BLE beacon. It advertises a IOTA transaction hash. Run it with Node.js and install the Bleno library. If you have any problems installing Bleno, try installing it with Node.js v8.0.
It contains a "main.js" and a "characteristic.js" scripts.
var bleno = require('bleno');

var BlenoPrimaryService = bleno.PrimaryService;

var EchoCharacteristic = require('./characteristic');

const beacon_name = 'IOTABeacon ' + Math.random().toString(36).substring(2,8)

console.log(beacon_name);

bleno.on('stateChange', function(state) {
  console.log('on -> stateChange: ' + state);

  if (state === 'poweredOn') {
    bleno.startAdvertising(beacon_name , ['107a']);
  } else {
    bleno.stopAdvertising();
  }
});

bleno.on('advertisingStart', function(error) {
  console.log('on -> advertisingStart: ' + (error ? 'error ' + error : 'success'));

  if (!error) {
    bleno.setServices([
      new BlenoPrimaryService({
        uuid: '107a',
        characteristics: [
          new EchoCharacteristic()
        ]
      })
    ]);
  }
});

IOTA Beacons app

Java
An Android Studio project containing the app source code in Kotlin. Compressed with 7z. Extraction password: iotaitbeacon

wget https://www.dropbox.com/s/krzus5eg6nle0vx/IOTABeacon.7z?dl=0
No preview (download only).

IOTA Beacon "characteristic.js"

JavaScript
A BLE beacon. It advertises a IOTA transaction hash. Run it with Node.js and install the Bleno library. If you have any problems installing Bleno, try installing it with Node.js v8.0.
It contains a "main.js" and a "characteristic.js" scripts.
var util = require('util');

var bleno = require('bleno');

var BlenoCharacteristic = bleno.Characteristic;

var EchoCharacteristic = function() {
  EchoCharacteristic.super_.call(this, {
    uuid: '107a',
    properties: ['read'],
    value: null
  });

  this._value = Buffer.from("9GQPJQWSIRCKQZG9VGXMPVYVSWUDEIULRQPIHHQSBHXTSQTSFCKYPD9EWFQKMGOGUVJXBIYRXBBUA9999");
  this._updateValueCallback = null;
};

util.inherits(EchoCharacteristic, BlenoCharacteristic);

EchoCharacteristic.prototype.onReadRequest = function(offset, callback) {
  console.log('IOTABeacon Address = ' + this._value.toString('hex'));

  callback(this.RESULT_SUCCESS, this._value);
};

module.exports = EchoCharacteristic;

Credits

Paulo Bartolomeu

Paulo Bartolomeu

1 project • 1 follower
Emanuel Vieira

Emanuel Vieira

1 project • 1 follower

Comments