Dec 21, 2015 Replies: 10 Simple solution that uses an embedded MQTT broker with a MQTT client to send the camera output to any connected client. The camera used is the standard RPi camera module. The program starts raspistill if it isn't already running. It configures it to take a shot every second. A timer sends the image every second. Code: Copy Dim shl As Shell shl.Initialize("shl", "raspistill", Array("-o", "temp.jpg", "-t", "0", _ "-tl", "1000", "-w", "640", "-h", "480", "-q", "75")) shl.Run(-1) Code: Copy Sub Timer1_Tick client.Publish2("image", Bit.InputStreamToBytes(File.OpenInput(File.DirApp, "temp.jpg")), 0, False) End Sub Building a client that displays the image is trivial: In this example I've implemented it with B4A. Note that raspistill will be left running if you kill the process. You can kill it with: Code: Copy ps -a |grep raspistill kill <pid> You may need to update raspistill for it to work properly. I've tested it with v1.3.8. Attachments PiCCTV_B4J.zip PiCCTV_B4J.zip 1.1 KB · Views: 1,558 PiCCTV_B4A.zip PiCCTV_B4A.zip 7.7 KB · Views: 1,401 Last edited: Dec 21, 2015 Click to expand...
Simple solution that uses an embedded MQTT broker with a MQTT client to send the camera output to any connected client. The camera used is the standard RPi camera module. The program starts raspistill if it isn't already running. It configures it to take a shot every second. A timer sends the image every second. Code: Copy Dim shl As Shell shl.Initialize("shl", "raspistill", Array("-o", "temp.jpg", "-t", "0", _ "-tl", "1000", "-w", "640", "-h", "480", "-q", "75")) shl.Run(-1) Code: Copy Sub Timer1_Tick client.Publish2("image", Bit.InputStreamToBytes(File.OpenInput(File.DirApp, "temp.jpg")), 0, False) End Sub Building a client that displays the image is trivial: In this example I've implemented it with B4A. Note that raspistill will be left running if you kill the process. You can kill it with: Code: Copy ps -a |grep raspistill kill <pid> You may need to update raspistill for it to work properly. I've tested it with v1.3.8.
derez Expert Licensed User Longtime User Dec 26, 2015 #2 Thank you Erel ! I would like to put the picture taken on an HTML page instead of b4a app. How can I add the image to an index.html file that I have (with radio switches and submit button) , working with Web socket ?
Thank you Erel ! I would like to put the picture taken on an HTML page instead of b4a app. How can I add the image to an index.html file that I have (with radio switches and submit button) , working with Web socket ?
Erel B4X founder Staff member Licensed User Longtime User Dec 27, 2015 #3 You have two options: 1. Implement it with ajax and a regular handler as done here: https://www.b4x.com/android/forum/threads/server-cctv-server.37382/#content 2. Convert the image to base 64 string and create a JavaScript that decodes it and sets the image. This will only work with smaller images.
You have two options: 1. Implement it with ajax and a regular handler as done here: https://www.b4x.com/android/forum/threads/server-cctv-server.37382/#content 2. Convert the image to base 64 string and create a JavaScript that decodes it and sets the image. This will only work with smaller images.
derez Expert Licensed User Longtime User Dec 27, 2015 #4 Moved to a new thread Last edited: Dec 27, 2015
Erel B4X founder Staff member Licensed User Longtime User Dec 27, 2015 #5 @derez please start a new thread for this.
derez Expert Licensed User Longtime User Aug 17, 2016 #6 It is possible to use a webcam instead of the raspberry camera : https://www.raspberrypi.org/documentation/usage/webcams/ I use it with a timer and get a new picture every second or two. The RPi as server can send the picture per requests from users. Code: Copy Sub tmr_tick Log("picture taken " & DateTime.time(DateTime.now)) shl.Initialize("shl", "fswebcam", Array("-r","640x480","--no-banner", "temp.jpg")) shl.Run(-1) End Sub I have found that I need to init the shell every cycle ...(?) Last edited: Aug 17, 2016
It is possible to use a webcam instead of the raspberry camera : https://www.raspberrypi.org/documentation/usage/webcams/ I use it with a timer and get a new picture every second or two. The RPi as server can send the picture per requests from users. Code: Copy Sub tmr_tick Log("picture taken " & DateTime.time(DateTime.now)) shl.Initialize("shl", "fswebcam", Array("-r","640x480","--no-banner", "temp.jpg")) shl.Run(-1) End Sub I have found that I need to init the shell every cycle ...(?)
Erel B4X founder Staff member Licensed User Longtime User Aug 18, 2016 #7 derez said: I have found that I need to init the shell every cycle ...(?) Click to expand... It probably ignores the option to take a screenshot every second.
derez said: I have found that I need to init the shell every cycle ...(?) Click to expand... It probably ignores the option to take a screenshot every second.
R rafie dandamun Member Aug 27, 2017 #8 help.I have this error Waiting for debugger to connect... Program started. Error occurred on line: 35 (Main) java.io.IOException: Cannot run program "ps" (in directory "."): CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048) at java.lang.Runtime.exec(Runtime.java:620) at org.apache.commons.exec.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:61) at org.apache.commons.exec.DefaultExecutor.launch(DefaultExecutor.java:279) at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:336) at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:166) at anywheresoftware.b4j.objects.Shell.RunSynchronous(Shell.java:144) at b4j.example.main._processisrunning(main.java:121) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:614) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93) at anywheresoftware.b4a.BA.raiseEvent(BA.java:77) at b4j.example.main.main(main.java:29) Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessImpl.create(Native Method) at java.lang.ProcessImpl.<init>(ProcessImpl.java:386) at java.lang.ProcessImpl.start(ProcessImpl.java:137) at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029) ... 22 more
help.I have this error Waiting for debugger to connect... Program started. Error occurred on line: 35 (Main) java.io.IOException: Cannot run program "ps" (in directory "."): CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048) at java.lang.Runtime.exec(Runtime.java:620) at org.apache.commons.exec.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:61) at org.apache.commons.exec.DefaultExecutor.launch(DefaultExecutor.java:279) at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:336) at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:166) at anywheresoftware.b4j.objects.Shell.RunSynchronous(Shell.java:144) at b4j.example.main._processisrunning(main.java:121) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:614) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93) at anywheresoftware.b4a.BA.raiseEvent(BA.java:77) at b4j.example.main.main(main.java:29) Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessImpl.create(Native Method) at java.lang.ProcessImpl.<init>(ProcessImpl.java:386) at java.lang.ProcessImpl.start(ProcessImpl.java:137) at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029) ... 22 more
Erel B4X founder Staff member Licensed User Longtime User Aug 28, 2017 #9 Please start a new thread for this and post the relevant code.
Johan Hormaza Well-Known Member Licensed User Longtime User May 8, 2018 #10 Instead of using an RPI, could I use my phone's camera? and how would it be? Thank you .
Erel B4X founder Staff member Licensed User Longtime User May 8, 2018 #11 Yes, but this is not the correct place for this question.