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
    • 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.
    /wp-content/uploads/2015/09/1_791518.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!

To report this post you need to login first.

15 Comments

You must be Logged on to comment or reply to a post.

  1. junda li

    Dear Ferry,

    long time no see!

    have you tried mobile JS frameworks like Ionic, React etc?

    which I think are more suitable comparing SAPUI5 for such scenario.

    UI5 is designed more for simple enterprise UI whereas others are more for internet life.

    Regards.

    Legend.

    (0) 
    1. Ferry Gunawan Post author

      Hi Legend

      Yes, very long time we haven’t meet! 🙂

      I haven’t tried other JS framework that you have mentioned. Thanks for the suggestion, I shall explore it sometime.

      Regards,

      Ferry

      (0) 
    1. Ferry Gunawan Post author

      Hi Sven,

      Please try to debug the code in Eclipse and see what was missing. Did you replace the www folder with the attached one? also you need to get a valid license from Anyline.io. If someone can build the scanning process as an opensource, that will be great!

      Regards,
      Ferry Djaja

      (0) 
        1. Ferry Gunawan Post author

          I think there is a missing step to add the plugin to Cordova. Please download the AnylineSDK_CordovaPlugin and add to your cordova project. You can refer to their document here.

          I have updated the above blog to add the AnylineSDK Cordova plugin with this command:

          cordova plugin add <path_to_AnylineSDK_Cordova_Plugin>

          (0) 
          1. Sven Küter

            Where can i download the AnyLineSDK_CordovaPlugin? I have downloaded the AndroidSDK. I can’t find a download for a Cordova-Plugin. I have only the possibility to download the android-sdk or the ios-sdk.

            (0) 
            1. Ferry Gunawan Post author

              Once you have downloaded the AndroidSDK, they will send you an email with a link to download the Cordova plugin. Or please check/contact them how to get the Cordova Plugin SDK.

              (0) 
  2. Matthias Gasser

    You caught us at an exciting time, we’ve just launched our Community Edition yesterday, which is why it will take until early next week for the Cordova Plugin to be released again. Sorry for the inconvenience!


    I think you’ve talked to my colleague Carina already today, if you need anything – always reach out to us!


    Great blog post by the way 🙂 Thanks!

    (0) 
  3. Jonathan Groll

    We have also developed and deployed a meter reading application in UI5, and are busy admiring the appearance of the anyline SDK.

    This is what our entry field looks like:

    meter reading entry.jpg

    I do have some questions regarding the anyline meter reading entry:

    1. How accurate is it – in the example, it appears as if the library knew to ignore decimal fragments, so it must somehow have OCR logic that can compensate  for the digits on the far right being a different colour. Will this work for every possible meter type, both water and electricity?

    2. What happens if the face of the meter is covered in mud (as is normally the case for my water meter in winter!) – is there also an option for manual entry?

    (0) 
    1. Ferry Gunawan Post author

      For item 2, yes we can create a manual entry before you submit the meter reading.

      For item 1, I will leave it to Matthias Gasser to answer this.

      May I know which library you are currently using to develop the meter reading? are you also using Anyline?

      (0) 

Leave a Reply