BME280 mbed i2c

Dependencies:   EthernetInterface HTTPClient mbed-rtos mbed

Fork of php_access by shinichi satoh

Committer:
thursday1024
Date:
Thu Jul 28 22:55:30 2016 +0000
Revision:
2:7cf2ef9c51da
Parent:
1:3c8fcecce568
BME280 I2C

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thursday1024 2:7cf2ef9c51da 1 // php_acces main.cpp
thursday1024 2:7cf2ef9c51da 2
thursday1024 2:7cf2ef9c51da 3 #include "mbed.h"
thursday1024 2:7cf2ef9c51da 4 #include "BME280.h"
thursday1024 2:7cf2ef9c51da 5 #include "EthernetInterface.h"
thursday1024 2:7cf2ef9c51da 6 #include "HTTPClient.h"
thursday1024 2:7cf2ef9c51da 7 #define BUFF_SIZE 128
thursday1024 2:7cf2ef9c51da 8
thursday1024 2:7cf2ef9c51da 9 extern void php_access_main( char *uri, char *ch_name, int* sp );
thursday1024 2:7cf2ef9c51da 10 char php_uri[]="https://alpha.c.dendai.ac.jp/plot/save_data.php";
thursday1024 2:7cf2ef9c51da 11
thursday1024 2:7cf2ef9c51da 12 //char ch_str[] ="ch13894";
thursday1024 2:7cf2ef9c51da 13 char ch_str[] ="ch1389400";
thursday1024 2:7cf2ef9c51da 14
thursday1024 2:7cf2ef9c51da 15
thursday1024 2:7cf2ef9c51da 16 extern HTTPClient http;
thursday1024 2:7cf2ef9c51da 17 EthernetInterface eth;
thursday1024 2:7cf2ef9c51da 18
thursday1024 2:7cf2ef9c51da 19 static int speed=0;
thursday1024 2:7cf2ef9c51da 20 void thread_main( void const *av ){
thursday1024 2:7cf2ef9c51da 21 char ch_name[BUFF_SIZE];
thursday1024 2:7cf2ef9c51da 22 strcpy( ch_name, ch_str );
thursday1024 2:7cf2ef9c51da 23 printf( "Channel Name:%s\n", ch_name );
thursday1024 2:7cf2ef9c51da 24
thursday1024 2:7cf2ef9c51da 25 php_access_main( php_uri, ch_name, &speed ); //
thursday1024 2:7cf2ef9c51da 26
thursday1024 2:7cf2ef9c51da 27 while(true) Thread::wait(1000);
thursday1024 2:7cf2ef9c51da 28 }
thursday1024 2:7cf2ef9c51da 29
thursday1024 2:7cf2ef9c51da 30 // memo
thursday1024 2:7cf2ef9c51da 31 // R-LED -> LED1; G-LED -> LED2; B-LED -> LED3;
thursday1024 2:7cf2ef9c51da 32 // sw3 -> PTA4; sw2 -> PTC6;
thursday1024 2:7cf2ef9c51da 33
thursday1024 2:7cf2ef9c51da 34 DigitalOut my_LED0(LED1);
thursday1024 2:7cf2ef9c51da 35 DigitalOut my_LED1(LED3);
thursday1024 2:7cf2ef9c51da 36 DigitalOut my_LED2(LED2);
thursday1024 2:7cf2ef9c51da 37 DigitalIn my_sw0(PTA4);
thursday1024 2:7cf2ef9c51da 38 DigitalIn my_sw1(PTC6);
thursday1024 2:7cf2ef9c51da 39
thursday1024 2:7cf2ef9c51da 40 #if defined(TARGET_LPC1768)
thursday1024 2:7cf2ef9c51da 41 BME280 sensor(p28, p27);
thursday1024 2:7cf2ef9c51da 42 #else
thursday1024 2:7cf2ef9c51da 43 BME280 sensor(I2C_SDA, I2C_SCL);
thursday1024 2:7cf2ef9c51da 44 #endif
thursday1024 2:7cf2ef9c51da 45
thursday1024 2:7cf2ef9c51da 46 int main() {
thursday1024 2:7cf2ef9c51da 47
thursday1024 2:7cf2ef9c51da 48
thursday1024 2:7cf2ef9c51da 49 //while(1) {
thursday1024 2:7cf2ef9c51da 50 // printf("hoge test = %2.2f degC, %04.2f hPa, %2.2f %%\n", sensor.getTemperature(), sensor.getPressure(), sensor.getHumidity());
thursday1024 2:7cf2ef9c51da 51 // wait(1);
thursday1024 2:7cf2ef9c51da 52 //}
thursday1024 2:7cf2ef9c51da 53
thursday1024 2:7cf2ef9c51da 54
thursday1024 2:7cf2ef9c51da 55
thursday1024 2:7cf2ef9c51da 56
thursday1024 2:7cf2ef9c51da 57
thursday1024 2:7cf2ef9c51da 58 my_LED0=1;
thursday1024 2:7cf2ef9c51da 59 my_LED1=1;
thursday1024 2:7cf2ef9c51da 60 Timer t;
thursday1024 2:7cf2ef9c51da 61 t.start();
thursday1024 2:7cf2ef9c51da 62
thursday1024 2:7cf2ef9c51da 63 int ret = eth.init(); //Use DHCP
thursday1024 2:7cf2ef9c51da 64 printf( "php_test Starting,...\n" ) ;
thursday1024 2:7cf2ef9c51da 65 while(1) {
thursday1024 2:7cf2ef9c51da 66 ret = eth.connect();
thursday1024 2:7cf2ef9c51da 67 if( ret==0 )break ; // DHCP OK
thursday1024 2:7cf2ef9c51da 68 Thread::wait( 100 );
thursday1024 2:7cf2ef9c51da 69 }
thursday1024 2:7cf2ef9c51da 70 t.stop();
thursday1024 2:7cf2ef9c51da 71 srand(t.read_ms());
thursday1024 2:7cf2ef9c51da 72
thursday1024 2:7cf2ef9c51da 73 printf( "IP = %s\n", eth.getIPAddress() );
thursday1024 2:7cf2ef9c51da 74
thursday1024 2:7cf2ef9c51da 75 #define STACK_SIZE 20000
thursday1024 2:7cf2ef9c51da 76 Thread thr( thread_main, NULL, osPriorityNormal, STACK_SIZE );
thursday1024 2:7cf2ef9c51da 77 speed=0;
thursday1024 2:7cf2ef9c51da 78 int i=0;
thursday1024 2:7cf2ef9c51da 79 //double tmp;
thursday1024 2:7cf2ef9c51da 80 while(true){
thursday1024 2:7cf2ef9c51da 81 speed = sensor.getTemperature()*100,
thursday1024 2:7cf2ef9c51da 82
thursday1024 2:7cf2ef9c51da 83 /* printf("hoge test = %2.2f degC, %04.2f hPa, %2.2f %%\n",
thursday1024 2:7cf2ef9c51da 84 tmp,
thursday1024 2:7cf2ef9c51da 85 sensor.getPressure(),
thursday1024 2:7cf2ef9c51da 86 sensor.getHumidity());
thursday1024 2:7cf2ef9c51da 87 speed = tmp*100;
thursday1024 2:7cf2ef9c51da 88 */
thursday1024 2:7cf2ef9c51da 89
thursday1024 2:7cf2ef9c51da 90
thursday1024 2:7cf2ef9c51da 91 /* if(!my_sw0 && speed<=0)speed++;
thursday1024 2:7cf2ef9c51da 92 if(!my_sw1 && speed>=0)speed--;
thursday1024 2:7cf2ef9c51da 93 if(speed>0 ){my_LED0=0;my_LED1=1;my_LED2=1;}
thursday1024 2:7cf2ef9c51da 94 if(speed<0 ){my_LED0=1;my_LED1=0;my_LED2=1;}
thursday1024 2:7cf2ef9c51da 95 if(speed==0){my_LED0=1;my_LED1=1;my_LED2=0;}
thursday1024 2:7cf2ef9c51da 96 speed = (rand()%3)-1;
thursday1024 2:7cf2ef9c51da 97 */
thursday1024 2:7cf2ef9c51da 98
thursday1024 2:7cf2ef9c51da 99 Thread::wait(1000);
thursday1024 2:7cf2ef9c51da 100 i++;
thursday1024 2:7cf2ef9c51da 101 }
thursday1024 2:7cf2ef9c51da 102 }
thursday1024 2:7cf2ef9c51da 103
thursday1024 2:7cf2ef9c51da 104