Technology Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
6,221

In many homes there are still electricity meters with a mechanical counter that do not provide a direct interface for reading the consumption of electrical energy. In this blog, I am trying to capture the consumption of electrical energy with a mobile device (Android) as a scanner to read the information from the mechanical counter and record it in the database like SAP HCP. In this case, we are going to build a SAPUI5 Cordova electricity meter reading with the SDK from Anyline.io.




  • Go to Anyline.io website to download the SDK Cordova plugin and obtain the license. 
  • Setup and build the Cordova project under C:\programs
    • cordova create C:\programs\meterReading com.enterprisemobility.meterReading meterReading
    • cd c:\programs\meterReading\
    • cordova platform add android
    • cordova plugin add <path_to_AnylineSDK_Cordova_Plugin>


  • Create a function to scan the mechanical counter by calling the scanElectricMeter function in ElectricScan.controller.js:

    scanElectricMeter: function() {
    cordova.exec(this.onResult, this.onError, "AnylineSDK", "scanElectricMeter", this.energyConfig);
    }






  • If scan is success, it will call the onResult function which will capture the meter reading value and pass the information to the ScanResult.view.js.

    onResult: function(result) {
    var meterType = []; var reading=[];
    meterType.push(result.meterType);
    reading.push(result.reading);
    var data = [];
    for(var i = 0; i < meterType.length; i++) {
    data.push({"meterType": meterType[i], "reading": reading[i]});
    }
    var oModel1 = new sap.ui.model.json.JSONModel({ "zgwmat": data });
    sap.ui.getCore().setModel(oModel1, "zgwmatmodel");
    var bus = sap.ui.getCore().getEventBus();
    bus.publish("nav", "to", {
      id : "scanresult",
    });
    },






  • I have attached the complete source code in this blog: www.zip. Replace the c:\Programs\meterReading\www folder with the attached www folder.
  • Download SAPUI5 runtime here and save it under C:\Programs\meterReading\www\resources
  • Build the cordova project under c:\programs\meterReading, execute command cordova build
  • Install the generated .apk from c:\Programs\meterReading\platforms\android\build\outputs\apk to your Android device.

That's it!

15 Comments