rwblinn Well-Known Member Licensed User Longtime User Sep 9, 2015 #1 Hi, developed a simple B4J server application (using websockets) to switch, via Browser, a LED connected to the GPIO PIN 1 On/Off. Information in the Browser is updated while blinking... When opening in the Browser, the app is running OK, but when the Browser is refreshed the app crashes: Code: Copy java.lang.RuntimeException: com.pi4j.io.gpio.exception.GpioPinExistsException: This GPIO pin already exists: GPIO 1 Searched several threads and it seems the Pin has to be released by using API method (included in pi4j-core.jar) Code: Copy gpio.shutdown(); gpio.unprovisionPin(pin); This could be accomplished in Websockets_Disconnect. Currently the jPi4J library does not contain such a method. Question: Is there a workaround avialable or would it be possible to include the method unprovisionPin in jPi4J libary? Appreciated Attachments blinkingled.zip blinkingled.zip 10.9 KB · Views: 406
Hi, developed a simple B4J server application (using websockets) to switch, via Browser, a LED connected to the GPIO PIN 1 On/Off. Information in the Browser is updated while blinking... When opening in the Browser, the app is running OK, but when the Browser is refreshed the app crashes: Code: Copy java.lang.RuntimeException: com.pi4j.io.gpio.exception.GpioPinExistsException: This GPIO pin already exists: GPIO 1 Searched several threads and it seems the Pin has to be released by using API method (included in pi4j-core.jar) Code: Copy gpio.shutdown(); gpio.unprovisionPin(pin); This could be accomplished in Websockets_Disconnect. Currently the jPi4J library does not contain such a method. Question: Is there a workaround avialable or would it be possible to include the method unprovisionPin in jPi4J libary? Appreciated
Erel B4X founder Staff member Licensed User Longtime User Sep 9, 2015 #2 Have you tried to call GPIOController.Shutdown in the Disconnected event? Though I think that it is better to initialize the controller when the server is started and keep it running as long as the server is running. Upvote 0
Have you tried to call GPIOController.Shutdown in the Disconnected event? Though I think that it is better to initialize the controller when the server is started and keep it running as long as the server is running.
rwblinn Well-Known Member Licensed User Longtime User Sep 9, 2015 #3 GPIO.shutdown = yes have tried - same error. Init the controller during server start = yes have been considering that (init the controller and the pins in Main - this is working as have tried), but then have not found a solution (yet) how update the websocket jqueryelements (defined in the websocket class) from Main when the user connects to the server. Upvote 0
GPIO.shutdown = yes have tried - same error. Init the controller during server start = yes have been considering that (init the controller and the pins in Main - this is working as have tried), but then have not found a solution (yet) how update the websocket jqueryelements (defined in the websocket class) from Main when the user connects to the server.
Erel B4X founder Staff member Licensed User Longtime User Sep 10, 2015 #4 Make sure to go over the threads section in this tutorial: https://www.b4x.com/android/forum/t...ads-sessions-and-server-events.39969/#content The best solution is to use a code module to handle the controller. Use CallSubDelayed to call subs in this module. The subs will run on the main thread. This way you can write code that can handle multiple clients correctly. Use CallSubDelayed again from the code module to the websocket handler when there a response is available. Upvote 0
Make sure to go over the threads section in this tutorial: https://www.b4x.com/android/forum/t...ads-sessions-and-server-events.39969/#content The best solution is to use a code module to handle the controller. Use CallSubDelayed to call subs in this module. The subs will run on the main thread. This way you can write code that can handle multiple clients correctly. Use CallSubDelayed again from the code module to the websocket handler when there a response is available.
rwblinn Well-Known Member Licensed User Longtime User Sep 10, 2015 #5 Hi Erel, thanks for your steer - have rewritten this Raspberry Pi GPIO Experiment "The blinking LED" accordingly. Very Good learning about thread handling. The app is working fine. For those interested, the code attached. This solution is the basis for several Raspberry Pi GPIO Experiments - all controlled via Browser. The next in progress is an Obstacle Detector. More to follow - look here. Again amaizing what can be done with B4J. Attachments blinkingled.zip blinkingled.zip 12.4 KB · Views: 453 Upvote 0
Hi Erel, thanks for your steer - have rewritten this Raspberry Pi GPIO Experiment "The blinking LED" accordingly. Very Good learning about thread handling. The app is working fine. For those interested, the code attached. This solution is the basis for several Raspberry Pi GPIO Experiments - all controlled via Browser. The next in progress is an Obstacle Detector. More to follow - look here. Again amaizing what can be done with B4J.