Juraj:
show the current code and output
sorry for the late reply, i was working on it without success
here's my latest code
#include <LCD5110_Graph.h>
#include <Adafruit_MLX90614.h>
#define DEVICE_ID "Monitor1"
#define DEBUG true
#define REQ_CODE_ACK 1
#define REQ_CODE_VALUES 2
//84w * 48h
LCD5110 myGLCD(8,9,10,12,11);
extern uint8_t SmallFont[]; //8h * 6w font
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
int pinLM35 = A0; //Pin A0 is for LM35
int fsrAnalogPin = A2; //Pin A2 is for force sensor
int blinkPin = 13; // Pin 13 is the on-board LED
String mSSID = "LibyaADSL-9a86"; //initial ssid and password
String mPASS = "BYRTPCRJAHPWQ";
//http request code
int service_code;
//wifi listen variables
String wifiBuf = "";
char character;
int connectionId = 0 ;
//sensor values
float sensor_mlx, sensor_heart, sensor_lm35;
int sensor_force;
void setup() {
//init LCD
myGLCD.InitLCD();
myGLCD.setFont(SmallFont);
randomSeed(analogRead(7));
//init MLX90614
mlx.begin();
//init serial
Serial.begin(115200); //Arduino-PC
Serial3.begin(115200); //Arduino-ESP8266\
//init esp8266
init8266();
pinMode(blinkPin,OUTPUT); // pin that will blink to your heartbeat!
delay(200);
}
//init esp8266
void init8266()
{
Serial.println("Init ESP...");
sendCommand("AT+RST\r\n",2000,DEBUG); // reset module
sendCommand("AT+CWMODE=1\r\n",1000,DEBUG); // configure as access point غيرت 1 لي 3
sendCommand("AT+CWDHCP=1,1\r\n",1000,DEBUG); // HI اني ضفته
sendCommand("AT+CWQAP\r\n",1000,DEBUG); // quit the AP
delay(1000);
sendCommand("AT+CWJAP=\""+ mSSID +"\",\""+ mPASS +"\"",20,"OK"); // join the AP
delay(10000);
sendCommand("AT+CIFSR\r\n",1000,DEBUG); // get ip address
sendCommand("AT+CIPMUX=1\r\n",1000,DEBUG); // configure for multiple connections
sendCommand("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // turn on server on port 80
}
/*
* Name: sendCommand
* Description: Function used to send data to ESP8266.
* Params: command - the data/command to send; timeout - the time to wait for a response; debug - print to Serial window?(true = yes, false = no)
* Returns: The response from the esp8266 (if there is a reponse)
*/
String sendCommand(String command, const int timeout, boolean debug)
{
String response = "";
Serial3.print(command); // send the read character to the esp8266
long int time = millis();
while( (time+timeout) > millis())
{
while(Serial3.available())
{
// The esp has data so display its output to the serial window
char c = Serial3.read(); // read the next character.
response+=c;
}
}
if(debug)
{
Serial.print(response);
}
return response;
}
//Process wifi request
void procWifiRequest(String content)
{
int indexEnd;
int dataSize = content.length();
char data[dataSize];
content.toCharArray(data,dataSize);
Serial.println("-------------------- Received Request --------------------");
Serial.write(data, dataSize);
int index = content.indexOf("+IPD,");
connectionId = content.charAt(index+5) - 48;
index = content.indexOf("action=");
service_code = content.charAt(index+7) - 48;
Serial.println("Service code = " + service_code);
if(service_code == REQ_CODE_VALUES)
{
responseSensors();
}
else
{
String response;
response = "result=ACK";
response += "&id=";
response += DEVICE_ID;
sendHTTPResponse(connectionId,response);
}
}
void responseSensors()
{
Serial.println("Responding Sensors...");
String response;
response = "result=success";
response += "&mlx=";
response += sensor_mlx;
response += "&heartbeart=";
response += sensor_heart;
response += "&lm35=";
response += sensor_lm35;
response += "&pressure=";
response += sensor_force;
sendHTTPResponse(connectionId,response);
}
/*
* Name: sendHTTPResponse
* Description: Function that sends HTTP 200, HTML UTF-8 response
*/
void sendHTTPResponse(int connectionId, String content)
{
// build HTTP response
String httpResponse;
String httpHeader;
// HTTP Header
httpHeader = "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=UTF-8\r\n";
httpHeader += "Content-Length: ";
httpHeader += content.length();
httpHeader += "\r\n";
httpHeader +="Connection: close\r\n\r\n";
httpResponse = httpHeader + content + " "; // There is a bug in this code: the last character of "content" is not sent, I cheated by adding this extra space
sendCIPData(connectionId,httpResponse);
}
/*
* Name: sendCIPDATA
* Description: sends a CIPSEND=<connectionId>,<data> command
*
*/
void sendCIPData(int connectionId, String data)
{
String cipSend = "AT+CIPSEND=";
cipSend += connectionId;
cipSend += ",";
cipSend +=data.length();
cipSend +="\r\n";
sendCommand(cipSend,1000,DEBUG);
sendData(data,1000,DEBUG);
}
String sendData(String command, const int timeout, boolean debug)
{
String response = "";
int dataSize = command.length();
char data[dataSize];
command.toCharArray(data,dataSize);
Serial3.write(data,dataSize); // send the read character to the esp8266
if(debug)
{
Serial.println("\r\n====== HTTP Response From Arduino ======");
Serial.write(data,dataSize);
Serial.println("\r\n========================================");
}
long int time = millis();
while( (time+timeout) > millis())
{
while(Serial3.available())
{
// The esp has data so display its output to the serial window
char c = Serial3.read(); // read the next character.
response+=c;
}
}
if(debug)
{
Serial.print(response);
}
return response;
}
void loop() {
//Listen http reques while(Serial3.available())
while(Serial3.available()){
character = Serial3.read();
wifiBuf.concat(character);
}
if (wifiBuf != "")
{
wifiBuf.trim();
if(wifiBuf.indexOf("action=") > 0)
{
if (wifiBuf.indexOf("action=2") > 0)
{
responseSensors();
}
else
{
procWifiRequest(wifiBuf);
}
wifiBuf.remove(0);
}
}
//read sensors
sensor_mlx = mlx.readObjectTempC();
int val = analogRead(pinLM35);
float mv = (val*500)/1023;
sensor_lm35 = mv;
/*vout=analogRead(sensor); //Reading the value from sensor
vout=(vout*500)/1023;
tempc=vout; // Storing value in Degree Celsius*/
sensor_heart = 80;
sensor_force = analogRead(fsrAnalogPin);
//display values
myGLCD.print("MLX:", LEFT, 0);
myGLCD.printNumF(sensor_mlx, 1, 6*5, 0);
myGLCD.print("°C", RIGHT, 0);
myGLCD.print("LM35:", LEFT, 8);
myGLCD.printNumF(sensor_lm35, 1, 6*6, 8);
myGLCD.print("°C", RIGHT, 8);
myGLCD.print("HEART:", LEFT, 0);
myGLCD.printNumF(sensor_heart, 1, 6*7, 16);
myGLCD.print("BPM", RIGHT, 0);
myGLCD.update();
delay(50);
}
and here's the output