This is the code (below) I use on my UI5 from a few years ago. Essentially I made a sloppy way to collect the JSON from the webcam, break it up and then re-compile it back again to enable/disable the motion.

The problem I found was that the CGI/JSON has to be downloaded in full only because you have to send the whole lot back again. Even though you only want to change one thing, being the motion trigger!

I'm sure that someone with some proper JSON coding could clear all of this up. It's worked flawlessly on my Foscam cameras (FI9826W) for years