Polling and keeping devices in sync

I have several plugins where I have implemented the TCPClient() protocol, including the Monoprice Multizone Controller (my foundation for this plugin is the plugin posted around the forum). The polling interval is set to 250. I know this has been asked a few times in both the old and new forums, but I am having trouble understanding exactly how the polling works.

I added a console.log() to the beginning of the onPoll function to see exactly what it is doing, and in most cases, it looks to run around 4 times, then does not run again. So, if I use a physical keypad to turn a zone on, the app is not picking it up, unless I refresh the app or it automatically refreshes itself (which seems to happen periodically if I change windows and go back to it?).

I feel like I have a fundamental misunderstanding of how polling works, or, it is possible that the Monoprice Controller does not report back state changes, so there is nothing for HR to receive.

Either way, this will be problematic if both my wife and I are using the app on our phones, but state changes are not synced. I am considering a couple different options here (which may be way overkill if I am misunderstanding how this is all working):

  1. Put a manual refresh button that will refresh the status of a device. This is not ideal, but I can for sure make this work.
  2. Automatically have the device refresh every XX seconds. This for sure is not ideal for network traffic but, again, would work.
  3. Set up one of my Raspberry Piā€™s as a websocket server connected to the Monoprice Controller. It will poll the Monoprice periodically for changes (every 1 second?) and record them somehow. Then, set up a websocket connection from HR to that websocket server so state changes are announced.

The other devices I have use the HTTPClient() library, which also seem to get out of sync at times, but not as much as my TCPClient() devices.

The PollingInterval is not the rate at which onPoll is called. It is a delay between consecutive calls. This probably should have been named PollingDelay to avoid the confusion. The TCP receive function is a blocking call. On initial connect there are probably quite a few messages coming in which will explain why it is called 4 times. Then after that itā€™ll likely reach a sit & wait situation which is expected. Thereā€™s nothing wrong with that.

I myself actually wrote that Plugin for the Monoprice Multizone controller. Iā€™m guessing you are referring to the one that Iā€™ve linked below. I know @Brian_Laroche has used this plugin for a few of the jobs heā€™s done & I donā€™t think heā€™s experienced this issue yet.
https://groups.google.com/g/thehomeremote/c/ogNGKXmkCSc/m/B_FCUm__AgAJ

Got it, thanks - yes, I read your description about PollingInterval before, so I think Iā€™m tracking that. And if Iā€™m understanding blocking calls correctly, it means that it wonā€™t (canā€™t?) do anything else until it receives a response. (And yes, it is your plugin I have been using.)

I wonder if there is something in my serial port interface that is the problem. I have the Monoprice Controller plugged into one of my Raspberry Piā€™s via serial->USB cable and am using ser2net, so I should dive into that interface to see if it has some sort of timeout or other configuration that is limiting something. I am not at all familiar with serial port connections, so it is quite possible I do not have it set up well. Most of the applications with the Monoprice Controller I saw online were using Node applications, but I was trying to avoid that if possible.

Is it possible / common that devices do not always announce state changes? Or is it more common that they do? Iā€™m assuming for a device that does not announce state changes, manual polling or a refresh button are the only solution.

On a separate but related note, I also believe that I cannot connect multiple devices to the same port at the same time to talk to the Monoprice Controller, so I still need to solve that issue - if I have the simulator open and then open the app on my phone, usually my phone will not connect, unless I disconnect the simulator first.

The fact that your set up only supports 1 connection at a time is going to be a problem. I think you need to get that fixed. I wouldnā€™t be surprised if thatā€™s causing these sync issues you are experiencing. You could have 2 apps fighting against each other for access to the connection. Iā€™m pretty sure Brian used a Global Cache iTach if I remember correctly. That supports 8 simultaneous connections. Research what you buy. There are going to be several options out there that only support 1 connection. Even the early Global Cache products like the GC-100 only supported 1 connection. Newer ones like iTach, Flex, & Global Connect all support multiple simultaneous connections.

https://www.globalcache.com/products/itach/ip2slspecs/

Well sure enough, that looks to be the ticket.

For those coming here in the future who use ser2net, there is a parameter with ser2net called ā€˜max-connectionsā€™ that defaults to 1. When I increased that, it works perfectly well now. Anything I do on my phone shows up near instantly on the simulator, and vice versa.

It does not sync physical button pushes on the keypad, but I am guessing that is because the Monoprice does not send those changes over the socket. So I probably just need to uninstall the physical keypads! (or set up a refresh interval)

For reference, my setup is:
Monoprice Controller -> USB to Serial Cable (PL2303 chipset) -> Raspberry Pi set up with ser2net -> ser2net broadcasts on the port I select

1 Like

Just want to chime in to confirm everything Bill already said. Iā€™m using the Global Cache iTach RS232 which allows for 8 simultaneous connections. Commands sent to the matrix via keypad can be picked up during the next pole. Iā€™ve installed 5 or 6 of these systems now and while there has been a few tweaks and improvements along the way - itā€™s a very solid integration and an affordable choice.

Good insights - thank you.

To clarify - are you saying that a physical keypad command will only be synced the next time something triggers a TCPClient poll? Or that a physical keypad command will automatically come down on the socket? Neither is happening for me, and I may need to dig into why that is in my setup.

A physical keypad entry will register with the matrix immediately - but THR is only going to pick up that new value the next time it poles the matrix.

Got it, ok. Iā€™ll have to earmark the Global Cache devices for a future project. They sound interesting.

Iā€™m kind of with @amingle. Iā€™m not sure they will be picked up. You probably have to resend the same status request commands that are in the ā€œconnectā€ method. They will likely be picked up eventually when something else changes in the system.

I know for a lot of systems like these changes made with physical keypads are not automatically broadcast as events. Maybe there was a setting in their software we had to enable. I donā€™t remember exactly.

Ok, then I feel less crazy. I just looked through the manual again (such as it is), and Iā€™m not seeing anything that leads me to believe the keypads will broadcast events. Honestly, the simplest thing for me is to take the keypads out so the family just uses HR. (Means I will have some drywall work to doā€¦)

All of my TCPClient-connected devices are syncing well across multiple Home Remote devices (for instance, my and my wifeā€™s phones). But I still do not have a good solution for syncing my Roku TV, because it is an HTTPClient device. Events, including power on, do not appear to be broadcast. Surely there has to be a better solution than just polling for power state every 1 second.

For the LG TV integration I did earlier this year, I used SSDP ā€œaliveā€ & ā€œbyebyeā€ events to monitor power state. Once I develop an official Roku integration, I plan on doing the same. Itā€™s not possible to listen to those events with Plugins. There are certain limitations.

If youā€™ve already gone through the trouble of getting the CAT wire run and keypads installed - I wouldnā€™t go through further trouble to remove everything IMO. I do have installations who use both: Keypads & THR - and can honestly say itā€™s never been an issue with displaying accurate values. Volume adjustments are probably infrequent enough and since THR polls each time it launches or refreshes that particular page - itā€™s always been a non-issue. Your use-case may be such that you do end up removing them.

Personally I designed a mount for them which consumes 3U of rack space, so I put all 6 room controllers there since they come with the unit and Iā€™d feel silly throwing them away. The designers I work with say they are too ugly to let me put them in the rooms most of the time :frowning:
If you have extra rack-space that could be an option for you.

image

This is out of my current skillset, but thatā€™s now become my task for tonight - see what I can learn about SSDP. Is there somewhere I can see the backend code in how you implemented it to take a shot at it?

Ha thatā€™s fair. I like your rack layout. That looks nice. Being that my wife is the ā€œdesigner I work withā€, theyā€™ll probably end up going. But great idea to move them downstairs to the rack.

Bonus points for removing the keypads and converting the CAT cables in your walls into recessed iPads utilizing the CAT wire for POE->USB to keep them powered. Currently my favorite tech addition to a room.

If you end up needing the rack-mount let me know. It was designed in fusion360 and I 3D print mine in PETG and assemble with some superglue on the back side.

Thatā€™s a fascinating concept - never even thought about POE USB chargers.

Appreciate all the insights and ideas. Itā€™s great to see all the creativity.

Brian,
Would you mind if you post your 3D print mount here or email me?

Bill,
I can make a refresh button to capture the change form the monoprice multizone amp.
how do i make auto refresh in every minute or so?
I tried to use Event trigger, but no sucssess.
I believe that itā€™s very simple thing with script, but just donā€™t knowā€¦

thank you

The preferred spot would be inside the plugin. You can add your refresh commands to the ā€œonPollā€ function of the plugin. The EventTrigger is for handling Button clicks, etc. Not for handling automated polling.