Quantcast
Channel: SCN : All Content - SAPUI5 Developer Center
Viewing all articles
Browse latest Browse all 6178

SAPUI5 Cordova Electricity Meter Reading

$
0
0

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.



Screenshot_2015-09-16-23-03-03.pngScreenshot_2015-09-16-23-02-51.pngScreenshot_2015-09-16-23-02-42.png

IMG_3149.JPG


  • 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


  • 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.
    1.jpg
  • 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!


Viewing all articles
Browse latest Browse all 6178

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>