Post a new topicPost a reply Page 1 of 1   [ 4 posts ]
Author Message
 Post subject: WFi module and UART sensors
PostPosted: Thu Jun 08, 2017 12:56 pm 

Joined: Wed Apr 26, 2017 10:45 am
Posts: 27
Good morning

I'm working with mySignals HW on my final project study. So i have to test all the features of MySignals.

I'm trying to send data of spirometer sensor to my server. Both modules (WiFi and spiromenter sensor) use the UART.
So i tried to use WiFi Sleep mode while measuring spirometer data and exiting Sleep mode for using WiFi. I have changed the code that you provided in The topic ECG Problems in the forum. As a result there is no data of spirometer.


#include <MySignals.h>
#include "Wire.h"
#include "SPI.h"

int8_t answer;

unsigned long previous = 0;

void setup() {
Serial.begin(115200);
MySignals.begin();

MySignals.println("Starting...");
MySignals.initSensorUART();
MySignals.enableSensorUART(WIFI);
delay(1000);
// Checks if the WiFi module is started
answer = sendATcommand("AT", "OK", 2000);
if (answer == 0)
{
MySignals.println("Error");
// waits for an answer from the module
while (answer == 0)
{
// Send AT every two seconds and wait for the answer
answer = sendATcommand("AT", "OK", 2000);
}
}
else if (answer == 1)
{
MySignals.println("WiFi succesfully working!");
if (sendATcommand("AT+CWMODE=1", "OK", 6000))
{
MySignals.println("AT+CWMODE=1 OK");
}
else {
MySignals.println("AT+CWMODE=1 Error");

}
if (sendATcommand("AT+CWJAP=\"dlink\",\"\"", "OK", 20000))
{
MySignals.println("Successfully connected!");
}

else {
MySignals.println("Error");

}
}
}

void loop()
{
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
// Enter 10 seconds WiFi Sleep mode for Spirometer measurement //
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////

answer = sendATcommand("AT+SLEEP=2", "OK", 6000);
if (answer == 0)
{
MySignals.println("AT+SLEEP=2 Error");
}
else if (answer == 1)
{
MySignals.println("AT+SLEEP=2 OK");
}

previous = millis();
while (((millis() - previous) < 10000))
{
MySignals.enableSensorUART(SPIROMETER);


while (MySignals.getStatusSpiro() == 0)
{
delay(50);
}
MySignals.getSpirometer();
uint16_t spir=MySignals.spirometerData[MySignals.spir_measures - 1].spir_pef;
}

delay(2000);




///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
// Exit 10 seconds WiFi Sleep mode for Spirometer measurement //
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////

answer = sendATcommand("AT+SLEEP=0", "OK", 6000);
if (answer == 0)
{
MySignals.println("AT+SLEEP=0 Error");
}
else if (answer == 1)
{

MySignals.println("AT+SLEEP=0 OK");

if( sendATcommand("AT+CIPSTART=\"TCP\",\"192.168.1.34\",3000", "OK", 20000))

{
MySignals.println("TCP connection ready");

previous = millis();
while (((millis() - previous) < 10000))
{
MySignals.enableSensorUART(SPIROMETER);


while (MySignals.getStatusSpiro() == 0)
{
delay(50);
}
MySignals.getSpirometer();
uint16_t spir=MySignals.spirometerData[MySignals.spir_measures - 1].spir_pef;



String toSend=String(spir);
int len =toSend.length();
String length_toSend=String(len);
String cmd="AT+CIPSEND=";
cmd+=length_toSend;
sendATcommand(cmd,"OK",20000);
sendATcommand(toSend,"OK",20000);
sendATcommand("AT+CIPCLOSE","OK",20000);
}
}
else{
MySignals.println("can't establish TCP connection");

}
}


delay(2000);





}


int8_t sendATcommand(String ATcommand, char* expected_answer1, unsigned int timeout)
{

uint8_t x = 0, answer = 0;
char response[500];
unsigned long previous;

memset(response, '\0', 100); // Initialize the string

delay(100);

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

delay(1000);
Serial.println(ATcommand); // Send the AT command


x = 0;
previous = millis();

// this loop waits for the answer
do {

if (Serial.available() != 0) {
response[x] = Serial.read();
x++;
// check if the desired answer is in the response of the module
if (strstr(response, expected_answer1) != NULL)
{
answer = 1;
//Serial.print("Received: ");
MySignals.println(response);

}
}
// Waits for the asnwer with time out
}
while ((answer == 0) && ((millis() - previous) < timeout));

return answer;
}



I would be happy if you could help me. Thank you.

With kind regards,


Top
 Profile  
 
 Post subject: Re: WFi module and UART sensors
PostPosted: Fri Jun 09, 2017 6:31 am 

Joined: Mon Sep 28, 2009 11:06 am
Posts: 10492
Hello Nour_Neifar,

there is no need of using WiFi Sleep mode in your case. We recommend this mode with ECG because the connected wifi affected the sensitive measurement of the ECG, but it is not your case.

You can write a simpler code using this functions:

Code:
MySignals.enableSensorUART(WIFI_ESP8266);
MySignals.enableSensorUART(SPIROMETER);


Are you using MySignals HW V1 or V2?

Regards


Top
 Profile  
 
 Post subject: Re: WFi module and UART sensors
PostPosted: Fri Jun 09, 2017 9:44 am 

Joined: Wed Apr 26, 2017 10:45 am
Posts: 27
Good morning,

I'm working with mySignals HW V1.


Top
 Profile  
 
 Post subject: Re: WFi module and UART sensors
PostPosted: Mon Jun 12, 2017 7:31 am 

Joined: Mon Sep 28, 2009 11:06 am
Posts: 10492
Hello Nour_Neifar,

then you must use V.1.0.2 library:

http://www.cooking-hacks.com/media/cook ... V1.0.2.zip

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.