Hello all! I am trying to make Gideros talk to a sensor peripheral (accelerometer and such) via BLE. I'm using the Red Bear Labs BLEmini board (redbearlab.com/blemini/), and I can successfully talk with it using Red Bear's sample Xcode project (github.com/RedBearLab/iOS). Searching around this forum / the rest of the internet, it seems the way to add Bluetooth functionality to a Lua script framework is via a plugin. I used
@OZApps very nice plugin tutorial to get started (howto.oz-apps.com/2013/11/creating-plug-in-for-lua-framework.html), and can successfully send data to and from the test.mm plugin.
All good so far! So I rebuilt GiderosiOSPlayer with the BLE (github.com/RedBearLab/iOS/tree/master/BLEFramework/BLE) and CoreBluetooth frameworks. However when I try to initialize a new BLE object I run into trouble. I added
#import "BLE.h"
at the top of test.mm, and then attempt to init the BLE object using
bleShield = [[BLE alloc] init];
from inside the test() function in test.mm. When calling
local t = require "mytest"
t.test()
from Gideros Studio, I get the following error:
main.lua:33: Error calling 'init' on ''
Could not find function named "init" associated with object BLE(0x15e66b50).(It may have been released by the GC)
stack traceback: main.lua:33: in main chunk
I'm definitely out of my depth here hacking around with the C++ / ObjC code. Can anyone point me towards a resource which might get me closer to BLE integration? I think this would be quite a nice addition to the world of Gideros, and I am more than happy to share my progress.
Thank you!
Comments
you mean that you are able to run this as a pure C++/Obj-C implementation but the moment you try to wrap it in a plug-in, you are faced with these issues, am I correct in that understanding?
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
@interface ViewController : UIViewController {
BLE *bleShield;
}
and BLE.h starts with
@protocol BLEDelegate
I'm guessing something about this delegate object type tells the Xcode compiler how to do the init. Probably I need to go back to basics and learn more about the keywords delegate, @interface, and @implementation!
I should also mention I tried using Wax to initialize a CBPeripheralManager, which did not work, perhaps because CoreBluetooth is not yet part of Wax?
a couple of things
1. I have been facing issues in trying to get BT working for over a year now. I was trying with an Android and Java using a 3rd party Library that *just* works, still no go.
2. The @protocol BLEDelegate is used to communicate with the module, sort of to set a call back.
3. WAX will not be of much help as it does not automatically map all of the protocols, delegates, etc
4. Yes it will help to catch up on the basics of objective-c classes and the keywords. interface and implementation are more OO related.
Let me see when I get the time to go through this code.
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
Ok, thank you very much for looking at it!
I found another Xcode project which wraps this Red Bear SDK, this one for PhoneGap Cordova (github.com/don/BluetoothSerial/tree/master/src/ios). Instead of a ViewController, the main wrapping code is called MEGBluetoothSerial. In MEGBluetoothSerial.h we find CDVPlugin instead of ViewController
So, to fit this pattern it seems that the plugin should be implemented as a class, and that class should adopt the BLEDelegate protocol. I'm confused about what to use instead of CDVPlugin or ViewController in the @interface line. Some Gideros core class?
how embarassing and frustrating, despite having more iOS gadgets than I can handle, and one running iOS7, I found that to run BT LTE, I need an iPad Mini or higher, a 4S or higher or the new iPad and higher.
I have an iPhone5 so I have a single device, however I do not have another device to experiment with (I have another new iPad but cannot use it for testing, out of bounds)
Will have to rethink getting a new ipad Air or something. Plus I am still running 10.7.5 on my main machine (need to upgrade that to 10.9.1) however most of my software that works might not continue to work on that. Grrrr..... crazy Apple hell, I thought that Microsoft DLL versioning was crazy, this Apple thing is worse
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
The code above is a custom encapsulation of the BT communication. Generally the device creates a service and starts broadcasting. Then the other device (generally your iOS device) will register to listen for all broadcast UUIDs and connect to one accordingly and then read/write data with that UUID.
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
My code is pretty messy, but someday I hope to turn it into a library (when I learn more about that process!). If anyone is trying to speak BLE, let me know and I will try to help.
Next up: talking to BLE on Android!
I am digging around but cant find useful approach to the problem. I have project that needs connection between Bluetooth device and Android phone and really prefer to use Gideros if possible. Any info will be of great help.
I actually wrote a BLE plugin for Gideron on Android and iOS one year ago or so, so it is indeed possible. But it mysteriously stopped working a few month ago for Android, I suppose due to some change in Android permission stuff or API. Note that is was BLE only, not generic bluetooth!
Likes: plamen
Likes: simwhi