An embedded server sending sensor information over the network to a remote client side process parsing the data
Dependencies: EthernetInterface NTPClient TimeInterface WebSocketClient mbed-rtos mbed ST_Events-old
Diff: data_logger.cpp
- Revision:
- 3:221997836268
- Parent:
- 2:5c9125d3ddae
- Child:
- 4:a6ff97cfb57a
--- a/data_logger.cpp Fri Jul 21 01:56:38 2017 +0000 +++ b/data_logger.cpp Sat Sep 16 21:05:00 2017 +0000 @@ -10,7 +10,6 @@ time_t timestamp; //Built-in time class instance TCPSocketServer server; TCPSocketConnection client; -RtosTimer periodic_report(&pressure_report), *ppr; EventQueue queue1; EventQueue queue2; Thread t1; @@ -19,7 +18,7 @@ //setup DigitalOut led1(LED1); -AnalogIn pressIn(A0); +AnalogIn strainIn(A0); InterruptIn sig(p5); //RtosTimer Timer(send_payload,osTimerPeriodic); @@ -49,7 +48,7 @@ printf("board is up"); timestamp = time(NULL); - queue1.call_every(RATE,&pressure_report); + queue1.call_every(RATE,&idle_report); t1.start(callback(&queue1, &EventQueue::dispatch_forever)); //Start the thread for periodic basline value reporting sig.rise(queue2.event(&cycle_time_isr_rise)); sig.fall(queue2.event(&cycle_time_isr_fall)); @@ -71,27 +70,33 @@ i++; }*/ //p_press = pressIn.read(); - + p_strain = strainCalc(); //Calculate strain while the machine is crushing } void cycle_time_isr_fall(void) { t.stop(); //Stop the timer cycle_time = t.read(); t.reset(); //reset the timer - sprintf(appbuffer,"<payload><time>%s</time><cy_time>%f</cy_time><p_press>%d</p_press></payload>",time_b.ctime(×tamp), cycle_time, p_press); + sprintf(appbuffer,"<payload><time>%s</time><cy_time>%f</cy_time><p_strain>%f</p_strain></payload>",time_b.ctime(×tamp), cycle_time, p_strain); printf(appbuffer); sprintf(appbuffer,"\0"); //Nullify the string m.unlock(); //Unlock the mutex } -void pressure_report(void) { +void idle_report(void) { m.lock(); //Attempt to lock the mutex here - sprintf(appbuffer,"<payload><time>%s</time><id_press>%d</id_press></payload>",time_b.ctime(×tamp), id_press); + id_strain = strainCalc(); //Calculate strain while the machine is idle + sprintf(appbuffer,"<payload><time>%s</time><id_strain>%f</id_strain></payload>",time_b.ctime(×tamp), id_strain); printf(appbuffer); sprintf(appbuffer,"\0"); //Nullify the buffer m.unlock(); //Unlock the mutex } - + +float strainCalc(void) { + float deltaR = strainIn/CURRENT; //Calculate Delta R + float strain = (1/GAUGE_FACTOR)*(deltaR/NOMINAL_R); //Calculate strain, see equation reference in docs + + return strain; + } -