diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server/main.c | 38 | ||||
-rw-r--r-- | src/tempmodule/main.ino | 29 |
2 files changed, 9 insertions, 58 deletions
diff --git a/src/server/main.c b/src/server/main.c index 737d694..11581ae 100644 --- a/src/server/main.c +++ b/src/server/main.c @@ -36,8 +36,7 @@ static void init(const unsigned int port, int *sock); static int getpacket(char *data, size_t buffsize, int *sock, struct sockaddr_in *sender); static void draw_idle(void); static void draw_busy(const char * const data); -static float digest_mpu_temp(const short int rawdata); -static float digest_thermistor_temp(const short int rawdata); +static float digest_temp(const short int rawdata); int main(void) { @@ -136,59 +135,40 @@ static void draw_idle(void) printw("sequence: [waiting for ESP8266...]"); move(1, 0); clrtoeol(); - mvprintw(1, 0, "mpu temp: [waiting for ESP8266...]"); + mvprintw(1, 0, "thermistor temp: [waiting for ESP8266...]"); move(2, 0); clrtoeol(); - mvprintw(2, 0, "thermistor temp: [waiting for ESP8266...]"); - move(3, 0); - clrtoeol(); - mvprintw(3, 0, "press 'q' to exit"); + mvprintw(2, 0, "press 'q' to exit"); refresh(); } static void draw_busy(const char * const data) { unsigned int sequence; - short int mpu_data; short int thermistor_data; - float mpu_temp; - float thermistor_temp; + float temp; memcpy(&sequence, data + 2, sizeof(sequence)); - memcpy(&mpu_data, data + 6, sizeof(mpu_data)); - memcpy(&thermistor_data, data + 8, sizeof(thermistor_data)); - mpu_temp = digest_mpu_temp(mpu_data); - thermistor_temp = digest_thermistor_temp(thermistor_data); + memcpy(&thermistor_data, data + 6, sizeof(thermistor_data)); + temp = digest_temp(thermistor_data); move(0, 0); clrtoeol(); printw("sequence: %u", sequence); move(1, 0); clrtoeol(); - mvprintw(1, 0, "mpu temp: %.3fC", mpu_temp); + mvprintw(1, 0, "thermistor temp: %.1fC", temp); move(2, 0); clrtoeol(); - mvprintw(2, 0, "thermistor temp: %.1fC", thermistor_temp); - move(3, 0); - clrtoeol(); - mvprintw(3, 0, "press 'q' to exit"); + mvprintw(2, 0, "press 'q' to exit"); refresh(); } -static float digest_mpu_temp(const short int rawdata) -{ - float ret; - - ret = rawdata / 340.0f + 36.53f; - - return ret; -} - /* * raw data is in 0.1°K per 1. Subtract 2730 to get Celsius. * Multiply by 0.1f (divide by 10) to get the correct scale. */ -static float digest_thermistor_temp(const short int rawdata) +static float digest_temp(const short int rawdata) { float ret; diff --git a/src/tempmodule/main.ino b/src/tempmodule/main.ino index e60b6e9..092cca8 100644 --- a/src/tempmodule/main.ino +++ b/src/tempmodule/main.ino @@ -20,7 +20,6 @@ #include <ESP8266WiFi.h> #include <WiFiUdp.h> -#include <Wire.h> #include <stddef.h> #include <string.h> #include <inttypes.h> @@ -33,7 +32,6 @@ struct temptuple { static const unsigned int iled = D4; static const unsigned int analog = A0; static const int port = 2191; -static const int mpu_addr = 0x68; static const int splitter_res = 4699; static char udppacketbuffer[32] = {0}; static char *udppacketcursor = NULL; @@ -44,7 +42,6 @@ static void sleep(void); static void udp_init_packet(IPAddress ip, const int port); static void udp_push(const void * const data, const size_t size); static int udp_flush(void); -static void mpu_wakeup(const int i2caddr); static void wifi_connect(const char * const ssid, const char * const password, const char doblink, const int ledpin); static void blink_led(const int pin, const int ontime, const int offtime); static void discover_client(void); @@ -60,8 +57,6 @@ void setup(void) pinMode(iled, OUTPUT); wifi_connect(ssid, password, 1, iled); Udp.begin(port); - Wire.begin(); - mpu_wakeup(mpu_addr); discover_client(); } @@ -72,10 +67,6 @@ void loop(void) char *dataptr; size_t i; - Wire.beginTransmission(mpu_addr); - Wire.write(0x3b); - Wire.endTransmission(0); - Wire.requestFrom(mpu_addr, 14, 1); udp_init_packet(ip, port); @@ -84,18 +75,6 @@ void loop(void) udp_push(&data, sizeof(data)); udp_push(&ticker, sizeof(ticker)); - /* - * We need to do all seven reads each time. - * We also have to work hard for the compiler - * to not optimize the load out. - */ - for (i = 0; i < 7; ++i) { - dataptr[1] = Wire.read(); - dataptr[0] = Wire.read(); - if (i == 3) { - udp_push(&data, sizeof(data)); - } - } data = analogRead(analog); data = get_temperature(get_resistance(data, splitter_res)); udp_push(&data, sizeof(data)); @@ -135,14 +114,6 @@ static int udp_flush(void) return Udp.endPacket(); } -static void mpu_wakeup(const int i2caddr) -{ - Wire.beginTransmission(i2caddr); - Wire.write(0x6b); - Wire.write(0); - Wire.endTransmission(1); -} - static void wifi_connect(const char * const ssid, const char * const password, const char doblink, const int ledpin) { WiFi.begin(ssid, password); |