Configuring camera using runonce.sh script - themactep/thingino-firmware GitHub Wiki
This information assumes you have read and comprehend the Updating Firmware wiki page.
Here is an example workflow for updating cameras that are already running Thingino firmware. This process is completed entirely from an SSH connection to the camera. It performs a Full Update. The Full Update removes any configuration and settings that were previously set in your camera. This workflow strives to simplify the process of reconfiguring the camera's settings after a Full Update. The camera can be added to WiFi and reconfigured without using the Web UI. This example is for cameras that do not have internet access, but the same steps can be used whether the cameras have internet access or not.
- A Fat32 SD Card in the camera with a maximum size of 32 GB
- A runonce.sh shell script on the SD Card
The runonce.sh file is the secret ingredient of this workflow. This file adds the camera to WiFi and configures the camera settings.
Here is an example of a runonce.sh
wlan configure MyWiFiSSID MyWiFiPassword
echo '{"stream0":{"fps": 15, "gop": 15},"stream1":{"fps": 5, "gop": 5}}' > /tmp/myprudynt.json
echo '{"motors":{"pos_0": "830,160"}}' > /tmp/mymotors.json
echo '{"webui":{"paranoid": true}}' > /tmp/mythingino.json
jct /etc/prudynt.json import /tmp/myprudynt.json
jct /etc/motors.json import /tmp/mymotors.json
jct /etc/thingino.json import /tmp/mythingino.json
tzselect -n Chicago
reboot
What exactly is this doing? The configuration files on the camera are stored as .json files, typically in the /etc directory. Thingino's built in jct import command is being utilized to update the .json configuration files.
- The wlan configure line sets the WiFi SSID and password. Replace MyWiFiSSID and MyWiFiPassword with your specific WiFi values. Match the case exactly for both SSID and Password.
- The lines staring with
echoare building temporary .json files in the camera's /tmp directory. These temporary .json files contain the desired settings for the camera. - The temporary .json files are then imported and merged into the camera's respective configuration files with the jct import command.
- The time zone on the camera is set.
- The camera is rebooted. This is optional, but may ensure the time zone is applied properly.
To investigate camera settings that can be configured, use the jct print command. For example, to print the prudynt.json file use the following command
jct /etc/prudynt.json print
Check out the full jct capabilities in the jct repo. The export function could be useful for listing out the settings that have been customized. This would be a great starting point for values to include in the ruonce.sh.
-
Build updated firmware or download the latest file from thingino.com. Verify it is the correct file for the target camera hardware.
-
Copy the firmware to the camera through an ssh session. Use scp -O option (upper case oh). scp -O <source> <destination> for example:
scp -O c:\CameraFirmware\firmware_filename.bin root@camera_ip:/tmp/ -
SSH to the camera
ssh root@CameraIPAddress -
Remove the runonce.done file from the SD Card if it exists. This file prevents the runonce.sh from executing on boot. The mount point of the SD Card may vary. If your SD Card is mounted at mmcblk0p1 the file can be removed with:
rm /mnt/mmcblk0p1/runonce.done -
Upgrade the camera from ssh with the firmware file. Use offline mode for sysupgrade (the -x option) if the camera does not have internet.
sysupgrade -x /tmp/<firmware_filename>- The camera will update the firmware and then reboot. runonce.sh will be executed on boot to automatically join the camera to Wi-Fi, and it will also configure the included camera settings. A runonce.done file will be created on the SD Card to prevent runonce.sh from executing on subsequent boots.
-
SSH to the camera to set the root password. you will be prompted to set the root password after logging in for the first time (default password is root).
-
Complete!
In summary:
- Obtain the appropriate firmware file and copy it to the camera
- Ensure that the appropriate runonce.sh exists on the SD Card, and that runonce.done does not exist on the SD Card
- Run sysupgrade -x <filename>
- Set the root password