Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


Recommended Posts

Posted (edited)

Who has ever faced the situation of needing to view the HC3 console from a remote part of the home? For example, to see a value when a sensor is triggered by hand or to monitor a response from a QuickApp. Carrying a laptop around the house is not convenient and there's no console view in the Yubii app. So, the only solution is to equip the QuickApp with its own messaging system that can be viewed on a phone.

 

Or… use the one central Virtual Console (OCVC).

 

The idea is simple: The user installs a QuickApp that can be downloaded below.

it's necessary to uncheck in this QuickApp: Advanced->Use the new views in mobile application. 
This QuickApp can then be added to ‘Favourites’ in the Yubii app. It acts as a console, implemented through the QA interface. It listens to messages from other QuickApps - as many as you want - and displays any message they send.

In the QuickApp from which we want to send messages to the console, we simply paste the following small code:

Please login or register to see this code.

And you can use it similar way as print:

Please login or register to see this code.

Each displayed message is preceded by the vprint-ing QuickApp ID and the first 6 characters of its name, so you always know where the message comes from. It works also out of home, within LTE range of course. 

If a few people find this useful, I’ll continue developing it further. There’s plenty of room for improvement - such as a longer message queue with scroll support (page up/down), filtering by QuickApp ID tag, and more.

Please login or register to see this attachment.

Edited by Łukasz997
Posted (edited)

Some friendly feedback...

1. Is "@)^&<?)93#" the magic key that tells you that its a VC event? I would have thought I was hacked if I saw events like that in my log (customEvents usually have descriptive names) :-) 

2. How long messages can you have? It's a name property of the customEvent structure, so I'm unsure. I see you hex code it (makes it longer) to only have valid characters (no space or other strange chars allowed).

3. Have you considered using a known fibaro global variable instead and just json.encode the structure into it, and pick up the GlobalVariableChangedEvent? The event contains the new value. It seems cleaner, even if a global var needs to be created.

4. There is a global lua variable 'quickApp' defined after exiting :onInit(). recommend to recommend to do quickApp=self in onInit instead of polluting with another variable QA
5. It needs the old view in mobile app due to the html table labels.  Could it be done without?

6. You use messg.type = self.id, that only works inside the QuickApp method. Use  messg.type  = plugin.mainDeviceId instead. It's defined as a global lua variable as soon as the code is entered (even before :onInit())

 

It's a bit strange that we don't have the Notification Center in the mobile app. I guess this is kind of what it was intended for. 

So this apps seems to fill a need. 

Edited by jgab
Posted (edited)

Another approach would be to let the user just print the message to the console
Ex.

Please login or register to see this code.

The user becomes responsible for formatting the message (incl colors) the way he wants.

One then intercepts the print function

Please login or register to see this code.

What one sends to VC one would probably also like to log to the console...

Edited by jgab
  • Topic Author
  • Posted

    Thank you for the remarks. I will try to answer.

     

    1 godzinę temu, jgab napisał:

    1. Is "@)^&<?)93#" the magic key that tells you that its a VC event? I would have thought I was hacked if I saw events like that in my log (customEvents usually have descriptive names) :-) 

    Yes, it's a "token" ensuring to process only qualified events - top secret, unbreakable, enormously sophisticated :). However you should not see it in logs, because it's hex encoded before emitting the event, decoded just in OCVC. If, according to your suggestion, a global variable were used instead, the token would no longer be necessary.

     

    1 godzinę temu, jgab napisał:

    2. How long messages can you have? It's a name property of the customEvent structure, so I'm unsure. I see you hex code it (makes it longer) to only have valid characters (no space or other strange chars allowed).

    I don't know, how long it can be - as long as emitted string (as usual, no documentation). There's no "cut to size" safeguard, because I want to keep the vprint as small as possible. First version of OCVC used base64 encode, which makes the string ~⅓ shorter. But it complicates vprint, so I dropped it. Interestingly, emitCustomEvent can't manage base64! No error, but no event. Some characters (probably +/=) are likely the issue, though they can be removed from Base64. Converting to hex resolves problem and it's simple at the cost of increased message size.

     

    1 godzinę temu, jgab napisał:

    3. Have you considered using a known fibaro global variable instead and just json.encode the structure into it, and pick up the GlobalVariableChangedEvent? ...

    I was so excited discovering the custom events that I didn't even think about it. I want just put CE to work! (and make OCVC "transparent"). Global variable is good: no need to have "token", no encoding, just pure json.
    But... I will leave it as is :)

     

    Points 4 & 6: I didn't know it. Of course it's better as you propose.

     

    2 godziny temu, jgab napisał:

    5. It needs the old view in mobile app due to the html table labels.  Could it be done without?

    Both we know that it can be done without html, but it need to build a message system from scratch, with many limitations: no color, no align, no fonts (or at least I don't know how to do it).

    I have my own ready solution - a library to manage html tables, with many advanced functions (row-level cache, inserting, deleting rows, color managing, linking table fields, static fields, filtering...). OCVC message engine is ultra-light version of this lib. 

    Posted

    Maybe provide a client lua file people can add into their QAs with the QuickApp:vprint defined for ease of use?

  • Topic Author
  • Posted

    Just a Lua file with the code of vprint? I think you mean something more… I can't quite catch what you exactly have in mind.

    I think the important thing is whether several users find it useful or not - that's the moment when I have a reason to do more.

  • Topic Author
  • Posted (edited)

    It is very easy to enrich vprint with echo to real HC3 console (what probably user needs), preserving message colors:

    Please login or register to see this code.

    No changes in OCVC.

    Edited by Łukasz997
  • Topic Author
  • Posted

    I'm sorry for misleading anyone with vprint function. This from message above is not working. Field plugin._quickApp.name was present only in HC3 emulator, what I didn't checked.

    Proper vprint function is the following (with echo to the console):

    Please login or register to see this code.

     

  • Topic Author
  • Posted (edited)

    Good morning,

    The current version of OCVC can only display a few lines of messages.

    However, a much richer new version is on the way! It can function as a full-featured console for Yubii.

     

    It's very useful when you're away from your computer and need to see the messages.

    Main features:

    - Keeps up to 1000 messages in a buffer (to fit new, oldest messages are deleted when the buffer is full).

    - Allows navigating through messages: Page Up, Page Down, Top, Bottom.

    - Echoes messages to the www console (only when needed, this can be disabled).

    - Provides dynamic filtering of messages by one or more QuickApp ID numbers.

    - Deduplicates consecutive identical messages, showing the number of repetitions and displaying only a single instance.

    - Displays few message statistics.

    Printing from user QuickApp is the same way as before - via new short vprint(...) function, which user have to add to one's QuickApp code.

    I'm testing it now and when I find it has no visible bugs, it will be available to download.

     

    Even with more than 1000 messages, It doesn't consume much of HC3's resources. When no messages are incoming, it remains idle and only listen to an event - everything is event-driven in OCVC. Even under a rapid and continuous stream of messages, the CPU load is not much higher comparing to a simple print(..) operation. This efficiency is achieved thanks to well-designed data structures. When a message incomes, there's not a single iteration or table.insert involved. Deduplication happens on the fly - still no iterations. But when filtering - the loop is necessary, still very fast. Implementing deduplication + filtering was quite a challenge for me (longer thinking & searching than programming).

     

    Here's the screen on Iphone:

    Please login or register to see this attachment.

    Edited by Łukasz997
  • Topic Author
  • Posted (edited)

    After tests, OCVC is free for download. Please test and I will be glad if you share your opinions, observations.

    I put new vprint and OCVC quickapp in next post.

    Here's the interface and features description:

    Please login or register to see this attachment.

    1. Filter Area.

    As messages will appear from various QA's, its ID and shorten name will be shown here. One or multiple QA can be selected and will act as a filter (similar as in www console). Messages only from highlighted QA's will be shown. If no one is selected, all messages are shown (no filter).

     

    2. Controls. 

    ◀️▶️ - cycle left, right through the list (no up, down).

    - toggle filter messages by highlighted QA. 

    - clear all filters (display all messages).

    CLR - after long press it clears all messages from OCVC. 

    🔼/🔽/ - Page up and page down. When long pressed goto top message, goto last messg. No line up/down navigation possible, only by page (can be added later).

    Vrbse (Verbose) - turns on/off visibility of shortened to 8 chars name of the QA in message area.

    ECHO - turns on/off echo of all messages to the console.

     

    3. Status.

    12/12 - current page/total page(s) number. 

    🔼🔽 - if displayed, there's content up or down to the current page. When not displayed you are on the top/bottom of the message list.

    All: 714 - count of all messages. When 🔄 symbol is on, it means the buffer is full and oldest messages will be deleted

    Flt: 252 - count of messages filtered by selected QA(s).

    Dd: 236 - number of messages after deduplication (identical messages in a row will be shown once).

    Today (or date in form 6-Jun) - this is the date of the topmost message on the displayed page.

     

    Remarks:

    The list of QA available to filter by - is completely dynamic: when the buffer is full, the oldest messages disappear. If all messages from certain QA will be deleted, its ID and name will dissapear from the filter area immediately. When possible, the highlighted (cursor) position will be preserved.

    When Echo is enabled, messages printed in the web console are not filtered – every message will be printed, even those which will be filtered out in OCVC message area.

    There are two local variables in this QA: MESSQUEUE_LEN and PAGE_SIZE.

    MESSQUEUE_LEN defines the total buffer capacity. The maximum is 3000 (with no noticeable negative impact on CPU usage), and the minimum is 100. It may even support twice that amount.

    PAGE_SIZE should be set according to the user’s phone screen size; 20 works well on an iPhone Pro. The maximum is 35. If not set, default values are used.

     

    Edited by Łukasz997
  • Topic Author
  • Posted (edited)

    Here's the main OCVC file for download.

    And slightly changed vprint function to print from any QuickApp to OCVC. Two versions at user choice:

    Please login or register to see this code.

     

    vprint receives parameters the same way as print (multiple). Additionally {_color="color_name"} can be specified to print the message in HTML color. color_name must match color names in OCVC source code tab HTMLTablesLC (at top - local HTMLcolors = {...}).

    Please login or register to see this code.

     

    Please login or register to see this attachment.

    Edited by Łukasz997
    Posted

    Please login or register to see this code.

    This little trick don't require the user to set quickApp=self in :onInit...

    • Like 1
  • Topic Author
  • Posted

    Here's download of new version with bug removed: when buffer is full new messages improperly displays on the top of the list. Now new messages are added at the end of message queue.

    By the way, I've noticed interesting property of emitCustomEvent function. Not only does it have extraordinary requirements about characters in the message. Additionally, when we emit same message in the same time (accurate to the one second), second (and more if present) event will be skipped (not emitted):

    Please login or register to see this code.

    Don't be surprised, when dealing with custom event in your app.

    I can fix it in vprint (replacing added to message static "token" with variable one), but it will make this function longer and it's very rare case...

    Please login or register to see this attachment.

  • Topic Author
  • Posted (edited)

    Here' an upgrade of Virtual Console available to download.

    Changes:

    - removed clear all messages

    Added:

    - invert of filter tag selection

    - clear messages by selected filer

    - up/down by one line

    - move selection in filter area up/down by one line

     

    Changed/added buttons:

    ◀️/🔼 - move left, long press move up (next button similar down/right)

    /I - select/deselect QuickApp to enable filtering, long press to invert current selection

    /C - clear all selected QA for filter, long press to clear (delete) all filtered messages. To clear all messages: when none selected use invert to select all, then long press /C

    /T - one page up, long pressed go to first message, next button similar...

    🔼 line - up one line, down one line

    Rest of the buttons works the same as before.

    vprint remains unchanged (it's also listed at the end of "main" tab)

     

    Please login or register to see this attachment.

    Edited by Łukasz997

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Reply to this topic...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...