I am working on a web app that reads electric meters, logs the data and sends reports to users’ browsers. I have been requested to add a real time feature that would read the meter every second and stream the data to the session requesting it and display it in a listbox. Can Xojo do this?
How about using a timer and updating the recently acquired data?
web api 1 or 2? api 2 have nice WebChart btw.
To answer your initial question - yes, absolutely, a collection of XOJO-made apps can accomplish everything. I’d be careful about the once-a-second expectation however. If this is on a managed intranet where the sensors and the end-user app(s) are all collocated then you can likely count on higher throughput. Naturally you’ll have to balance things based on the number of meters, the number of parameters each meter is logging… but that’d be a constraint no matter what platform you develop on I suppose.
This will be an API 2 app and most likely running on a LAN with only one meter data showing at a time. My question should have been How would I do it? Not can it be done. It looks like updating the webpage every time a new reading comes in then calling Listbox.UpdateBrowser might work.
Hi Dean - love to help! To start with, how will the data be getting “out” of the meter? Does the meter “push” data out (to a dbase of some kind) or do you pull it out of the meter with calls to an onboard web services api built into the meter itself?
Xojo can’t really make streaming due to its single thread limitations, fortunatelly for you, sending a mesage each second is not streaming.
How to do it? There is an example in Xojo called PushExample
A web app running on a Raspberry Pi mounted in the same enclosure with the meters polls the meters and writes the data to a Postgres db. It also syncs that data with either our cloud server or a third party building management system. Another web app connects to the db and allows users to configure the system and get reports. Readings are normally stored every 15 minutes so I am thinking I will use a TCPSocket to send real-time readings to the rPi’s web server which would then update the browser with the new data as it comes in. The TCPSocket is now used to request non-scheduled meter readings and allow a user to tell the ReadSync program to reset itself because the system configuration has changed.
I’m inclined to agree with @Ivan_Tellez and looking into the PushExample, it gives some ideas on how to real-time disseminate info to multiple sessions. What’s interesting about this example (to me) is that the update timing is based on how often messages are pushed, and don’t rely on polling as much.