AguaClara / post.bluetooth-DEPRECATED

The bluetooth widget for connecting POST with the turbidimeter.
0 stars 0 forks source link

Bluetooth module and version #5

Closed danelimjoco closed 7 years ago

danelimjoco commented 7 years ago

Hi @iamchriskelley!

I was wondering I'll Bluetooth version and module you use for the turbidimeter. I'm having trouble connecting the Agua Clara phone with my iPhone and laptop, so I'm wondering if it will be able to connect with the turbidimeter smoothly. Thanks!

iamchriskelley commented 7 years ago

Hey @danelimjoco,

Everything has been shipped and should arrive at Cornell Wednesday morning. After your message I waited an extra day to be able to test Bluetooth 2.0 (Android-compatible only) and 4.1 (Android- & iOS-compatible) dongles.

Here is an explanation of what I've shipped and how to use it to test the Bluetooth connectivity in POST:

Since you guys had an issue operating the last turbidimeter I sent, this time I went as simple as possible -- a breadboarded microcontroller connected to a bluetooth dongle and lipo battery, with a single button. When the battery is plugged in, the device turns on; the device must then be connected over Bluetooth to a phone using a Bluetooth terminal app. After successful tethering, pressing the button prompts the dummy device to broadcast over Bluetooth a JSON string with a random turbidity value. The message may contain a dummy numeric reading error or global error code (10% chance of each).

-Here are the components you should receive: 20161106_181603

-Here is a closeup of the device with no BT dongle attached. Note the position of the power connecter and the microprocessor board in case either detaches during shipping. Re-attaching either component to the wrong rows of pins could of course be very bad. 20161106_181616

-Here is the device with the Bluetooth 2.0 dongle (green face, 90-degree header pins, Android-only) attached: 20161106_181638

To interface this dongle with and Android phone, I use the Android Bluetooth Terminal app. First time, use "Connect - Insecure", and when prompted for the pin enter '1234'. Once this is stored, you can connect securely without re-entering the pin. The dongle model name is "HC-06".

-Here is the device with the Bluetooth 4.1 dongle (blue face, 180-degree header pins, Android & iOS) attached: 20161106_181705

To interface this dongle with and Android phone, I use the HMBLE Terminal app. I didn't need a pin to connect; if you find you need one on iOS the dongle model name is "HM-10" and the pin is probably '1234' or '1111'.

-Here is the device connected to the battery: 20161106_181737

You'll need to remove the bit of tape I covered the battery terminal with before shipping.

-When you press the button, the green led on the board should light up: 20161106_181742

Please let me know if you have any issues.

ALSO: If you'd like to update the firmware on the dummy device, you can access the necessary pins (5V, GND, TX, RX, DTR) on the breadboard. Here is the current firmware code:

include

define BTN 13

long pulse_count = 0;

void add_pulse() {++pulse_count;}

void setup() { PCintPort::attachInterrupt(BTN, add_pulse, RISING); Serial.begin(9600); pinMode(BTN, INPUT); randomSeed(analogRead(0)); }

void loop() { delay(10); if(digitalRead(BTN)){ pulse_count = 0; long rnd = random(10000); float f = float(rnd) / 50.0; long ge = random(10); long e = random(10);

String s = "{\"id\":\"01010101\",\"dt\":\"hhT\",\"al\":\"{}\",\"ge\":[";
if(ge < 3) s += ge;
s += "],\"rt\":0,\"ts\":0,\"rd\":{\"tur\":{\"d\":[";
s += f;
s += "],\"u\":\"ntu\",\"e\":[";
if(e < 3) s += e;
s += "],\"t\":[0]}}}";
Serial.println(s);
delay(100);
s = "";

} }

iamchriskelley commented 7 years ago

@danelimjoco I should also add that I haven't tested the Bluetooth 4.1 dongle with an Apple product, but generally speaking Bluetooth 2.0 simply does not work with Apple, and Bluetooth 4.1 does.

danelimjoco commented 7 years ago

Hi @iamchriskelley Thank you so much! Super excited to start working with it, it looks great!

danelimjoco commented 7 years ago

@ethan92429 @iamchriskelley

Good news! I was able to pair the phone with the device. After tweaking the app a bit, I was able to press the button and fill the turbidity fields in ODK with the correct randomly generated values! However, I need to unpair and pair the device again for my app to recognize the device when I try to fill another turbidity field. Also, the phone just doesn't recognize the device sometimes when I try to pair it and I get an error saying "Couldn't pair with HC-06 because of an incorrect PIN or passkey" but if I try a couple more times it eventually works.

*Update: I was able to avoid having to re-pair the device for each time by calling closeBT() right before sending the value and finishing.

iamchriskelley commented 7 years ago

@danelimjoco @ethan92429

That sounds promising! My first question -- are you using, as I presume, an Android phone (and what type)? And, have you run the basic test cases (outlined previously) for each BT module? Regarding the second issue, I have only once or twice encountered a connection error for an Android phone when using either type of module, and those errors were fixed by cycling the phone's BT, so it would be good to know whether the phone is having connection issues even with dedicated terminal apps.

As for the first issue, I'm not Java-fluent and afraid I can't be much help. A former undergraduate assistant in my lab wrote a basic Java app that paired these BT modules to a phone; I'd be happy to ask him about sharing his code if you like.

eak24 commented 7 years ago

I think we fixed these problems so I'm closing this issue.