Set function from API does not work

Forum for questions and support relating to the 1.28.x releases only.
marcolino7
Posts: 73
Joined: Wed Sep 16, 2015 12:20 pm

Set function from API does not work

Post by marcolino7 »

Hi,
I have Zoneminder 1.28.100, and I have installed the API to remote control ZM function from an home automation software.

I use this command to switch from Modect to Monitor:

Code: Select all

curl -XPOST htetp://zoneminder/zm/api/monitors/1.json -d "Monitor[Function]=Monitor"
On ZoneMinder web interface, I can see that Function is switched to Monitor, but motion detection continue to operate and record video when motion is detected.
Only way to have it back to monitor is from web interface to set in Modect and then back to Monitor. In this way, motion detection really stop.

Any hekp would be appreciated.

Regards
Marco
Production Zoneminder 1.31.4 Ubuntu 16.04 LTS on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Set function from API does not work

Post by asker »

The Controller for this is MonitorsController.php inside the API directory. If I recall correctly, the monitor is not restarted when you edit the mode.
Take a look at daemonControl inside that file - you will probably need to restart that monitor. Once you test and have it working, consider doing a pull request. If everything works, it would probably be one line addition at the edit function there.

marcolino7 wrote:Hi,
I have Zoneminder 1.28.100, and I have installed the API to remote control ZM function from an home automation software.

I use this command to switch from Modect to Monitor:

Code: Select all

curl -XPOST htetp://zoneminder/zm/api/monitors/1.json -d "Monitor[Function]=Monitor"
On ZoneMinder web interface, I can see that Function is switched to Monitor, but motion detection continue to operate and record video when motion is detected.
Only way to have it back to monitor is from web interface to set in Modect and then back to Monitor. In this way, motion detection really stop.

Any hekp would be appreciated.

Regards
Marco
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
marcolino7
Posts: 73
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 »

asker wrote:The Controller for this is MonitorsController.php inside the API directory. If I recall correctly, the monitor is not restarted when you edit the mode.
Take a look at daemonControl inside that file - you will probably need to restart that monitor. Once you test and have it working, consider doing a pull request. If everything works, it would probably be one line addition at the edit function there.
Thanks for answer.
I'm not a developer so I need more help to find and troubleshoot. I found file MonitorsController.php, but I cannot find nothing regarding daemonControl. Here is the contenent of my file:

Code: Select all

<?php
App::uses('AppController', 'Controller');
/**
 * Monitors Controller
 *
 * @property Monitor $Monitor
 * @property PaginatorComponent $Paginator
 */
class MonitorsController extends AppController {


/**
 * Components
 *
 * @var array
 */
	public $components = array('Paginator', 'RequestHandler');

/**
 * index method
 *
 * @return void
 */
	public function index() {
                $this->Monitor->recursive = 0;
        	$monitors = $this->Monitor->find('all');
        	$this->set(array(
        	    'monitors' => $monitors,
        	    '_serialize' => array('monitors')
        	));
	}

/**
 * view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function view($id = null) {
		$this->Monitor->recursive = 0;
		if (!$this->Monitor->exists($id)) {
			throw new NotFoundException(__('Invalid monitor'));
		}
		$options = array('conditions' => array('Monitor.' . $this->Monitor->primaryKey => $id));
		$monitor = $this->Monitor->find('first', $options);
		$this->set(array(
			'monitor' => $monitor,
			'_serialize' => array('monitor')
		));
	}

/**
 * add method
 *
 * @return void
 */
	public function add() {
		if ($this->request->is('post')) {
			$this->Monitor->create();
			if ($this->Monitor->save($this->request->data)) {
				return $this->flash(__('The monitor has been saved.'), array('action' => 'index'));
			}
		}
	}

/**
 * edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function edit($id = null) {
		$this->Monitor->id = $id;

		if (!$this->Monitor->exists($id)) {
			throw new NotFoundException(__('Invalid monitor'));
		}

		if ($this->Monitor->save($this->request->data)) {
			$message = 'Saved';
		} else {
			$message = 'Error';
		}

		$this->set(array(
			'message' => $message,
			'_serialize' => array('message')
		));
	}

/**
 * delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function delete($id = null) {
		$this->Monitor->id = $id;
		if (!$this->Monitor->exists()) {
			throw new NotFoundException(__('Invalid monitor'));
		}
		$this->request->allowMethod('post', 'delete');
		if ($this->Monitor->delete()) {
			return $this->flash(__('The monitor has been deleted.'), array('action' => 'index'));
		} else {
			return $this->flash(__('The monitor could not be deleted. Please, try again.'), array('action' => 'index'));
		}
	}}
Production Zoneminder 1.31.4 Ubuntu 16.04 LTS on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Set function from API does not work

Post by asker »

Looks like you are running an old version of the APIs.
There are two ways to handle this:

1) Stick with the current version you have and restart ZM after you change monitor mode from your side. I think the API for that is

Code: Select all

http://zoneminder/zm/api/states/change/restart.json
Try it from command line first to see if it works. If not you need to update your ZM

2) Update your ZM to make sure you have the latest APIs (this is not a stable release). https://github.com/pliablepixels/zmNinj ... r-with-API
Then, open up Monitors.php and in the edit function, right after this line https://github.com/ZoneMinder/ZoneMinde ... er.php#L75
try adding a daemonControl restart (look at the code in other parts to figure out the command)

I'm not 100% it will work - but you need to tinker to get 2) working if the suggestion above doesn't work.
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
marcolino7
Posts: 73
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 »

Hi asker,
i tried to install a new server with latest version of the ZM and API using instruction on link you sent, but i did it on Debian not on Ubuntu, and I'm stuck, because ZM does not start, and I'm not able to go forward on this. If you are able to help me, I can try to go ahead on this installation.

Meanwhile, I'll try step 1) on my actual server.
Regards

Marco
Production Zoneminder 1.31.4 Ubuntu 16.04 LTS on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Set function from API does not work

Post by asker »

Hi Marco,
I don't believe Debian has a distribution that automatically installs the API correctly. You can compile from source, but I won't be able to guide you since I don't use Debian

Hope 1) works for you.
marcolino7 wrote:Hi asker,
i tried to install a new server with latest version of the ZM and API using instruction on link you sent, but i did it on Debian not on Ubuntu, and I'm stuck, because ZM does not start, and I'm not able to go forward on this. If you are able to help me, I can try to go ahead on this installation.

Meanwhile, I'll try step 1) on my actual server.
Regards

Marco
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
bbunge
Posts: 2934
Joined: Mon Mar 26, 2012 11:40 am
Location: Pennsylvania

Re: Set function from API does not work

Post by bbunge »

I'll fire up my Debian test bed and give it a try..

bb
marcolino7
Posts: 73
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 »

Hi,
I installed an Ubuntu 15.04 Server. I followed step to install zoneminder with api from GitHub. When i fire this command:

systemctl restart zoneminder

I got this error:

Job for zoneminder.service failed. See "systemctl status zoneminder.service" and "journalctl -xe" for details.
Production Zoneminder 1.31.4 Ubuntu 16.04 LTS on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration
marcolino7
Posts: 73
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 »

Running

Code: Select all

systemctl status zoneminder.service
I got this:

Code: Select all

â zoneminder.service - ZoneMinder CCTV recording and surveillance system
   Loaded: loaded (/lib/systemd/system/zoneminder.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Thu 2015-09-17 10:33:55 CEST; 3h 44min ago
  Process: 10173 ExecStart=/usr/bin/zmpkg.pl start (code=exited, status=255)

Sep 17 10:33:55 zoneminder zmpkg.pl[10173]: Can't connect to db at /usr/share/perl5/ZoneMinder/Config.pm line 105.
Sep 17 10:33:55 zoneminder zmpkg.pl[10173]: BEGIN failed--compilation aborted at /usr/share/perl5/ZoneMinder/Config.pm line 105.
Sep 17 10:33:55 zoneminder zmpkg.pl[10173]: Compilation failed in require at /usr/share/perl5/ZoneMinder.pm line 33.
Sep 17 10:33:55 zoneminder zmpkg.pl[10173]: BEGIN failed--compilation aborted at /usr/share/perl5/ZoneMinder.pm line 33.
Sep 17 10:33:55 zoneminder zmpkg.pl[10173]: Compilation failed in require at /usr/bin/zmpkg.pl line 48.
Sep 17 10:33:55 zoneminder zmpkg.pl[10173]: BEGIN failed--compilation aborted at /usr/bin/zmpkg.pl line 48.
Sep 17 10:33:55 zoneminder systemd[1]: zoneminder.service: control process exited, code=exited status=255
Sep 17 10:33:55 zoneminder systemd[1]: Failed to start ZoneMinder CCTV recording and surveillance system.
Sep 17 10:33:55 zoneminder systemd[1]: Unit zoneminder.service entered failed state.
Sep 17 10:33:55 zoneminder systemd[1]: zoneminder.service failed.
it seems there is some issue with database
Production Zoneminder 1.31.4 Ubuntu 16.04 LTS on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration
marcolino7
Posts: 73
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 »

Hi,
It seems that the installation of ZM have not created the database inside mysql:

Code: Select all

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
Can anyone help me?

Regards
Production Zoneminder 1.31.4 Ubuntu 16.04 LTS on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Set function from API does not work

Post by asker »

Hi,
bbunge posted instructions on how to install zoneminder-master for ubuntu for both 14.x and 15.x
Please see here
http://www.zoneminder.com/forums/viewto ... 32&t=23375
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
bbunge
Posts: 2934
Joined: Mon Mar 26, 2012 11:40 am
Location: Pennsylvania

Re: Set function from API does not work

Post by bbunge »

I was not able to get Debian working with the API's. So, I set up Ubuntu 15.04 and "learned" how to configure ZM API's from the master PPA. Just got the API to work. Next to reload 15.04 so I can write down what I did then try Debian again. Should have results sometime tomorrow. Need to sleep on a couple of things and finish reloading Win 10 on my laptop. At least my Asus router is working well (60 days up time!).

bb
marcolino7
Posts: 73
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 »

Hi,
I followed tutorial by bbunge, and now ZoneMinder start and it work. But calling the API test Page, I get this:


Not Found
The requested URL /zm/api/host/getVersion.json was not found on this server.
Apache/2.4.10 (Ubuntu) Server at 192.168.1.224 Port 80

Thanks
Production Zoneminder 1.31.4 Ubuntu 16.04 LTS on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration
bbunge
Posts: 2934
Joined: Mon Mar 26, 2012 11:40 am
Location: Pennsylvania

Re: Set function from API does not work

Post by bbunge »

I got the API to work on Debian 8.2. Write up to follow.

bb
marcolino7
Posts: 73
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 »

bbunge wrote:I got the API to work on Debian 8.2. Write up to follow.

bb
Hi bbunge,
do you provide a step to step guide? Ubuntu is too heavy for my virtual enviroment, Devian is lighter.
Many Thanks
Production Zoneminder 1.31.4 Ubuntu 16.04 LTS on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration
Locked