Cooking Hacks Forum
https://cooking-hacks.com/forum/

e-Health wi-fi module open command
https://cooking-hacks.com/forum/viewtopic.php?f=20&t=13712
Page 1 of 1

Author:  Seiya [ Mon Jun 11, 2018 10:32 am ]
Post subject:  e-Health wi-fi module open command

I use a program that saves pulse wave and body temperature data in a file and can check it with a browser.
But there is a problem with this program.
It takes time to process the open command to acquire the data every second.
How can I send data every second?
Write the code used below and the result of the Arduino serial monitor.

Because I am using Google translation, it may be funny English, but thank you.

ArduinoIDE
Code:
#include <PinChangeInt.h>
#include <eHealth.h>
//Enter here your data
const char wifi_ssid[] = "ssid";
const char wifi_password[] = "passward";

const char host[] = "my PC IP";
const char gateway[] = "192.168.0.1";
const char server[] = "192.168.0.70";
const char host_port[] = "8080";
const char GET[] = "test.php?Temperature=20&PRbpm=45";

int8_t answer;
char response[300];
char response2[100];
int cont;
int kaunt=0;
char aux_str[100];
int s=1;
int l=0;

char value[50];

void setup()
{
  //Write here you correct baud rate
  Serial.begin(9600);
  //Serial.begin(115200);
 
  wificonfig();
    eHealth.initPulsioximeter();

  //Attach the inttruptions for using the pulsioximeter.
  PCintPort::attachInterrupt(6, readPulsioximeter, RISING);
}

void loop()
{
 
  Serial.println(F("Sending HTTP GET"));
 
  //delay(100);
  while(s>0){
  Serial.println("============================="); 
  Serial.print("PRbpm : ");
  Serial.print(eHealth.getBPM());

  Serial.print("    %SPo2 : ");
  Serial.print(eHealth.getOxygenSaturation());

  Serial.print("\n");
  //delay(500);
 
  float temperature = eHealth.getTemperature();

  Serial.print("Temperature (ºC): ");
  Serial.print(temperature, 2);
  Serial.println("");
  Serial.println("=============================");
 
  sendGET(temperature,eHealth.getBPM());
  //delay(1000);   // wait for a second
  }
}



void wificonfig() {
 
  Serial.println(F("Setting Wifi parameters"));
  sendCommand("exit\r","EXIT",2000);
  //delay(2000);
 
  enterConfig(2000);
  sendCommand("leave\r","DeAuth",2000);
  //delay(1000);
  // Sets DHCP and TCP protocol
  /*sendCommand("set ip dhcp 1\r","AOK",2000);
  delay(1000);   
  sendCommand("set ip protocol 18\r","AOK",2000);
  delay(1000);

  // Configures the way to join the network AP, sets the encryption of the
  // network and joins it
  sendCommand("set wlan join 0\r","AOK",2000); //The auto-join feature is disabled
  delay(1000);

  snprintf(aux_str, sizeof(aux_str), "set wlan phrase %s\r", wifi_password);
  sendCommand(aux_str,"AOK",2000);*/
  //delay(1000);   
  snprintf(aux_str, sizeof(aux_str), "join %s\r", wifi_ssid);
  answer = sendCommand(aux_str,"Associated",10000);


  if (answer == 1){

    snprintf(aux_str, sizeof(aux_str), "Connected to \"%s\"", wifi_ssid);
    Serial.println(aux_str);
    //delay(5000);
  }

  else {
    snprintf(aux_str, sizeof(aux_str), "Error connecting to: \"%s\"", wifi_ssid);
    Serial.println(aux_str);
    delay(1000);
  }


  Serial.println(F("Wifi succesfully configured"));
  //delay(1000);
}



void sendGET(float Temperature,int PRbpm) {
 
  enterConfig(2000);
  //sendCommand("set i h 0\r","AOK",2000);
  //delay(1000);
  //snprintf(aux_str, sizeof(aux_str), "set d n %s\r", server);
  //sendCommand(aux_str,"AOK",2000);
  /*delay(1000);
  snprintf(aux_str, sizeof(aux_str), "set dns address %s\r", gateway);
  sendCommand(aux_str,"AOK",2000);
  delay(1000);
  snprintf(aux_str, sizeof(aux_str), "set ip host %s\r", host);
  sendCommand(aux_str,"AOK",2000);
  delay(1000);
  snprintf(aux_str, sizeof(aux_str), "set ip gateway %s\r", gateway);
  sendCommand(aux_str,"AOK",2000);
 
  delay(1000);
  snprintf(aux_str, sizeof(aux_str), "set ip address %s\r", server);
  sendCommand(aux_str,"AOK",2000);
  delay(1000);*/
  //Configures HTTP connection
 
  snprintf(aux_str, sizeof(aux_str), "set ip remote %s\r", host_port);
  sendCommand(aux_str,"AOK",2000);
  //delay(1000);

  sendCommand("set opt format 1\r","AOK",2000);
  //delay(1000);
 
  dtostrf(Temperature,5,2,value);
 
  snprintf(aux_str, sizeof(aux_str), "set comm remote GET$/test.php?Temperature=%s&PRbpm=%d\r", value,PRbpm);
  sendCommand(aux_str,"AOK",10000);
  //delay(1000);

  // Calls open to launch the configured connection.
  sendCommand("open\r","*CLOS*",10000);
  //delay(1000);
 
 
 
  findResponse();
 

 
}


void findResponse(){
  Serial.println(response);
  boolean go_On = true;
  uint16_t counter = 0;

  while (go_On){

    if (response[counter] == '\r'){

      if (response[counter+1] == '\n'){

        if (response[counter+2] == '\r'){

          if (response[counter+3] == '\n'){

            go_On = false;
          }

        }   

      }     

    }

    counter++;
  }
  counter = counter + 3;

  for (int i=0;response[i+counter]!='*'; i++){
    response2[i] = response[i+counter];
    delay(100);


  }

  snprintf(aux_str, sizeof(aux_str), "GET response:\"%s\"", response2);
  Serial.println(aux_str);


}


int8_t sendCommand(const char* Command, const char* expected_answer, unsigned int timeout){

  uint8_t x=0,  answer=0;
  unsigned long previous;

  memset(response, 0,300);    // Initialize the string

  delay(100);

  while( Serial.available() > 0) Serial.read();    // Clean the input buffer

  Serial.println(Command);    // Send Command

    x = 0;
  previous = millis();

  // this loop waits for the answer
  do{
    if(Serial.available() != 0){   
      // if there are data in the UART input buffer, reads it and checks for the asnwer
      response[x] = Serial.read();
      x++;
      // check if the desired answer  is in the response of the module
      if (strstr(response, expected_answer) != NULL)   
      {
        answer = 1;
      }
    }
  }
  // Waits for the asnwer with time out
  while((answer == 0) && ((millis() - previous) < timeout));   

  return answer;
}


int8_t enterConfig(unsigned int timeout){

  uint8_t x=0,  answer=0;
  unsigned long previous;

  memset(response, 0,300);    // Initialize the string

  delay(100);

  while( Serial.available() > 0) Serial.read();    // Clean the input buffer

  Serial.print("$$$");    // Send Command


  x = 0;
  previous = millis();

  // this loop waits for the answer
  do{
    if(Serial.available() != 0){   
      // if there are data in the UART input buffer, reads it and checks for the asnwer
      response[x] = Serial.read();
      x++;
      // check if the desired answer  is in the response of the module
      if (strstr(response, "CMD") != NULL)   
      {
        answer = 1;
      }
    }
  }
  // Waits for the asnwer with time out
  while((answer == 0) && ((millis() - previous) < timeout));   

  return answer;
}

void readPulsioximeter(){

  cont ++;

  if (cont == 50) { //Get only of one 50 measures to reduce the latency
    eHealth.readPulsioximeter();
    cont = 0;
  }
}


test.php
Code:
<?php
    $filename = "data.txt";

    $data1 = $_GET['Temperature'];
    $data2 = $_GET['PRbpm'];
    if($data1=='a'){
    $fp = fopen($filename, "r");
    $contents = fread($fp, filesize($filename));
    print($contents);
    fclose($fp);
  }
    else{
    $fp = fopen($filename, 'a');
    date_default_timezone_set('Asia/Tokyo');
    fwrite($fp,  date("Y-m-d H:i:s")."\t".$data1."\t".$data2."\r\n");
    fclose($fp);
  }

?>


ーSerial monitorー

Setting Wifi parameters
exit

$$$leave

join AirMacTimeCapsuleKO

Connected to "AirMacTimeCapsuleKO"
Wifi succesfully configured
Sending HTTP GET
=============================
PRbpm : 0 %SPo2 : 0
Temperature (ºC): 44.71
=============================
$$$set ip remote 8080

set opt format 1

set comm remote GET$/test.php?Temperature=44.71&PRbpm=0

open

open

<4.41>

<4.41>
*OPEN*HTTP/1.1 200 OK
Date: Mon, 11 Jun 2018 09:28:36 GMT
Server: Apache/2.4.33 (Win32) OpenSSL/1.1.0h PHP/7.2.5
X-Powered-By: PHP/7.2.5
Content-Length: 0
Connection: close
Content-Type: text/html; charset=UTF-8

*CLOS*
GET response:""
=============================
PRbpm : 0 %SPo2 : 0
Temperature (ºC): 44.78
=============================
$$$set ip remote 8080

set opt format 1

set comm remote GET$/test.php?Temperature=44.78&PRbpm=0

open

open

<4.41>

<4.41>
*OPEN*HTTP/1.1 200 OK
Date: Mon, 11 Jun 2018 09:28:44 GMT
Server: Apache/2.4.33 (Win32) OpenSSL/1.1.0h PHP/7.2.5
X-Powered-By: PHP/7.2.5
Content-Length: 0
Connection: close
Content-Type: text/html; charset=UTF-8

*CLOS*
GET response:""
=============================
PRbpm : 0 %SPo2 : 0
Temperature (ºC): 44.93
=============================
$$$set ip remote 8080

set opt format 1

set comm remote GET$/test.php?Temperature=44.93&PRbpm=0

open

open

<4.41>

<4.41>
*OPEN*HTTP/1.1 200 OK
Date: Mon, 11 Jun 2018 09:28:52 GMT
Server: Apache/2.4.33 (Win32) OpenSSL/1.1.0h PHP/7.2.5
X-Powered-By: PHP/7.2.5
Content-Length: 0
Connection: close
Content-Type: text/html; charset=UTF-8

*CLOS*
GET response:""
=============================
PRbpm : 0 %SPo2 : 0
Temperature (ºC): 44.67
=============================
$$$set ip remote 8080

set opt format 1

set comm remote GET$/test.php?Temperature=44.67&PRbpm=0

open

open

<4.41>

<4.41>
*OPEN*HTTP/1.1 200 OK
Date: Mon, 11 Jun 2018 09:29:00 GMT
Server: Apache/2.4.33 (Win32) OpenSSL/1.1.0h PHP/7.2.5
X-Powered-By: PHP/7.2.5
Content-Length: 0
Connection: close
Content-Type: text/html; charset=UTF-8

*CLOS*

Author:  libelium-dev [ Tue Jun 12, 2018 7:55 am ]
Post subject:  Re: e-Health wi-fi module open command

Hi,

We think that it's the time needed for the open command and it isn't possible to decrease that time. Anyway yo can try to develop a simple code where that command is used in order to know the time expend.

Regards

Author:  Seiya [ Tue Jun 19, 2018 8:54 am ]
Post subject:  Re: e-Health wi-fi module open command

Is there an example of that simple code?
Even though I thought myself, I did not understand well.

Author:  libelium-dev [ Wed Jun 20, 2018 10:09 am ]
Post subject:  Re: e-Health wi-fi module open command

Hi,

We mean with simple code to a code to know the time that takes the command. You can use the millis function
https://www.arduino.cc/reference/en/lan ... me/millis/

Anyway, we think that it isn't possible to read and send data each second.

Regards

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/