Apr 17, 2014 Replies: 18 This example demonstrates how a Raspberry Pi board can be controlled from the browser. It tracks the switches state and allows the user to turn on and off the 8 leds. The toggle buttons are based on this jQuery plugin: http://simontabor.com/labs/toggles/ The server code is quite simple. All the active connections are stored in a Map. This map is used to notify all connections about the switches events: Code: Copy Sub HandleSwitch(index As Int, State As Boolean) 'notify all active connections about the switch state change. For Each wsm As WebSocketModule In connections.Keys CallSubDelayed3(wsm, "SwitchStateChanged", index, State) Next End Sub The leds are toggled with this code: Code: Copy Public Sub Led_Toggle(Params As Map) Dim id As String = Params.Get("id") 'id will be ledx Dim active As Boolean = Params.Get("active") Main.pface.GetLED(id.SubString(3)).State = active End Sub You should use B4J-Bridge to connect to the Raspberry Pi during development. Note that the www folder is not copied automatically during deployments. You need to copy the files whenever a static file is changed. See this link for more information about jPi4J library: http://www.b4x.com/android/forum/threads/jpi4j-raspberry-pi-gpio-controller.37493/#content Attachments PiFaceServer.zip PiFaceServer.zip 6 KB · Views: 1,821 Click to expand...
This example demonstrates how a Raspberry Pi board can be controlled from the browser. It tracks the switches state and allows the user to turn on and off the 8 leds. The toggle buttons are based on this jQuery plugin: http://simontabor.com/labs/toggles/ The server code is quite simple. All the active connections are stored in a Map. This map is used to notify all connections about the switches events: Code: Copy Sub HandleSwitch(index As Int, State As Boolean) 'notify all active connections about the switch state change. For Each wsm As WebSocketModule In connections.Keys CallSubDelayed3(wsm, "SwitchStateChanged", index, State) Next End Sub The leds are toggled with this code: Code: Copy Public Sub Led_Toggle(Params As Map) Dim id As String = Params.Get("id") 'id will be ledx Dim active As Boolean = Params.Get("active") Main.pface.GetLED(id.SubString(3)).State = active End Sub You should use B4J-Bridge to connect to the Raspberry Pi during development. Note that the www folder is not copied automatically during deployments. You need to copy the files whenever a static file is changed. See this link for more information about jPi4J library: http://www.b4x.com/android/forum/threads/jpi4j-raspberry-pi-gpio-controller.37493/#content
rwblinn Well-Known Member Licensed User Longtime User Apr 23, 2014 #2 Hi Erel, thanks for sharing - very good = tested and works fine. Q: Instead of accessing via a Browser, do you have an example of accessing via clients written in B4A and B4J? Appreciated.
Hi Erel, thanks for sharing - very good = tested and works fine. Q: Instead of accessing via a Browser, do you have an example of accessing via clients written in B4A and B4J? Appreciated.
Erel B4X founder Staff member Licensed User Longtime User Apr 24, 2014 #3 This example is built with the WebApp framework. You can use the new WebSocket client library to create a similar solution with B4A. Another option is to add standard server handlers and communicate with HttpUtils2. Why do you need to create a native solution? This solution is cross platform. You can change the UI to better fit mobile devices if you like.
This example is built with the WebApp framework. You can use the new WebSocket client library to create a similar solution with B4A. Another option is to add standard server handlers and communicate with HttpUtils2. Why do you need to create a native solution? This solution is cross platform. You can change the UI to better fit mobile devices if you like.
M monchanch Member Licensed User Longtime User Dec 7, 2014 #4 When i run the code i get errors. I have attached the error image of the same. What could be the matter?
When i run the code i get errors. I have attached the error image of the same. What could be the matter?
Erel B4X founder Staff member Licensed User Longtime User Dec 7, 2014 #5 Are you running it on a Pi board with PiFace extension?
M monchanch Member Licensed User Longtime User Dec 7, 2014 #6 Hello Erel, I am running it from my laptop. I have connected the b4j bridge between my laptop and raspberry pi. I guess i am missing out some things...PiFace Extension?
Hello Erel, I am running it from my laptop. I have connected the b4j bridge between my laptop and raspberry pi. I guess i am missing out some things...PiFace Extension?
Erel B4X founder Staff member Licensed User Longtime User Dec 7, 2014 #7 You can (and should) run it with B4J-Bridge. However this specific example requires the PiFace extension.
You can (and should) run it with B4J-Bridge. However this specific example requires the PiFace extension.
W wenzelww Member Licensed User Longtime User Jan 11, 2015 #8 Hello Erel, I tried this example but I could not get it to work stable. e.g. I connect with Android Phone and it works, but get the message "No Data available" when I try to access with Laptop. Sometimes it also works with the Laptop. Do you have an idea what could be wrong?
Hello Erel, I tried this example but I could not get it to work stable. e.g. I connect with Android Phone and it works, but get the message "No Data available" when I try to access with Laptop. Sometimes it also works with the Laptop. Do you have an idea what could be wrong?
Erel B4X founder Staff member Licensed User Longtime User Jan 12, 2015 #9 Are you running it on a Pi board with the PiFace extension?
W wenzelww Member Licensed User Longtime User Jan 12, 2015 #10 Yes, Version B with PiFAce. And it works, but not always. Today it does not work at all. I get HTTP Error 404
Yes, Version B with PiFAce. And it works, but not always. Today it does not work at all. I get HTTP Error 404
Erel B4X founder Staff member Licensed User Longtime User Jan 12, 2015 #11 404 means that the page is not found. Are there any error messages in the server logs?
W wenzelww Member Licensed User Longtime User Jan 12, 2015 #12 i think you mean .log files in /home/pi/tempjars/logs there are no error messages in this files.
W wenzelww Member Licensed User Longtime User Jan 12, 2015 #13 after starting the program with B4JBridge, everything works fine, also when i later started the .jar directly. Sorry i have no clue what happened.
after starting the program with B4JBridge, everything works fine, also when i later started the .jar directly. Sorry i have no clue what happened.
W wenzelww Member Licensed User Longtime User Jan 12, 2015 #14 now i have the case that it works over android phone, but get error 404 when I access with laptop in same network (over private IP). The entries in the log file: 192.168.2.105 - - [12/Jan/2015:19:03:08 +0000] "GET /ws HTTP/1.1" 101 - "-" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36" 192.168.2.105 - - [12/Jan/2015:19:03:10 +0000] "GET /favicon.ico HTTP/1.1" 404 289 "-" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36" 192.168.2.105 - - [12/Jan/2015:19:03:28 +0000] "GET /favicon.ico HTTP/1.1" 404 289 "-" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"
now i have the case that it works over android phone, but get error 404 when I access with laptop in same network (over private IP). The entries in the log file: 192.168.2.105 - - [12/Jan/2015:19:03:08 +0000] "GET /ws HTTP/1.1" 101 - "-" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36" 192.168.2.105 - - [12/Jan/2015:19:03:10 +0000] "GET /favicon.ico HTTP/1.1" 404 289 "-" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36" 192.168.2.105 - - [12/Jan/2015:19:03:28 +0000] "GET /favicon.ico HTTP/1.1" 404 289 "-" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"
Erel B4X founder Staff member Licensed User Longtime User Jan 13, 2015 #15 These 404 errors are not important. The browser is making additional calls to get the site icon and these calls fail.
These 404 errors are not important. The browser is making additional calls to get the site icon and these calls fail.
W wenzelww Member Licensed User Longtime User Jan 13, 2015 #16 i have again the same situation: it works over android phone, but get error 404 when I access with laptop in same network (over private IP). This how it looks like: ping to raspberry pi is ok
i have again the same situation: it works over android phone, but get error 404 when I access with laptop in same network (over private IP). This how it looks like: ping to raspberry pi is ok
W wenzelww Member Licensed User Longtime User Jan 18, 2015 #18 meanwhile the problem could be solved. PiFaceSever runs for several days without errors. It was not an issue of the PiFaceSever software, but configuration and powermanagement (sleepmode) of wlan USB stick. Thank's Erel for suppport!
meanwhile the problem could be solved. PiFaceSever runs for several days without errors. It was not an issue of the PiFaceSever software, but configuration and powermanagement (sleepmode) of wlan USB stick. Thank's Erel for suppport!
Mark Turney Active Member Licensed User Longtime User Nov 7, 2015 #19 BTW - this example is demo'd in the 7th B4J video tutorial to be released soon. See the B4J Video Tutorial thread....
BTW - this example is demo'd in the 7th B4J video tutorial to be released soon. See the B4J Video Tutorial thread....