2019 Motion Fix for Deamon (Permission denied) and proper install

If you ever had encounter error writing to a permanent mounted drive for motion running as deamon, please consider to check the following.


  1. Mount Point
    1. I could not figure it out, but motion, ran as deamon, will not write to devices mounted in /media/<$USER>/. Point your mountpoint to /mnt.
  2. Folder owner and permission
    1. change the owner of the folder where motion.conf is pointing to (target_dir)
      1. sudo chown motion:adm
    2. change the permission
      1. sudo chmod 0775
  3. File system type (not required)
    1. I discovered mounting removable media as EXT4 is more convinient when mounting it permanent trough /etc/fstab
Following is an example of mounting disk to your system and configure motion, almost problem free. assume that your mounting point is /mnt/seagate

Installing file system drivers NTFS and Fat32, if needed
sudo apt-get update

File system
command
NTFS
sudo apt-get install ntfs-3g
ExFAT, FAT, FAT32
sudo apt-get install exfat-fuse

Create the mounting folder
           sudo mkdir /mnt/Seagate
sudo chown -R desireuser:desiregroup /mnt/seagate
           sudo chmod 0777 /mnt/seagate

Disk (permanent mount)
Make a backup of /etc/fstab
            sudo cp /etc/fstab /etc/fstab.bck
Get the UUID of the disk partition, for example /dev/sda1
sudo blkid
Optput
/dev/mmcblk0p7: LABEL="root" UUID="b53d31e9-e8de-4074-8c6c-deafe8bb7155" TYPE="ext4" PARTUUID="0007c09c-07"
/dev/sda1: LABEL="Mem32" UUID="401e0caf-8633-4f7f-92d7-fdfef3478b2e" TYPE="ext4" PARTUUID="01f27d07-01"
Append the permanent mountpoint in /etc/fstab with following code:
Ext 4 > echo "UUID=401e0caf-8633-4f7f-92d7-fdfef3478b2e /mnt/Seagate nodelalloc ext4 defaults 0 0" | sudo tee -a /etc/fstab
NTFS > echo "UUID=401e0caf-8633-4f7f-92d7-fdfef3478b2e /mnt/Seagate ntfs-3g defaults,permissions 0 0" | sudo tee -a /etc/fstab
Samba Shares echo “//server/share  /mnt/Seagate cifs  user=user 0  0" | sudo tee -a /etc/fstab 

·         defaults - default mount settings (equivalent to rw,suid,dev,exec,auto,nouser,async).
·         In some cases, NTFS partition owner and group may be set by defining the option uid and gid.
·         Permissions are also defined at the time of mounting the partition with umask, dmask, and fmask and can not be changed with commands such as chown or chmod.
·      For mounting samba shares you can specify a username and password, or better a credentials file.To use a credentials you have to create the credential file with the following codes. (replace user and password with yours)
echo " username=user
password=password" | sudo tee -a /etc/samba/credentials
sudo chown root.root /etc/samba/credentials && sudo chmod 400 /etc/samba/credentials
Then modify the /etc/fstab by replacing "user=user" with "credentials=/etc/samba/credentials"
User could be guest or username=yourusername,password=yourpassword
Mount the partition
sudo mount -a

Motion Setup

For best result your host machine should have a static IP for the live streaming

Make sure that the camera is correctly detected.
You should see the name of your camera when you run the command below. If it is NOT there, then there is some problem with camera or the camera is not supported in motion.
lsusb
Install Motion
sudo apt install -y motion libio-socket-ssl-perl libnet-ssleay-perl perl
Configure Motion
           sudo cp /etc/motion/motion.conf /etc/motion/motion.conf.bck
sudo nano /etc/motion/motion.conf
# Daemon
daemon off                             > on
# Capture device options
Width 320                                > 640 (optional)
height to 240                           > 480 (optional)
framerate 2                             > 12 - 24
# Motion Detection Settings:
post_capture 0                        > 5
event_gap 60                          > 15 - 60
# Image File Output
quality 75                                 > 100 (optional)
# Target Directories and filenames For Images And Films
target_dir /var/lib/motion         target_dir /mnt/Seagate/motion
# Live Stream Server
Stream_quality 50                   > 100 (optional)
Stream_localhost on               > off
# HTTP Based Control
Webcontrol_localhost on        > off
Exit Nano and save settings.
Configure Motion Daemon
sudo cp  /etc/default/motion  /etc/default/motion.bck
            sudo nano /etc/default/motion
                        start_motion_daemon=no              > yes
Exit Nano and save settings.
Start Motion daemon
            sudo systemctl enable motion
            sudo systemctl restart motion


2019 VBA reference - equivalents for Autoit, C++ and Java function and keywords

Author: Jeffrey Paesch

This page is started on March 10, 2019. The idea is to provide techniques, function to equivalents well know programming language functions and or statements.
You will enjoy this page, especially if you are the guy that translate code to another code Language,

==========================================================
Return x 
Description: exit function and return a value (java, autoit, and more)
Solution:  functionname = x: exit function (on the same line)
Example:
.    function (arg1,....)
.        if arg1 = "" then myfunction = -1: exit function
.        .......
.        ....
.    end function
==========================================================
void mysub( const int i );.
Description: passing const variable (as of C++) to VBA function. Link with detailed description
Solution: create a local (scope) variable within your function and capture the function byref variables
Example:
.    function (arg1,const_arg1 as integer, const_arg2 as boolean)
.        Dim arg1as integer, arg2 as boolean
.        arg1 = const_arg1,
.        arg2 = const_arg2
.        ' work from here with the local variables arg1 and arg2,
.        .......
.        ....
.    end function
==========================================================
more to come


2019 VBA Clear Inmmediate window


Author Jeffrey Paesch

There are many post about clearing the immediate window. However none of them seems to work or at least work as I expected. For instance many of the pages suggest flush the immediate. To flush your immediate window in VBA you can use the following sub.

Sub VBE_immediate_flush()
    Debug.Print String(100, vbCr)
End Sub

When it comes to clear your window, the following statement  will help you:
Application.SendKeys "^g ^a {bs}".
However, the above statement has limitation, It can not be run while you are running your codes. Immediate windows can be cleared only in the reset (stop) mode.
Pasting the above statement at the beginning of your statements will not have a desirable result. Your immediate window will remain empty, although you unfocused the immediate window with "Doevents" or Application.SendKeys "{F7}" statement.
Therefore, the best solution to cleare the immediate window is with the following sub:

Sub VBE_immediate_clear()
    get_win = Application.VBE.ActiveWindow.Caption
    cmpnts1 = Mid(get_win, 1, InStr(get_win, "(") - 2)
    Application.SendKeys "^g ^a {bs}"
    Stop
    Application.SendKeys "{F7}"
    Set Application.VBE.ActiveCodePane = _
    ThisWorkbook.VBProject.VBComponents(cmpnts1).CodeModule.CodePane
End Sub

Cons
This sub enter the reset (stop) mode in order to give the immediate windows to clear.

pros
it clear the immediate windows for real
The sub can be call at the beginning of your statements.
The sub will later activate and focus the captured VBE window after the immediate cleaning.


Conclusion
I hope this code will save you lot of headache on research