Shop OBEX P1 Docs P2 Docs Learn Events
SUCCESS!!! SimpleIDE, the RN-42 Bluetooth Module, and B4A Android App - Page 2 — Parallax Forums

SUCCESS!!! SimpleIDE, the RN-42 Bluetooth Module, and B4A Android App

2»

Comments

  • Bluetooth.

    I think that you already stated that you have selected a BT module

    :smiley: LOL Well now I feel like an idiot :smile:
  • you are not alone
  • @idbruce

    Hey buddy, shoot me an email:

    craig at universecontrol dot net
  • Hey buddy, shoot me an email:

    An email has been sent.
  • For those that may be interested

    As it pertains to my recent questions pertaining to B4X libraries, I recently became a member of the B4X forum community, and asked my questions within the forum. The response was a little late, due to the new membership, but here is the thread, with a reply from an "Expert":

    https://b4x.com/android/forum/threads/a-couple-questions-about-libraries.116163/
  • idbruceidbruce Posts: 6,197
    edited 2020-08-11 20:22
    To Those That May Be Interested

    I finally managed to get my WiFi module working properly, so I am now going to attempt to get the Bluetooth module working properly. In my attempt to get Bluetooth working, I will be using the B4A platform to build a mobile application. I began building an application a long time ago and I must admit that it was interesting, however since that time, I have discovered a new possibility.

    From what I have read, apparently you can load html into an application, with the aid of the WebView library, and you can also use JavaScript by adding the WebViewExtras library. This is truly significant for me.

    Before I tell you why it is significant, let me give you a little background on my project. I built a machine, which I wanted to be able to control wirelessly, but you must first crawl before you can walk. After building the machine, of course I wanted to test it, but I had no wireless devices to control it. Without having wireless devices, I decided to build a CGI script, having an HTML form, and host it on my web site, as a control panel. I additionally built a C++ (MFC) application to retrieve command values from the web site and serially send the commands to the Propeller chip, through a hardwire connection. Everything worked great, at which point, it was time to make it wireless. By conquering the WiFi module, I am no longer tethered to a PC to receive my serial commands :) However, I am limited to being within 30 meters of the WiFi access point :( But that is good enough for my purposes :)

    Anyhow, I will now refer back to the significance of the WebView library, the WebViewExtras library, and the ability to use JavaScript. It basically means that most of my hardwork is already done, from a user interface standpoint. Since I already have the CGI script written in Perl, which provides the necessary HTML form for the user interface, I can simply strip out the Perl scripting, leaving me with the HTML form interface, at which point, I can simply add JavaScript to do the form validation and processing :) Or at least I believe so :) So the main goal at that point would be to acquire the machine command from the JavaScript validated form and send the command serially over Bluetooth.

    This is my current plan, please wish me luck :)

    EDIT: I forgot to mention that my JavaScript coding is a wee bit rusty :)
  • B4X is a sweet suite :smile:
  • idbruceidbruce Posts: 6,197
    edited 2020-08-11 23:09
    If this works out, it will certainly be nice and easy :) I like easy :) Machine control through an HTML form over a mobile device, with no internet connection needed, actually sounds pretty sweet :)

    I never truly imagined that scenario :)

    EDIT: Although I am sure it can be accomplished with the WiFi module, but I am talking about a Bluetooth connection.
  • idbruce wrote: »
    If this works out, it will certainly be nice and easy :) I like easy :) Machine control through an HTML form over a mobile device, with no internet connection needed, actually sounds pretty sweet :)

    I never truly imagined that scenario :)

    EDIT: Although I am sure it can be accomplished with the WiFi module, but I am talking about a Bluetooth connection.

    Yup. The big industrial control guys are now catching on to wireless control which I find encouraging. I have been doing this for eight years but only the HMI and users love the portability aspect.

    Next on my agenda is to eliminate 100% of field wiring (apart from power, obviously) in favor of distributed wireless nodes. No more fighting rat nests of dozens of wires.

    I have pretty much decided on switching from B4A to the simple RFO-BASIC, though because I find it much more suited to what I want to achieve. It also is compatible with HTML, etc.
  • I have been working on the JavaScript this morning, and I have it all pretty much wrapped up. Very shortly, I will be trying to figure out how to get it all working in B4A and build my application :)

    It is going good so far (fingers crossed).
  • Mickster

    That machine that you and I discussed a while back.... Pretty soon it will be able to be controlled remotely through WiFi or locally by Bluetooth :)
  • UPDATE:

    Without getting any direct help from anyone, it took me a while to figure out how to inject a JavaScript variable from my HTML source code, into my mobile app. It took many hours of investigation to get it right, but my JavaScript is now much better than it was and I now have access to my command string, which will control my machine :):):)

    I am now at the point to where I must hook up the Bluetooth module and get my mobile app to send the Propeller my command string :):):)
  • I think a lot of us are watching this thread with interest but are unable to contribute meaningfully. You have to admit that when it comes to making a wild, wonderful, wooley, cross-platform digital mash-up, this project has to be somewhere in the top 5% :) So “game on” and keep posting!
  • idbruceidbruce Posts: 6,197
    edited 2020-08-14 15:00
    Thanks JRoark

    Along the way, this project has had it's fair share of both setbacks and victories. Without a doubt, it is a very unique project and has been interesting every step of the way, and I have learned a lot about many things.

    The downside is that I wish I could share more information, but it is a "top secret" project, as well as being inappropriate for a younger audience. I do not think Parallax would approve of me posting serious content about this project :)

    When my project is done, and if I feel real ambitious, I may create some example code to show the programming aspects of it all.

    It is a very complicated project which does or will include:
    ...WiFi communication with a web server (Done)
    ...Bluetooth communication with Android running an HTML/JavaScript GUI (Currently working on it)
    ...SD card access (Code is written, but needs to be added to the project)
    ...DS3231 RTC timestamps (Code is written, but needs to be added to the project)
    ...Very serious control of a stepper motor

    I see the light at the end of the tunnel, but it is still quite far off in the distance :)

    EDIT: I hope all the code will fit, if not, then I will have to leave some of the options out and port it to a P2, when Parallax comes out with an Activity Board for the P2.
  • That combination of “top secret”, “Inappropriate for younger audience” and “very serious control of a stepper motor” suddenly has the undivided attention of the audience! :)
  • That combination of “top secret”, “Inappropriate for younger audience” and “very serious control of a stepper motor” suddenly has the undivided attention of the audience! :)

    LOL... Yea, I suppose :)
  • idbruceidbruce Posts: 6,197
    edited 2020-08-15 13:37
    SUCCESS :):):)

    Once again, I had a bit of trouble, but I just figured it out :)

    At this point, I now have an Android app, hosting an HTML form, with JavaScript, which searches for Bluetooth devices to connect with, connects with a selected device, and depending upon user selection from the HTML, the app now sends a command string to the Propeller :):):)

    Yippppppppiiiiiieeee :)

    Now I have to take all of my various test container code and carefully insert it into my project :)

    EDIT: The light at the end of the tunnel is now much closer :)
  • Hi idbruce

    This is great work!
    If, when you have time, you were to write an instructable on the processes and code used- I for one would be very grateful.

    Dave


  • More progress! Cool!

    Note that we are still waiting for some pictures of this project in-use. (Ha! See what I did there?)
  • If, when you have time, you were to write an instructable on the processes and code used- I for one would be very grateful.

    I am not saying that I will or that I won't, but my time is very limited. If I was to provide instructions, an interested party would need the following, in order to fully comprehend the processes and the code that I used:

    1. A fair level of skill in programming C/C++
    2. A fair level of skill in writing HTML
    3. A fair level of skill in creating HTML forms
    4. A fair level of skill and understanding of JavaScript
    5. A fair level of understanding CSS
    6. A fair level of understanding and the ability to alter Basic programs

    As JRoark referred to it:
    a wild, wonderful, wooley, cross-platform digital mash-up

    I think that about sums up this portion of my project :)

    Once again, if I did write something up and create an example, I certainly wouldn't want to answer a million questions, for those that don't have these skills or knowledge. Please don't misunderstand me.... I don't mind helping someone or teaching somone something, but my processes and code are fairly complex, and I know there would be a lot of questions :)
  • idbruceidbruce Posts: 6,197
    edited 2020-08-15 16:10
    However, in the meantime, I think I can point you in the right direction, as far as B4A goes. These links will help you get to the basics of making it happen:

    https://b4x.com/android/forum/threads/bluetooth-microcontroller-communication.24604/

    https://b4x.com/android/forum/threads/b4xpages-bluetooth-chat-example.119014/

    https://b4x.com/android/forum/threads/webviewextras.12453/

    There is another link that was helpful but I cannot find it.
  • idbruceidbruce Posts: 6,197
    edited 2020-08-15 16:31
    The ultimate key which unlocks the abilty of using HTML forms and sending form data back to the Propeller, lies in the WebViewExtras class. The WebViewExtras class has a class member of "CallSub". First you retrieve the form data with the aid of JavaScript, and in your JavaScript, you would make a call to "CallSub". Something like the following:
    B4A.CallSub('Update_Command', false, command);
    

    Update_Command is a user defined function in the B4A app that retrieves the data contained within "command", from your JavaScript, in your HTML. The data is then sent over bluetooth to the Propeller.

    The B4A app Update_Command function looks like this:
    Sub Update_Command(command As String)
    	
    	B4XPages.MainPage.SendMessage(command)
    	Log("Update_Command: "&command)
    End Sub
    
  • idbruceidbruce Posts: 6,197
    edited 2020-08-15 16:38
    I may provide an example in the B4A forum, which is a very good idea, because at that point, a person would just have to modify the HTML, the HTML form, the JavaScript coding, and the Update_Command funtion to suit there needs.

    Hmmmmmm........
  • Okay.... I created an example B4A application, for the RN-42 Bluetooth Module, and uploaded it to the b4X.com forum. It is currently awaiting approval. Once it is approved, I will provide a link to my post which contains the example. Additionally, at that time, I will zip up a SimpleIDE project, which will receive commands from an Android app, via the RN-42 Bluetooth Module.
  • Hi dbruce

    Thanks for that information. I do like learning from others examples, but I understand it takes a lot of time and trouble to assemble into an understandable form, and the implication of answering a myriad of silly questions- but everything you share will be appreciated.

    Dave
  • I am certainly not going to answer a bunch of questions :)
  • idbruceidbruce Posts: 6,197
    edited 2020-08-16 14:46
    Hmmmmm..... I suppose I could just post the zipped example here :)

    Here is a quote from my post at B4X.com:

    The title of my post is:
    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 :)

    Alright folks this is what you need :)

    EDIT: If I am not mistaken, you must be running Version: 10.0 (the latest updated version) of B4A, for this example to work.

    EDIT: You have everything here, but for completeness, 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/

    EDIT: Please note that in "Command.side", the constants BT_RST, BT_RTS, and BT_CTS are really not needed to communicate with the "42Nurses" Android app. I am updating "Command.side" to include a function prototype, so that it doesn't spit out warnings when compiled.

    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. :)

  • While I have a moment, I just wanted to notify interested parties that an updated version has been uploaded to the B4X.com forum, but it is currently waiting for moderator approval. It should be visible in a couple to several hours.

    The updated version makes it much easier to edit the HTML source code :)
  • UPDATE:

    It is still awaiting moderator approval at B4X.com.....
    Once again, thank you Erel, but this time I thank you for your "Voice Recognition Example", which can be found here: https://www.b4x.com/android/forum/threads/voice-recognition-example.7317/

    I have now added voice recognition to the 42Nurses example application, which entailed adding another CallSub from the WebViewExtras library, in the JavaScript and adding another HTML source file, as well as some other miscellaneous stuff. Of course the voice recognition part of this example is contingent upon your device being able to support it.

    In operation, your voice is transformed into a text string, and then this text string is transmitted via Bluetooth :)

    I hope you like the possibilities :)
Sign In or Register to comment.