SPIN: RN-42 Bluetooth Module And Android App... Working Example
idbruce
Posts: 6,197
Hello Everyone
I realize that there are members who prefer Spin over C/C++, so I took one of my C/C++ projects/discussions and am providing it for Spin also, because I think it is useful And Parallax, please forgive me for similar posts, but I think you can relate to the situation. For a more in depth discussion, but in a SimpleIDE context, please refer to this thread: forums.parallax.com/discussion/171419/success-simpleide-the-rn-42-bluetooth-module-and-b4a-android-app#latest
Anyhow, I purchased an RN-42 Bluetooth module, which I intended for machine control, but I definitely needed a custom app for Android. There are several choices when it comes to creating an Android app, but after a nudge from JonnyMac and Mickster, I looked into B4A, which is a programming environment for Android.
To sum it, I created an app which I believe will be useful to many people here that work and play with robots, machines, and home automation. To be able to use this example app, you will have to dabble in B4A just a little bit, to load and build the application, as well as altering some HTML and JavaScript code.
To make it easier on me, I will simply quote a post I made at B4X.com.
The title of the post was:
Here is a link to the B4X.com forum thread, where I posted the application: https://b4x.com/android/forum/threads/42nurses-webview-html-form-for-machine-robot-control-home-automation.121258/
To run and edit the Android example, you must be running Version: 10.0 (the latest updated version) of B4A.
Please note the constants BT_RST, BT_RTS, and BT_CTS, defined in "Command.spin" are really not needed to communicate with the "42Nurses" Android app.
42Nurses was written and compiled with B4A Ver. 10.0 and Command.spin was created and written with the Propeller Tool Ver. 1.3.2
EDIT: And for those of you who are not to keen on making the necessary alterations, I will make the alterations for you, in exchange for payment.
I realize that there are members who prefer Spin over C/C++, so I took one of my C/C++ projects/discussions and am providing it for Spin also, because I think it is useful And Parallax, please forgive me for similar posts, but I think you can relate to the situation. For a more in depth discussion, but in a SimpleIDE context, please refer to this thread: forums.parallax.com/discussion/171419/success-simpleide-the-rn-42-bluetooth-module-and-b4a-android-app#latest
Anyhow, I purchased an RN-42 Bluetooth module, which I intended for machine control, but I definitely needed a custom app for Android. There are several choices when it comes to creating an Android app, but after a nudge from JonnyMac and Mickster, I looked into B4A, which is a programming environment for Android.
To sum it, I created an app which I believe will be useful to many people here that work and play with robots, machines, and home automation. To be able to use this example app, you will have to dabble in B4A just a little bit, to load and build the application, as well as altering some HTML and JavaScript code.
To make it easier on me, I will simply quote a post I made at B4X.com.
The title of the post was:
42Nurses - WebView HTML Form For Machine/Robot Control & Home Automation
Hello Everyone
I believe this is only my second post and I have come here to contribute
Before I contribute, please allow me to say thank you to Erel for his [B4XPages] Bluetooth Chat Example, because without it, my contribution would not be possible. His example can be found here: https://www.b4x.com/android/forum/threads/b4xpages-bluetooth-chat-example.119014/
Now for the details... Ahhhh.... I will just summarize it Basically I took his chat example and added a WebView, along with WebViewExtras. In the WebView, I have an HTML form, supported and validated with JavaScript. Within the JavaScript, I utilize the member CallSub from the WebViewExtras library, to pass data back to the B4A app.
By altering the HTML, the HTML form, and the JavaScript, as well as perhaps adding additional CallSub calls, many things can be achieved and controlled with this example, very easily. It is intended for Bluetooth communication. I am using something very similar to this example application, to send commands to an RN-42 Bluetooth module, which passes those commands onto a Parallax Propeller uC, for machine control, and it does the job perfectly (so far ).
Anyhow, check it out, because it may help you find a solution. 42Nurses = RN-42
Here is a link to the B4X.com forum thread, where I posted the application: https://b4x.com/android/forum/threads/42nurses-webview-html-form-for-machine-robot-control-home-automation.121258/
To run and edit the Android example, you must be running Version: 10.0 (the latest updated version) of B4A.
Please note the constants BT_RST, BT_RTS, and BT_CTS, defined in "Command.spin" are really not needed to communicate with the "42Nurses" Android app.
42Nurses was written and compiled with B4A Ver. 10.0 and Command.spin was created and written with the Propeller Tool Ver. 1.3.2
EDIT: And for those of you who are not to keen on making the necessary alterations, I will make the alterations for you, in exchange for payment.
Comments
The updated version makes it much easier to edit the HTML source code
WOW I certainly expected more feedback
I guess everybody is focused on other things.
Your efforts/experiences are very valuable, thank you for posting them. Keep up the good work.
While I don't have a specific need/use for these developments at the moment, I'm sure they will come in handy in the future...
Thanks Francis
Just had time to get back onto the forum.
Thanks for posting this. I am interested in how an iphone or ipad can be used with a graphical display connected to the P2 (as Peter has said on the P2 forum). Because of iphone/iPad software costs, I think I should try this on an Android device first
Not sure when/if I will get time to try this but I've saved the link for when that time comes.
Thanks for posting, and keep us informed
Yea, with $99 per year (cost of developer account for B4I), you could have a new Android phone each year, instead of paying that fee I would definitely go the Android route.
The hardest part for anyone interested, is downloading the software and installing it. After that, running my app is a walk in the park, and altering HTML and JavaScript is not all that difficult.
It has been quite a while since I dived into any serious web programming, but I am fairly certain that technology has come a long way since I was serious. So I imagine a person could create some very nice interfaces with HTML, JavaScript, and CSS. And my example app can help them all to talk with a Propeller and even a Basic Stamp
It is still awaiting moderator approval at B4X.com.....
https://teguar.com/10-inch-android-rugged-tablet-trt-a5380.html