Thermometer connected to internet

Dependencies:   BME280 EthernetInterface FXOS8700Q HTTPClient-wolfSSL NTPClient NetworkAPI OAuth4Tw TSL2561_I2C eCompass_FPU_Lib mbed-rtos mbed wolfSSL

Fork of TCP_Server_Example by Roy van Dam

Committer:
zeus3110
Date:
Sun Sep 27 11:04:54 2015 +0000
Revision:
12:12369ee344ab
Network thermometer test program

Who changed what in which revision?

UserRevisionLine numberNew contents of line
zeus3110 12:12369ee344ab 1 #include "mbed.h"
zeus3110 12:12369ee344ab 2 #include "FXOS8700Q.h"
zeus3110 12:12369ee344ab 3 #include "eCompass_Lib.h"
zeus3110 12:12369ee344ab 4 #include "rtos.h"
zeus3110 12:12369ee344ab 5 //#include "MotionSensorDtypes.h"
zeus3110 12:12369ee344ab 6
zeus3110 12:12369ee344ab 7
zeus3110 12:12369ee344ab 8 FXOS8700Q_acc acc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1);
zeus3110 12:12369ee344ab 9 FXOS8700Q_mag mag( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1);
zeus3110 12:12369ee344ab 10
zeus3110 12:12369ee344ab 11 DigitalOut gpo(D0);
zeus3110 12:12369ee344ab 12 DigitalOut led(LED_RED);
zeus3110 12:12369ee344ab 13 eCompass compass;
zeus3110 12:12369ee344ab 14
zeus3110 12:12369ee344ab 15 //void calibrate_thread(void const *argument);
zeus3110 12:12369ee344ab 16 //void print_thread(void const *argument);
zeus3110 12:12369ee344ab 17 //void compass_thread(void const *argument);
zeus3110 12:12369ee344ab 18
zeus3110 12:12369ee344ab 19
zeus3110 12:12369ee344ab 20
zeus3110 12:12369ee344ab 21 extern axis6_t axis6;
zeus3110 12:12369ee344ab 22 extern uint32_t seconds;
zeus3110 12:12369ee344ab 23 extern uint32_t compass_type; // optional, NED compass is default
zeus3110 12:12369ee344ab 24 extern int32_t tcount;
zeus3110 12:12369ee344ab 25 extern uint8_t cdebug;
zeus3110 12:12369ee344ab 26 int l = 0;
zeus3110 12:12369ee344ab 27 volatile int sflag = 0;
zeus3110 12:12369ee344ab 28
zeus3110 12:12369ee344ab 29 MotionSensorDataCounts mag_raw;
zeus3110 12:12369ee344ab 30 MotionSensorDataCounts acc_raw;
zeus3110 12:12369ee344ab 31
zeus3110 12:12369ee344ab 32 void hal_map( MotionSensorDataCounts * acc_raw, MotionSensorDataCounts * mag_raw)
zeus3110 12:12369ee344ab 33 {
zeus3110 12:12369ee344ab 34 int16_t t;
zeus3110 12:12369ee344ab 35 // swap and negate X & Y axis
zeus3110 12:12369ee344ab 36 t = acc_raw->x;
zeus3110 12:12369ee344ab 37 acc_raw->x = acc_raw->y * -1;
zeus3110 12:12369ee344ab 38 acc_raw->y = t * -1;
zeus3110 12:12369ee344ab 39 // swap mag X & Y axis
zeus3110 12:12369ee344ab 40 t = mag_raw->x;
zeus3110 12:12369ee344ab 41 mag_raw->x = mag_raw->y;
zeus3110 12:12369ee344ab 42 mag_raw->y = t;
zeus3110 12:12369ee344ab 43 // negate mag Z axis
zeus3110 12:12369ee344ab 44 mag_raw->z *= -1;
zeus3110 12:12369ee344ab 45 }
zeus3110 12:12369ee344ab 46
zeus3110 12:12369ee344ab 47 //
zeus3110 12:12369ee344ab 48 // Print data values for debug
zeus3110 12:12369ee344ab 49 //
zeus3110 12:12369ee344ab 50 void debug_print(void)
zeus3110 12:12369ee344ab 51 {
zeus3110 12:12369ee344ab 52 // Some useful printf statements for debug
zeus3110 12:12369ee344ab 53 printf("roll=%d, pitch=%d, yaw=%d\r\n", axis6.roll, axis6.pitch, axis6.yaw);
zeus3110 12:12369ee344ab 54 printf("Acc: X= %2.3f Y= %2.3f Z= %2.3f ", axis6.fGax, axis6.fGay, axis6.fGaz);
zeus3110 12:12369ee344ab 55 printf("Mag: X= %4.1f Y= %4.1f Z= %4.1f\r\n\r\n", axis6.fUTmx, axis6.fUTmy, axis6.fUTmz);
zeus3110 12:12369ee344ab 56 printf("Quaternion: Q0= %1.4f Q1= %1.4f Q2= %1.4f Q3= %1.4f\r\n\r\n", axis6.q0, axis6.q1, axis6.q2, axis6.q3);
zeus3110 12:12369ee344ab 57 }
zeus3110 12:12369ee344ab 58
zeus3110 12:12369ee344ab 59
zeus3110 12:12369ee344ab 60 void compass_thread(void const *argument) {
zeus3110 12:12369ee344ab 61
zeus3110 12:12369ee344ab 62 // get raw data from the sensors
zeus3110 12:12369ee344ab 63 acc.getAxis( acc_raw);
zeus3110 12:12369ee344ab 64 mag.getAxis( mag_raw);
zeus3110 12:12369ee344ab 65 if(tcount) compass.run( acc_raw, mag_raw); // calculate the eCompass
zeus3110 12:12369ee344ab 66 if(l++ >= 50) { // take car of business once a second
zeus3110 12:12369ee344ab 67 seconds++;
zeus3110 12:12369ee344ab 68 sflag = 1;
zeus3110 12:12369ee344ab 69 compass.calibrate();
zeus3110 12:12369ee344ab 70 debug_print();
zeus3110 12:12369ee344ab 71 l = 0;
zeus3110 12:12369ee344ab 72 led = !led;
zeus3110 12:12369ee344ab 73 }
zeus3110 12:12369ee344ab 74 tcount++;
zeus3110 12:12369ee344ab 75 }
zeus3110 12:12369ee344ab 76
zeus3110 12:12369ee344ab 77 /*
zeus3110 12:12369ee344ab 78 void calibrate_thread(void const *argument) {
zeus3110 12:12369ee344ab 79 while (true) {
zeus3110 12:12369ee344ab 80 // Signal flags that are reported as event are automatically cleared.
zeus3110 12:12369ee344ab 81 Thread::signal_wait(0x1);
zeus3110 12:12369ee344ab 82 compass.calibrate(); // re-calibrate the eCompass every second
zeus3110 12:12369ee344ab 83 }
zeus3110 12:12369ee344ab 84 }
zeus3110 12:12369ee344ab 85
zeus3110 12:12369ee344ab 86
zeus3110 12:12369ee344ab 87
zeus3110 12:12369ee344ab 88 void print_thread(void const *argument) {
zeus3110 12:12369ee344ab 89 while (true) {
zeus3110 12:12369ee344ab 90 // Signal flags that are reported as event are automatically cleared.
zeus3110 12:12369ee344ab 91 Thread::signal_wait(0x1);
zeus3110 12:12369ee344ab 92 debug_print(); // re-calibrate the eCompass every second
zeus3110 12:12369ee344ab 93 }
zeus3110 12:12369ee344ab 94 }
zeus3110 12:12369ee344ab 95 */
zeus3110 12:12369ee344ab 96
zeus3110 12:12369ee344ab 97 int compass_main() {
zeus3110 12:12369ee344ab 98
zeus3110 12:12369ee344ab 99
zeus3110 12:12369ee344ab 100 RtosTimer compass_timer(compass_thread, osTimerPeriodic);
zeus3110 12:12369ee344ab 101
zeus3110 12:12369ee344ab 102 //cdebug = 1; // uncomment to disable compass
zeus3110 12:12369ee344ab 103 printf("\r\n\n\n\n\n\n\n");
zeus3110 12:12369ee344ab 104 printf("Who AM I= %X\r\n", acc.whoAmI());
zeus3110 12:12369ee344ab 105 acc.enable();
zeus3110 12:12369ee344ab 106
zeus3110 12:12369ee344ab 107
zeus3110 12:12369ee344ab 108 acc.getAxis( acc_raw);
zeus3110 12:12369ee344ab 109 mag.getAxis( mag_raw);
zeus3110 12:12369ee344ab 110
zeus3110 12:12369ee344ab 111 compass_timer.start(20); // Run the Compass every 20ms
zeus3110 12:12369ee344ab 112 while(1) {
zeus3110 12:12369ee344ab 113 Thread::wait(osWaitForever);
zeus3110 12:12369ee344ab 114 }
zeus3110 12:12369ee344ab 115 }