ESP8266 and nRF51822 simple WiFi connection and temperature publishing to a socket server.
Dependencies: BLE_API DnsQuery ESP8266Interface NetworkSocketAPI mbed nRF51822
Fork of BLE_TemperatureBeacon by
temp.cpp@6:d5f97e422fed, 2015-08-29 (annotated)
- Committer:
- kixorz
- Date:
- Sat Aug 29 21:58:02 2015 +0000
- Revision:
- 6:d5f97e422fed
wifi
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kixorz | 6:d5f97e422fed | 1 | #include "mbed.h" |
kixorz | 6:d5f97e422fed | 2 | #include <math.h> |
kixorz | 6:d5f97e422fed | 3 | AnalogIn thermistor(P0_3); |
kixorz | 6:d5f97e422fed | 4 | |
kixorz | 6:d5f97e422fed | 5 | int beta = 3975; |
kixorz | 6:d5f97e422fed | 6 | float temperature, resistance; |
kixorz | 6:d5f97e422fed | 7 | |
kixorz | 6:d5f97e422fed | 8 | float getTemp() { |
kixorz | 6:d5f97e422fed | 9 | unsigned int a = thermistor.read_u16(); /* Read analog value 16 bit 65536*/ |
kixorz | 6:d5f97e422fed | 10 | |
kixorz | 6:d5f97e422fed | 11 | /* Calculate the resistance of the thermistor from analog votage read. positive feedback 100k to ground 10 bit ADC*/ |
kixorz | 6:d5f97e422fed | 12 | resistance= (float) 100000.0 * ((1023.0 / a) - 1.0); |
kixorz | 6:d5f97e422fed | 13 | |
kixorz | 6:d5f97e422fed | 14 | /* Convert the resistance to temperature using Steinhart's Hart equation */ |
kixorz | 6:d5f97e422fed | 15 | temperature=(1/((log(resistance/100000.0)/beta) + (1.0/298.15)))-273.15; |
kixorz | 6:d5f97e422fed | 16 | return temperature; |
kixorz | 6:d5f97e422fed | 17 | } |