Post a new topicPost a reply Page 1 of 1   [ 4 posts ]
Author Message
 Post subject: Reading Serial Data in Windows via Mysignals BLE
PostPosted: Mon Jun 19, 2017 3:50 am 

Joined: Fri Jun 09, 2017 4:29 am
Posts: 6
Good morning, Admin,

I am in problem of reading serial data in windows via Mysignals BLE,
The following are my procedure:
I use BLE App Connection Example and modify the code, so that it will be updating ECG data,
then I attempt to read the data using incoming BLE data, using Putty and Tera Term, however it doesn't show any output messages.
I have also attempted using BLE serial Apps in Smartphone, but it also failed.

For info: the data from ECG has shown in TFT LCD screen, and I have been successfully connected to Mysignals HW

Attach Image:
https://ibb.co/kCFh8Q

Thank you admin


Top
 Profile  
 
 Post subject: Re: Reading Serial Data in Windows via Mysignals BLE
PostPosted: Mon Jun 19, 2017 7:42 am 

Joined: Mon Sep 28, 2009 12:06 pm
Posts: 11292
Hello DragonWilly,

You have to keep in mind that serial communication with the BLE module is not done using ASCII printable characters, but with hexadecimal characters, so you need a program that is capable of receiving hexadecimal communication. For example in Linux we use Cutecom selecting "Hex output".

Regards


Top
 Profile  
 
 Post subject: Re: Reading Serial Data in Windows via Mysignals BLE
PostPosted: Mon Jun 19, 2017 8:18 am 

Joined: Fri Jun 09, 2017 4:29 am
Posts: 6
Dear Admin,
Thanks for the notice,
I have tried another Terminal, which support with hexadecimal output, such as yat and hercules,
however, I didn't find any output in Serial Terminal,
I attach my code, for more information,

Code:
#include <Adafruit_GFX_AS.h>
#include <Adafruit_ILI9341_AS.h>
#include <MySignals.h>
#include <MySignals_BLE.h>
#include <Wire.h>
#include <SPI.h>

char buffer_tft[30];

Adafruit_ILI9341_AS tft = Adafruit_ILI9341_AS(TFT_CS, TFT_DC);

unsigned long previous;


// Sensor list
bool selected_airflow;
bool selected_ecg;
bool selected_emg;
bool selected_gsr;
bool selected_position;
bool selected_snore;
bool selected_temp;
bool selected_spiro;
bool selected_eeg;
bool selected_spo2_uart;
bool selected_bp_uart;
bool selected_gluco_uart;
bool selected_scale_ble;
bool selected_spo2_ble;
bool selected_bp_ble;
bool selected_gluco_ble;
uint8_t sensor_list_mode;

uint8_t spir_measure_individual;
uint8_t gluco_measure_individual;

uint8_t last_measure_hour_spiro;
uint8_t last_measure_minutes_spiro;
uint8_t last_measure_number_spiro;

uint8_t last_measure_hour_gluco;
uint8_t last_measure_minutes_gluco;
uint8_t last_measure_number_gluco;



void setup()
{
  MySignals.begin();

  tft.init();
  tft.setRotation(2);
  tft.fillScreen(ILI9341_BLACK);
  tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);

  //TFT message: Welcome to MySignals
  strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[0])));
  tft.drawString(buffer_tft, 0, 0, 2);


  Serial.begin(115200);

  MySignals.initSensorUART();


  MySignals.enableSensorUART(BLE);

  MySignals_BLE.hardwareReset();
  MySignals_BLE.initialize_BLE_values();


  if (MySignals_BLE.initModule() == 1)
  {

    if (MySignals_BLE.sayHello() == 1)
    {
      //TFT message: "BLE init ok";
      strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[1])));
      tft.drawString(buffer_tft, 0, 15, 2);
    }
    else
    {
      //TFT message:"BLE init fail"
      strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[2])));
      tft.drawString(buffer_tft, 0, 15, 2);


      while (1)
      {
      };
    }
  }
  else
  {
    //TFT message: "BLE init fail"
    strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[2])));
    tft.drawString(buffer_tft, 0, 15, 2);

    while (1)
    {
    };
  }



}


void loop()
{

  //1. SET MODE: SLAVE (VISIBLE TO APP)
  while ((MySignals_BLE.ble_mode_flag == master_mode))
  {

    if (MySignals_BLE.setMode(slave_mode) == 0)
    {
      //TFT message:  "Slave mode ok";
      strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[3])));
      tft.drawString(buffer_tft, 0, 30, 2);


      MySignals_BLE.ble_mode_flag = slave_mode;
    }
    else
    {
      //TFT message:  "Slave mode fail"
      strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[4])));
      tft.drawString(buffer_tft, 0, 30, 2);


      MySignals_BLE.hardwareReset();
      delay(100);
      MySignals_BLE.initialize_BLE_values();
    }
  }



  //2. SET BONDABLE MODE
  if (MySignals_BLE.bond_mode_and_mitm == 0)
  {
    if (MySignals_BLE.setBondableMode(BLE_ENABLE_BONDING) == 0)
    {

      //TFT message:  "Bondable mode ok"
      strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[5])));
      tft.drawString(buffer_tft, 0, 45, 2);



      //3. SET SM PARAMETERS
      if (MySignals_BLE.setSMParameters(BLE_ENABLE_MITM) == 0)
      {
        //TFT message:  "SM parameters ok"
        strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[7])));
        tft.drawString(buffer_tft, 0, 60, 2);


        MySignals_BLE.bond_mode_and_mitm = 1;

      }
      else
      {
        //TFT message:  "SM parameters fail"
        strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[8])));
        tft.drawString(buffer_tft, 0, 60, 2);

        MySignals_BLE.hardwareReset();
        delay(100);
        MySignals_BLE.initialize_BLE_values();
      }
    }
    else
    {
      //TFT message:  "Bondable mode fail"
      strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[6])));
      tft.drawString(buffer_tft, 0, 45, 2);

      MySignals_BLE.hardwareReset();
      delay(100);
      MySignals_BLE.initialize_BLE_values();
    }
  }


  //3. BONDING AND CONNECTION CONFIGURATION
  if ((MySignals_BLE.ble_mode_flag == slave_mode) && (MySignals_BLE.bonded_and_connected_flag == 0))
  {

    MySignals_BLE.bonding_correct = 0;
    MySignals_BLE.app_connected_flag = 0;
    MySignals_BLE.bonding_fail = 0;

    /////////////////////

    //TFT message:  "Waiting connections..."
    strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[9])));
    tft.drawString(buffer_tft, 0, 75, 2);


    uint8_t flag = MySignals_BLE.waitEvent(500);

    if (flag == BLE_EVENT_CONNECTION_STATUS)
    {
      MySignals_BLE.app_connected_flag = 1;
    }
    else if (flag == BLE_EVENT_SM_BOND_STATUS)
    {
      if (MySignals_BLE.event[6] == 0x01)
      {
        MySignals_BLE.bonding_correct = 1;
        delay(1000);
      }
    }
    else if (flag == 0)
    {
      // If there are no events, then no one tried to connect
    }
    else if (flag == BLE_EVENT_ATTRIBUTES_VALUE)
    {
      //Already connected
      MySignals_BLE.app_connected_flag = 1;
      MySignals_BLE.bonding_correct = 1;
      MySignals_BLE.bonded_and_connected_flag = 1;
    }
    else
    {
      // Other event received from BLE module
    }

    /////////////////////

    if ((MySignals_BLE.bonding_correct == 1) || MySignals_BLE.app_connected_flag == 1)
    {
      //TFT message:  "Connection detected..."
      strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[10])));
      tft.drawString(buffer_tft, 0, 90, 2);

      previous = millis();

      while ((MySignals_BLE.bonded_and_connected_flag == 0) && (MySignals_BLE.bonding_fail == 0))
      {
        //  Timeout 30 sg
        if ((millis() - previous) > 30000)
        {
          MySignals_BLE.bonding_fail = 1;
        }

        flag = MySignals_BLE.waitEvent(1000);

        if (flag == 0)
        {
          //Do nothing
        }
        else if (flag == BLE_EVENT_SM_PASSKEY_DISPLAY)
        {

          uint32_t passkey_temp =
            uint32_t(MySignals_BLE.event[5]) +
            uint32_t(MySignals_BLE.event[6]) * 256 +
            uint32_t(MySignals_BLE.event[7]) * 65536 +
            uint32_t(MySignals_BLE.event[8]) * 16777216;

          //TFT message:  "Passkey:";"
          strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[11])));
          tft.drawString(buffer_tft, 0, 105, 2);
          tft.drawNumber(passkey_temp, 50, 105, 2);
        }

        else if (flag == BLE_EVENT_ATTRIBUTES_VALUE)
        {
          //Already connected
          MySignals_BLE.app_connected_flag = 1;
          MySignals_BLE.bonding_correct = 1;
          MySignals_BLE.bonded_and_connected_flag = 1;
        }

        else if (flag == BLE_EVENT_SM_BOND_STATUS)
        {

          if (MySignals_BLE.event[6] == 0x01)
          {
            //Man-in-the-Middle mode correct
            MySignals_BLE.bonding_correct = 1;
          }
        }

        else if (flag == BLE_EVENT_CONNECTION_FEATURE_IND)
        {
          //Do nothing
        }

        else if (flag == BLE_EVENT_CONNECTION_VERSION_IND)
        {
          //Do nothing
        }

        else if (flag == BLE_EVENT_SM_BONDING_FAIL)
        {
          MySignals_BLE.bonded_and_connected_flag = 0;
          MySignals_BLE.bonding_fail = 1;
        }
        else if (flag == BLE_EVENT_CONNECTION_STATUS)
        {

          if (MySignals_BLE.event[5] == 0x03)
          {
            //Connection correct
            MySignals_BLE.app_connected_flag = 1;

          }
        }
        else if (flag == BLE_EVENT_CONNECTION_DISCONNECTED)
        {
          MySignals_BLE.bonded_and_connected_flag = 0;
          MySignals_BLE.bonding_fail = 1;
        }
        else
        {
          //Do nothing
        }


        if (MySignals_BLE.bonding_correct && MySignals_BLE.app_connected_flag)
        {

          //TFT message:  "Connected!"
          strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[12])));
          tft.drawString(buffer_tft, 0, 120, 2);


          //TFT message:  "Sensor list:"
          strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[14])));
          tft.drawString(buffer_tft, 0, 135, 2);

          //// SENSORES

          //TFT message:  "Airflow:"
          strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[20])));
          tft.drawString(buffer_tft, 0, 150, 2);

          //TFT message:  "Temperature:"
          strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[21])));
          tft.drawString(buffer_tft, 0, 165, 2);

          //TFT message:  "Position:"
          strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[22])));
          tft.drawString(buffer_tft, 0, 180, 2);

          //TFT message:  "GSR:"
          strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[23])));
          tft.drawString(buffer_tft, 0, 195, 2);

          //TFT message:  "ECG:"
          strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[24])));
          tft.drawString(buffer_tft, 0, 210, 2);

          //TFT message:  "EMG:"
          strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[25])));
          tft.drawString(buffer_tft, 0, 225, 2);

          //TFT message:  "Snore:"
          strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[26])));
          tft.drawString(buffer_tft, 0, 240, 2);

          //TFT message:  "SPO2:"
          strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[28])));
          tft.drawString(buffer_tft, 0, 255, 2);

          //TFT message:  "Glucometer:"
          strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[29])));
          tft.drawString(buffer_tft, 0, 270, 2);

          //TFT message:  "Spirometer:"
          strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[30])));
          tft.drawString(buffer_tft, 0, 285, 2);

          MySignals_BLE.bonded_and_connected_flag = 1;
        }

      }


      // If the bonding failed to restart the module and reload page
      if (MySignals_BLE.bonding_fail == 1)
      {
        //TFT message:  "Connection failed. Reseting"
        strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[13])));
        tft.drawString(buffer_tft, 0, 120, 2);

        MySignals_BLE.bonded_and_connected_flag = 1;
        MySignals_BLE.hardwareReset();
        delay(100);
        MySignals_BLE.initialize_BLE_values();
      }
    }
  }




  //4. READ SENSOR LIST AND UPDATE VALUES OF SENSORS
  if ((MySignals_BLE.ble_mode_flag == slave_mode) && (MySignals_BLE.app_connected_flag == 1))
  {
    if (MySignals_BLE.readLocalAttribute(handle_3_0) == 0)
    {

      sprintf(buffer_tft, "%X %X %X  ", MySignals_BLE.attributeValue[1], MySignals_BLE.attributeValue[0], MySignals_BLE.attributeValue[2]);
      tft.drawString(buffer_tft, 100, 135, 2);


      selected_airflow    = MySignals_BLE.attributeValue[0] & 0b00000001;
      selected_gluco_uart = MySignals_BLE.attributeValue[0] & 0b00000010;
      selected_spiro      = MySignals_BLE.attributeValue[0] & 0b00000100;
      selected_gluco_ble  = MySignals_BLE.attributeValue[0] & 0b00001000;
      selected_bp_uart    = MySignals_BLE.attributeValue[0] & 0b00010000;
      selected_bp_ble     = MySignals_BLE.attributeValue[0] & 0b00100000;
      selected_scale_ble  = MySignals_BLE.attributeValue[0] & 0b01000000;
      selected_ecg        = MySignals_BLE.attributeValue[0] & 0b10000000;

      selected_eeg        = MySignals_BLE.attributeValue[1] & 0b00000001;
      selected_emg        = MySignals_BLE.attributeValue[1] & 0b00000010;
      selected_gsr        = MySignals_BLE.attributeValue[1] & 0b00000100;
      selected_position   = MySignals_BLE.attributeValue[1] & 0b00001000;
      selected_snore      = MySignals_BLE.attributeValue[1] & 0b00010000;
      selected_spo2_uart  = MySignals_BLE.attributeValue[1] & 0b00100000;
      selected_spo2_ble   = MySignals_BLE.attributeValue[1] & 0b01000000;
      selected_temp       = MySignals_BLE.attributeValue[1] & 0b10000000;
    }
   
      SPI.end();

      MySignals.ECGFlagBPM = 1;

      uint16_t ecg_raw = MySignals.getECG();

      tft.fillRect(70, 212, 100, 11, ILI9341_BLACK);
      tft.drawNumber(ecg_raw, 80, 210, 2);

      uint8_t ecg_raw_low = ecg_raw & 0b0000000011111111;
      uint8_t ecg_raw_high = (ecg_raw & 0b1111111100000000) / 256;

      uint8_t ecg_vector[3] =
      {
        ecg_raw_low, ecg_raw_high, MySignals.ECGDataBPMBalanced
      };

      MySignals.enableSensorUART(BLE);
      MySignals_BLE.writeLocalAttribute(handle_3_4, ecg_vector, 3);


    // parse the status: 0 not connected; 1 connected; 2 encrypted;
    // 4 connection completed; 8 parameters changed
    MySignals.enableSensorUART(BLE);
    //MySignals.pauseInterrupt();
    if (MySignals_BLE.getStatus(MySignals_BLE.connection_handle) == 0)
    {

      //TFT message:  "Disconnected"
      strcpy_P((char*)buffer_tft, (char*)pgm_read_word(&(table_MISC[15])));
      tft.drawString(buffer_tft, 0, 120, 2);

      MySignals_BLE.hardwareReset();
      delay(100);
      MySignals_BLE.initialize_BLE_values();
    }
    //MySignals.resumeInterrupt();
  }
}

Is there something wrong with my code?
Thanks for your help Admin


Top
 Profile  
 
 Post subject: Re: Reading Serial Data in Windows via Mysignals BLE
PostPosted: Thu Jun 22, 2017 7:36 am 

Joined: Mon Sep 28, 2009 12:06 pm
Posts: 11292
Hello DragonWilly,

we recommend using TFT for debugging while using BLE module because this module uses the UART comunication. The code seems to be correct but we don't understand exactly what you want to do now. What is your goal?

Regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 4 posts ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Libelium theme based on 610nm Style by Daniel St. Jules of http://www.gamexe.net


© Libelium Comunicaciones Distribuidas S.L. | Terms of use.