Motion and fswebcam running - input

I am using fswebcam to capture and image, when an email is received. I thought that it would be nice to have Motion running as well. I installed Motion, and that worked fine.
However, when I tried to use fswebcam to take a picture,
I received the error:
Error selecting input 0
VIDIOC_S_INPUT: Device or resource busy
then I stopped Motion, and tried it again. It worked. So, I can only have one program accessing the camera at a time.
Is there any way round this?

Use one or the other, two apps can't read the same video camera device at the same time.
Motion is capable of running a script on event detection, so if you want to do that look in the config for on_area_detected or on_movie_start
Then get it to call some kind of shell script that attaches the current photo and emails it to you.
Hope you don't get too many events, else there will be too many emails to find the important ones.

You can use the Motion HTTP Based Control. Simply call:
http://yourraspberrypi:XXXX/0/action/snapshot
using cURL or any other method that you prefer.
Where yourraspberrypi should be the IP of your Pi, and XXXX should be the port defined under 'control_port', in /etc/motion/motion.conf
Note: A symbolic link called lastsnap.jpg created in the target_dir will always point to the latest snapshot, unless snapshot_filename is exactly 'lastsnap'
You can also use the HTTP Based Control, for example, to stop/start motion detection
More info here: http://www.lavrsen.dk/foswiki/bin/view/Motion/MotionHttpAPI

It worked for me after uninstalling motion. To do so, run the following command from the terminal:
sudo apt-get remove motion

Related

Can I poll my USB HID device without first sending a command

I was able to make a working HID USB stack on my "StartUSB for PIC" board for the 18F2550 microcontroller. I based it on one of the MLA libraries, which was made for the 18F45K50 (MLA 2018_11_26, hid_custom, picdem_fs_usb_k50.x), but I converted it to work with the 18F2550 (there might have been easier ways, but only learned to work with PIC about 1 month ago). On the host side, I'm using LibUsbDotNet (also here, there might be easier ways - the documentation on this library really sucks) on a Windows 10 machine.
I'm using the HID class, full speed, and all seems to work. Although, I get some random errors on the host PC (see below), but doing one close/re-open cycle on the host side when getting the error is kind of solving it. Dirty, but it works. So I kind of ignore this now.
Win32Error:Win32Error:GetOverlappedResult Ep 0x01
995:The I/O operation has been aborted because of either a thread exit or an application request.
I'm not an expert on USB (yet). But all examples I'm seeing are based on 1) you send first a command to the device and 2) then you retrieve the answer from the device. I did some performance tests, and see that this indeed shows that I can do about 500 cycles/second. I think that is correct, because each cycle, sending command and retrieving answer, each takes 1 msec.
But do I really need to send a command? Can't I just keep reading endlessly, and when the device has somthing to say, it does send the data in an IN transaction, and when not it ignores which creates a timeout on the host side. That would mean that I can poll at 1000 cycles/second? Unfortunately, I have tried it by changing my implementation on the PIC, but I get very weird results. I think I have issues with suspend mode. That brings me to another question - how can I make the device get out of suspend mode (means that not the host, but the device should be triggering this event). I have searched the MLA library for command such as "wakeup", "resume", ... but couldn't find anything.
So, to summarize, 2 questions:
Conceptual: Can I send data from device to host without being requested for it by a command from the host?
For PIC experts: How can I have a device trigger for a wakeup from suspend mode?
And indeed, the answer is Yes on the first question.
In the meantime, I found another link on the web that contains a Visual Studio C# implementation of a USB library including all the source files.
If you're interested, this is the link
This C# host implementation works as a charm. Without sending a command to the device, I get notified immediately if a button is pressed. Great!
It also proofs that my earlier device implementation based on the original MicroChip MLA, is 100% correct. I stress tested the implementation by sending a "toggle LED command" as fast as I could, and I reach 1000 commands/second. Again great!
I think that LibUsbDotNet isn't that perfect after all. As I wrote above, I get rather unstable communication (Win32Error). But with this implementation, I don't get a single error, even after running for half an hour # 1000 commands/second.
So for me, case closed.

How to Remove StartStop trait from the device model

complete noob here. I got the assistant sdk running on a rasp pi 3+ (woot!). Everything is running swell, I can trigger some routines configured in my google home app/profile. One of them being to play the "news" / podcasts. While it is playing back though, i cannot get the assistant to stop playback. I try saying "Ok Google, stop" or stop playback and it acknowledges but the podcast keeps playing.
On this site (which I used for the whole setup)
https://developers.google.com/assistant/sdk/guides/library/troubleshooting#podcast_and_news_playback_issues
It says:
Podcast and news playback issues
The Assistant does not follow playback commands (for example, pausing or stopping a podcast).
This is an issue if you have the StartStop or OnOff trait enabled for a given device model. Remove this trait from the device model and playback commands will work.
I hoping this is what I need to do but I don't know how to actually do this. How do I remove the StartStop or OnOff trait?
Any help would be great! Thanks
You can register actions for your device. When setting up your device model, you can configure the types of actions that you want to run. From there, you can disable certain traits like StartStop.

Raspberry camera error: "mmal: No data received from sensor"

I used successfully my raspberry camera times ago.
Now I tried again to acquire a image with the raspistill -o image.jpg command; the red led on the camera flashes, but I get this error:
mmal: No data received from sensor.
Check all connections, including the Sunny one on the camera board
Of course the camera connections are fine. Is there any other way to check if the camera is still working?
This error usually appears because of a faulty connection with the camera.
I had the exact same problem in different camera+Pi configurations. The following case is what I encountered:
The connector is not correctly inserted either in the camera or in the Pi.
The Sunny connector (the small yellow one on the camera) is not connected well.
(now it gets interesting)
If you often remove and reinsert the camera in the Pi please be sure to remove all power from the Pi. The sensor is very sensitive and a spark on the wrong pin could burn it. (I did this already unfortunately)
This could also trigger a problem with the Pi connector pins. It was somewhat confirmed that for Pi2 the connector may have some bad soldering which could lead to cold contact soldering. You can fix this by using some flux on the pins and then pass the soldering iron hot end over the pins to remake the connection.
I used a longer cable that had both connectors on the same side of the cable. If you connect it like it is you can burn your sensor and the Pi will not start because of the power surge (also the camera gets very hot in this case). DO NOT REMOVE IT from the Pi without removing power before. To a cable like this you have to remove the blue plastic from one end and bend the connector with the contacts on the other side. Insert this end in the camera since this will not be removed/inserted as often as the Pi end.
Make sure that the silver contacts are well inserted into the PCB connector.
(video here)
Also, make sure that the sunny connector is firmly attached.
This fixed it for me.
I was experiencing the same problem too, until I found a solution.
I removed the sunny connector(the yellow thingy below the camera in the board) and fixed it in the same place. The camera is working fine after trying this.
I have got the same issue. I have find out it was a power supply issue.
Try to change your cable and/or your raspberry power supply adaptor.
You check if this is your reason of your problem by typing:
$ dmesg
if you see something like this:
[ 44.152029] Under-voltage detected! (0x00050005)
-> Then replace your power supply! :D
The only fix for me was to purchase a new camera.
No real root causes identified.
My problem was I put the camera in, while the Pi was on. which might
have made the camera shot. i.e the camera module is static sensitive
and it's possible that it's been damaged
Unfortunately if this is the case there's nothing you can realistically do to fix it, just get a replacement.
This specific error shows when another application is using the camera. In my case, it was motion.
It might be possible that the cable is placed the wrong way. I had this problem and after multiple tries I realized that was the problem.

Sandbox - killall Operation not permitted

I'm writing a small Mac application (in Obj-C) which runs the following command:
system("killall Finder");
I wanted to see what would happen if I sandbox the app (as sandboxing will be required on June 01), and the app wouldn't work. I got the following response:
killall: warning: kill -TERM 6524: Operation not permitted
Is there any way to get around that? As in a specific entitlement to add or another way to run the command?
Thanks in advance.
Your app completely goes against the spirit of the sandbox, so there's almost no chance that the MAS reviewers will accept it. Also, you may be surprised at what "defaults write com.apple.finder" does from inside your sandbox—basically, nothing useful. You'll have to use a temporary exception entitlement to home-relative /Library/Preferences/com.apple.finder.plist, use some non-sandbox-affected API to get the path to home (e.g., getpwent()->pw_dir), and load and save the plist directly. And then you'll discover that there is no way to call on a non-child process from a sandboxed app, period, no way around it—and if you try to system killall, it ends up running inside the same sandbox as you, and therefore has the same limitations.
However, you asked a specific question as to whether there's a way around that system killall failing, and there are at least three (not counting holes in the sandbox which have either been plugged by 10.7.4 or will surely be plugged soon):
You can create a helper app that isn't sandboxed, that does the killall for you. The only two App Store-approved ways to do this are XPC and SMLoginItemSetEnabled. And you're not allowed to enable the helper without the user explicitly telling you to do so.
You can send Finder an Apple Event asking it to quit, instead of signaling it. The easiest way to do this is to execute the Applescript 'tell app "Finder" to quit'. At least for 10.7.3 and earlier, you'll need a temporary exception entitlement to send Apple Events to com.apple.finder. (There may be different mechanisms for future OS versions, but nobody can discuss them outside the NDA forums.)
You can send an Apple Event to some other process—like System Events—to kill Finder on your behalf.
And so on.
If you have a good reason you can still kill applications like this:
How can I terminate my app in a helper app with sanboxing enabled?

Reading values from a Power Meter via USB

Over the past two days, I am doing some reading on how to get data over USB from an external device which has no device driver installed. I have to read data from a WT500 Yokogawa Power Meter (basically I want to read just one of the parameter that the meter shows, just the power values) over USB. I am aware that a device driver for WT500 is available, but it has some dependencies and I do not want to install a software or change anything majorly in our node to cater to that.
I have found that libusb could be used to perform what I would want, and I have a C program that sniffs the USB device and returns some information. I have looked into usb-robot as well, which also uses libusb. The server node that I am probing has OpenSUSE Linux kernel 2.6.30. I have usbfs mounted.
Question:
I am expecting that using libusb, I would be able to get data dumps from the power meter whenever I request, via usb device. Can I request the meter something like - send 25k of data, and then upon parsing it, I get the parameter value that I am looking for? Considering that I have zero knowledge about the device, can I get some meaningful values out of it? An example code would help.
--
There are some standard messages like ?IDN with which a USBTMC device could be queried. However, specific queries need to be sent to a meter (the syntax should be there in the technical doc/manual/communication interface) if one needs to get whatever is showing up on screen.
I guess there are no easier ways of doing what I want - like just reading a file using something like fread ??
--
Yes, almost. If USBTMC module is installed (the default one in our kernel did not work, detailed explanation of installing and querying a device is here - http://code.google.com/p/scte/wiki/USBTMC), then one just needs to send some queries and read the response via cat or something from the specific files under /dev.
From the meter technical document, I see that the driver communication interface that is described is Windows specific, so I reckon I might need to do some reverse engineering.
--
Yes, but only a tiny bit or may be not at all.
Thank you.
EDIT: After a bit of googling I think I have the answers, I have added them next to the questions I asked.