Welcome to EnviroDIY, a community for do-it-yourself environmental science and monitoring. EnviroDIY is part of WikiWatershed, a web toolkit designed to help citizens, conservation practitioners, municipal decision-makers, researchers, educators, and students advance knowledge and stewardship of fresh water. New to EnviroDIY? Start here

Transfer file from SD card to iOS/Android via bluetooth

Home Forums Infrastructure and Equipment Transfer file from SD card to iOS/Android via bluetooth

Tagged: 

Viewing 7 reply threads
  • Author
    Posts
    • #14998
      Selbig
      Participant

      Newbie question here…I successfully setup the Mayfly to measure and record temperature and dissolved oxygen to the SD card. Access to the loggers will require someone to paddle out in a canoe or kayak. Rather than have them risk dropping the SD card in the water while transferring data to a laptop, I’d like to have a simple file transfer via bluetooth to their smartphone.

      I’m using a HM-10 bluetooth module wired to the TXD and RXD ports (5 volt). I can connect to the bluetooth and send/receive text strings through the serial port but I can’t figure out how to transfer the file from the SD card to the smartphone through the bluetooth device. An internet search suggests using the DumpFile script in  SoftwareSerial.h (see below)

      #include <SPI.h>
      #include <SD.h>
      #include <SoftwareSerial.h>
      const int chipSelect = 12;
      SoftwareSerial BTSerial(3, 2); // RX | TX[/b]

      void setup() {
      // Open serial communications and wait for port to open:
      Serial.begin(57600);
      BTSerial.begin(57600);
      while (!Serial) {
      ; // wait for serial port to connect. Needed for native USB port only
      }

      Serial.print(“Initializing SD card…”);

      // see if the card is present and can be initialized:
      if (!SD.begin(chipSelect)) {
      Serial.println(“Card failed, or not present”);
      // don’t do anything more:
      while (1);
      }
      Serial.println(“card initialized.”);

      // open the file. note that only one file can be open at a time,
      // so you have to close this one before opening another.
      File dataFile = SD.open(“test.txt”);

      // if the file is available, write to it:
      if (dataFile) {
      while (dataFile.available()) {
      BTSerial.write(dataFile.read());
      }
      dataFile.close();
      }
      // if the file isn’t open, pop up an error:
      else {
      Serial.println(“error opening test.txt”);
      }
      }

      This works but it only spits out the data from the file on the SD card to the serial COM port on my laptop but not the bluetooth terminal on my smartphone. What am I missing?

    • #15061
      Sara Damiano
      Moderator

      I’m sorry, I’ve never tried anything with Bluetooth, so I’m only guessing here.

      If the Bluetooth chip is that simple, and you have it connected to TXD and RXD on your Mayfly, you should print to the bluetooth using just Serial.print and not do anything with SoftwareSerial.  Serial is the TXD and RXD on the Mayfly.  You could also connect it to TX1 and RX1 and use Serial1instead of sharing with the FTDI/PC output.

      The range of Bluetooth is very short under water (a few inches) so your users wouldn’t be able to do a float-by download.  They would most likely still need to pull the logger out of the water, and then initiate the Bluetooth connection.  Once it’s out of the water, though, you hopefully could get the data without actually opening the sealed box.

    • #15071
      neilh
      Participant

      Hi @selbig an interesting idea.

      I’ve been thinking about unattended access (of just equipment monitoring) and BT (low power) would be pretty nice. However as you are seeing there is a lot of complexity and some history with BT protocol versions that makes a simple concept a bit challenging.  Sounds like for some reason BT is not associating with your phone. That of course becomes the issue if you have a logger device with BT how do you get it to associate with the right device, and from a canoe.

      So I’m guessing from your description that you have a Mayfly logger above the water, in an environmental enclosure (IP65)  and are powering it in some way.

      Perhaps another idea that is almost as simple, is to use a USB cable

      So you would like to paddle up to the enclosure, plug into it, and receive the readings.

      There are some USB connectors that can be water tight, and sit on the bottom of the enclosure, assuming the water never rises as high as the enclosure.

      The act of plugging in to the USB cause it to reset from a computer, (and might also do it from a phone App Android “USB Serial Terminal Pro” ~ I haven’t tried it) and you could do a test in software in setup()  that if there is USB link ( with a time out of 10seconds to allow for a regular reset), to dump the contents of the data file.

      One item to consider with an isolated unattended device is to be able to verify  the “wall time” when collecting data from the logger. That is when getting to look at the data if the time series has  “funny time” how do you connect the readings with what we think of us “wall time”.

      One answer is that you may need to check it manually  when collecting the data, and have the person collecting the data note the time they downloaded.

      However if you have a USB cable connected, the time on download could be checked,  and then if off,  set through with a cmd line date/time setting.

       

    • #15072
      Selbig
      Participant

      Thanks for the input. I got it figured out. It’s a pretty sweet arrangement that will make life easier for data collection. As @neilh indicated, the Mayfly logger, bluetooth HM-10, battery, and all wires will be in a waterproof box above the water with the sensors in the water below secured to channel iron or some other rod. There’s an app called Bluetooth Commander for iOS that allows for data transfer right to your phone. Works pretty slick.

    • #15079
      Sara Damiano
      Moderator

      That’s great!  I’m sorry, I was imagining you had the entire set-up, Mayfly and all, running on batteries and sealed under water

    • #15091
      neilh
      Participant

      @selbig Wow thanks for sharing that. I’ve been thinking about BT for some time… and hadn’t seen how far it has come. There is also Blue Tooth Commander App  for Android  – so good for all types.

      I’m just wondering how you are powering it.?

      On powering, I’m really looking that it needs to be able to use low power, and then turn on when the CellPhone with BT is nearby and notify the Maylfy.  Low Power is a relative term to how much power is available.

      Possibly DSD TECH HM-19 CC2640R2F has possibly more support for low power… and as BT 5.0 says could have 4times range. Haven’t looked through it yet.

      The Digi Xbee LTE CAT-M1 also incorporates BTLE.

      Some other resources I found

      https://how2electronics.com/bluetooth-low-energy-tutorial-with-hm-10-ble-4-0-arduino/

      https://how2electronics.com/nordic-nrf52840-advanced-bluetooth-5-arduino-ide/

       

       

    • #15098
      Sara Damiano
      Moderator

      I was reading up on the BLE support on the XBee3.  I think the only way to send data over Bluetooth is with Digi API frames.  You can use the on-board micropython, but from what I can tell, that uses the API frames under the hood.  So apart from having to figure out how to use the Mayfly to switch the XBee3 into API mode and properly chunk/format/send the SD card data into those frames, you’d have to figure out some way to take the frames you receive and turn them back into the data you want.  I *strongly* suspect that it wouldn’t be even close to worth the trouble to figure all those bits out and would just get a simpler Bluetooth device and leave the XBee3’s Bluetooth off.  My experience with the API frames on the XBee is that they’re a huge PITA and really hard to get right (as in, I couldn’t do it).

    • #15104
      neilh
      Participant

      found this

      http://www.dfrobot.com/product-1073.html  TEL0073 Xbee TH BLUETOOTH 4.0  using Ti’s CC2540.  Digikey 1738-1014-ND‎

      Seems to me there is a critical power issue;  how can a powered BT LE sleeping device plugged into a Mayfly,   wake a sleeping Mayfly once a remote BT LE beacon (cell phone) has been detected.  For the TEL0073 there is a mapping to an Xbee Socket Pins (Xbee9/D23,  Xbee12/D19 or  Xbee16/D20) that might work.

      Ti’s CC2540 suggests sleep current is in the low 10’s uA (but not sure if this is monitoring for a beacon while asleep) .

      BT LE 5.0 has 4 x longer reach at reduced data, not sure what other benefits it would have to a modular sensors configuration.

      I haven’t had time to dig further into TEL0073 or HM-19. The Tel0073 looks attractive for simplicity of plugging into the Xbee socket.

       

Viewing 7 reply threads
  • You must be logged in to reply to this topic.