use Dussolved_oxygen_sensor_on_wifi

Dependencies:   watersenor_and_temp_code MQTT NetworkSocketAPI X_NUCLEO_IDW01M1v2 mbed

Fork of DS1820_IDW01M1 by CHANG rozen

Committer:
e58136782000
Date:
Wed Nov 08 06:22:19 2017 +0000
Revision:
7:8eaef8890eee
Parent:
5:42113ea1b319
turbid sensor online;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rozendhyan@gmail.com 0:80c7778c82b8 1 #include "mbed.h"
rozendhyan@gmail.com 0:80c7778c82b8 2 #ifndef BME280_HPP
rozendhyan@gmail.com 0:80c7778c82b8 3 #define BME280_HPP
rozendhyan@gmail.com 0:80c7778c82b8 4
e58136782000 7:8eaef8890eee 5 #define BME280_size 6
rozendhyan@gmail.com 0:80c7778c82b8 6
e58136782000 5:42113ea1b319 7 Serial sensor(PA_11,PA_12);// Tx,Rx
rozendhyan@gmail.com 0:80c7778c82b8 8 Serial pc(USBTX,USBRX);
rozendhyan@gmail.com 0:80c7778c82b8 9 class BME280{
rozendhyan@gmail.com 0:80c7778c82b8 10 public:
rozendhyan@gmail.com 0:80c7778c82b8 11 void judgement_data(char buf[]);
e58136782000 5:42113ea1b319 12 int data_read();
rozendhyan@gmail.com 0:80c7778c82b8 13
e58136782000 5:42113ea1b319 14 int datareadfuiction(int data);
e58136782000 5:42113ea1b319 15 void receive();
rozendhyan@gmail.com 0:80c7778c82b8 16 private:
e58136782000 5:42113ea1b319 17 char buf[BME280_size];
rozendhyan@gmail.com 0:80c7778c82b8 18 void send_AT();
e58136782000 5:42113ea1b319 19
e58136782000 5:42113ea1b319 20 int data;
rozendhyan@gmail.com 0:80c7778c82b8 21
rozendhyan@gmail.com 0:80c7778c82b8 22 };
e58136782000 5:42113ea1b319 23 int BME280::datareadfuiction(int data)
e58136782000 5:42113ea1b319 24 {
e58136782000 5:42113ea1b319 25 return buf[data];
e58136782000 5:42113ea1b319 26 }
e58136782000 5:42113ea1b319 27 void BME280::judgement_data(char buf[])
e58136782000 5:42113ea1b319 28 {
e58136782000 5:42113ea1b319 29 // int i=0;
e58136782000 5:42113ea1b319 30
e58136782000 5:42113ea1b319 31 /* if(buf[i++]== 0x5A){
rozendhyan@gmail.com 0:80c7778c82b8 32 //pc.printf("first_step\n");
rozendhyan@gmail.com 0:80c7778c82b8 33 if(buf[i++]== 0x5A){
rozendhyan@gmail.com 0:80c7778c82b8 34 //pc.printf("second_step\n");
rozendhyan@gmail.com 0:80c7778c82b8 35 //i++;//go to data type
rozendhyan@gmail.com 0:80c7778c82b8 36 if(buf[i] == 0x15){
rozendhyan@gmail.com 0:80c7778c82b8 37 //pc.printf("Lux type\n");
rozendhyan@gmail.com 0:80c7778c82b8 38 i++;//04
rozendhyan@gmail.com 0:80c7778c82b8 39 Lux = ((buf[i+1]<<24) | (buf[i+2]<<16) | (buf[i+3]<<8) | buf[i+4])/100;
rozendhyan@gmail.com 0:80c7778c82b8 40 //Lux = (0x00<<24) | (0x00<<16) | (0xFE<<8) | 0x40;//test
rozendhyan@gmail.com 0:80c7778c82b8 41 //pc.printf("Lux = %d\n", Lux);
rozendhyan@gmail.com 0:80c7778c82b8 42 }else if(buf[i] == 0x45){
rozendhyan@gmail.com 0:80c7778c82b8 43 //pc.printf("temp type\n");
rozendhyan@gmail.com 0:80c7778c82b8 44 i++;//0A
rozendhyan@gmail.com 0:80c7778c82b8 45 Temp = ((buf[i+1]<<8)|(buf[i+2]))/100;
rozendhyan@gmail.com 0:80c7778c82b8 46 Preesure = ((buf[i+3]<<24)|(buf[i+4]<<16)|(buf[i+5]<<8)|(buf[i+6]))/100;
rozendhyan@gmail.com 0:80c7778c82b8 47 Hum = ((buf[i+7]<<8)|(buf[i+8]))/100;
rozendhyan@gmail.com 0:80c7778c82b8 48 Height = ((buf[i+9]<<8)|(buf[i+10]));
rozendhyan@gmail.com 0:80c7778c82b8 49 //pc.printf("Temp = %d\n", Temp);
rozendhyan@gmail.com 0:80c7778c82b8 50 //pc.printf("Preesure = %d\n", Preesure);
rozendhyan@gmail.com 0:80c7778c82b8 51 //pc.printf("Hum = %d\n", Hum);
rozendhyan@gmail.com 0:80c7778c82b8 52 //pc.printf("Height = %d\n", Height);
rozendhyan@gmail.com 0:80c7778c82b8 53 }
rozendhyan@gmail.com 0:80c7778c82b8 54 }
e58136782000 5:42113ea1b319 55 }*/
rozendhyan@gmail.com 0:80c7778c82b8 56 }
e58136782000 3:30d9b8d9adc9 57 void BME280::receive()
e58136782000 3:30d9b8d9adc9 58 {
e58136782000 5:42113ea1b319 59 pc.printf("start receive \n");
e58136782000 5:42113ea1b319 60 for(int i=0;i<BME280_size;i++)
e58136782000 5:42113ea1b319 61 {
e58136782000 7:8eaef8890eee 62 sensor.gets(buf,9);
rozendhyan@gmail.com 0:80c7778c82b8 63 }
rozendhyan@gmail.com 0:80c7778c82b8 64
rozendhyan@gmail.com 0:80c7778c82b8 65 }
e58136782000 5:42113ea1b319 66
e58136782000 5:42113ea1b319 67 int BME280::data_read()
e58136782000 5:42113ea1b319 68 {
rozendhyan@gmail.com 0:80c7778c82b8 69 receive();
rozendhyan@gmail.com 0:80c7778c82b8 70 //wait(0.2);
rozendhyan@gmail.com 0:80c7778c82b8 71 judgement_data(this->buf);
rozendhyan@gmail.com 0:80c7778c82b8 72
e58136782000 5:42113ea1b319 73 return data;
rozendhyan@gmail.com 0:80c7778c82b8 74 }
rozendhyan@gmail.com 0:80c7778c82b8 75
rozendhyan@gmail.com 0:80c7778c82b8 76 #endif