ZoneMinder API NodeJS Project Help?

Forum for questions and support relating to the 1.32.x releases only.
Post Reply
trillobite
Posts: 8
Joined: Fri Aug 03, 2018 10:36 pm

ZoneMinder API NodeJS Project Help?

Post by trillobite »

Hopefully there is a javaScript developer out there to help out, but I have been attempting to toggle my cameras "mode" between Modect and Mocord.

This project is running in NodeJS, I have successfully been able to change the camera's mode while using postman, however when I try to make the same POST request in NodeJS the new mode doesn't set. I am using "request" to simplify the request. Documentation on that is here: https://github.com/request/request#forms

Here's some code:

Code: Select all

            request.post({
                url: `${zmRoot}/monitors/${camera}.json`, 
                form: {
                    Monitor: {
                        Function: mode, //This holds a string value of either "Modect" or "Mocord."
                    }
                }
            }, (err, httpResponse, body) => {
                if (err) {
                    reject(err);
                } else {
                    resolve(JSON.parse(body));
                }
            });
Here's the response from zoneminder:

Code: Select all

{ message: 'Saved' }
However, whenever I check zoneminder's console, I do not see that any of the modes have changed on any of the cameras.
Last edited by trillobite on Tue Oct 15, 2019 8:21 pm, edited 1 time in total.
trillobite
Posts: 8
Joined: Fri Aug 03, 2018 10:36 pm

Re: ZoneMinder API NodeJS Project Help?

Post by trillobite »

Here is the full project source, pushing my latest copy right now...
https://github.com/trillobite/zmScheduler
trillobite
Posts: 8
Joined: Fri Aug 03, 2018 10:36 pm

Re: ZoneMinder API NodeJS Project Help?

Post by trillobite »

I actually figured out the issue...
Zoneminder counts it's cameras starting with 1,
Node/JavaScript counts it's cameras starting with 0.

My index was off by -1 and it was setting the incorrect camera.

If anyone likes this project let me know, and I may continue to make updates on the side.
User avatar
iconnor
Posts: 2900
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: ZoneMinder API NodeJS Project Help?

Post by iconnor »

Let's be clear, we don't start the Id's at 1. mysql starts any sequence at 1. There can also be gaps.

Isaac
Post Reply