Remote Writing IoT Data to Influx-DB over HTTP-API.
Fork of AvnetATT_shape_hackathon by
Revision 11:e6602513730f, committed 2016-07-12
- Comitter:
- stefanrousseau
- Date:
- Tue Jul 12 03:11:05 2016 +0000
- Parent:
- 10:df54436ecd38
- Child:
- 12:7c94ec5069dc
- Commit message:
- Fixed I2C issues. ; a) Removed stop between HTS221 address and read; b) The latest MBED uses the slave address differently from the legacy. Stick with the old for now and fixed the HTS221 address to BF instead of 5F.; c) Made I2C definitions externs.
Changed in this revision
--- a/Flow_parameters.h Mon Jul 11 23:54:24 2016 +0000 +++ b/Flow_parameters.h Tue Jul 12 03:11:05 2016 +0000 @@ -3,8 +3,11 @@ ******************************************************/ //sockwrite_mdm("GET \r\n/f653d97537235/a31c2684a02c/d35e42196968fd6/in/flow/climate?deviceID=foo&temp=41.0&humidity=87.33\r\n HTTP/1.1\r\nHost: run-east.att.io:80\r\nAccept: */*\r\n\r\n"); -#define FLOW_CALLBACK_URL_START "GET \r\n/f653d97537235/a31c2684a02c/d35e42196968fd6/in/flow/climate" -#define FLOW_CALLBACK_URL_END "\r\n HTTP/1.1 Host: run-east.att.io:80 Accept: */*\r\n\r\n" +//#define FLOW_CALLBACK_URL_START "GET \r\n/f653d97537235/a31c2684a02c/d35e42196968fd6/in/flow/climate" +//#define FLOW_CALLBACK_URL_END "\r\n HTTP/1.1 Host: run-east.att.io:80 Accept: */*\r\n\r\n" + +#define FLOW_CALLBACK_URL_START "GET \r\n/1e464b19cdcde/774c88d68202/86694923d5bf28a/in/flow/climate" +#define FLOW_CALLBACK_URL_END "\r\n HTTP/1.1 Host: run-west.att.io:80 Accept: */*\r\n\r\n" /****************************************************** * Type Definitions
--- a/HTS221.h Mon Jul 11 23:54:24 2016 +0000 +++ b/HTS221.h Tue Jul 12 03:11:05 2016 +0000 @@ -28,7 +28,9 @@ int writeRegister(unsigned char slaveAddress, unsigned char regToWrite, unsigned char dataToWrite); }; -#define HTS221_ADDRESS 0x5F +//#define HTS221_ADDRESS 0x5F +//By Stefan +#define HTS221_ADDRESS 0xBF //Define a few of the registers that we will be accessing on the HTS221 #define WHO_AM_I 0x0F
--- a/config_me.h Mon Jul 11 23:54:24 2016 +0000 +++ b/config_me.h Tue Jul 12 03:11:05 2016 +0000 @@ -3,8 +3,8 @@ // User must set these for own context: static const char * MY_FLOW_DEVICE_ID_STR = "48482f"; -//Stefan's: static const char * MY_FLOW_DEVICE_ID_STR = "a26205cf22c24e28f36ca1691303f9a8"; -static const char * MY_SERVER_URL = "run-east.att.io"; +//static const char * MY_SERVER_URL = "run-east.att.io"; +static const char * MY_SERVER_URL = "run-west.att.io"; static const char * MY_APN_STR = "m2m.com.attz"; static const char * MY_PORT_STR = "80";
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hardware.h Tue Jul 12 03:11:05 2016 +0000 @@ -0,0 +1,5 @@ +#ifndef Hardware_H_ +#define Hardware_H_ +extern I2C i2c; //SDA, SCL -- define the I2C pins being used + +#endif
--- a/hts221_driver.cpp Mon Jul 11 23:54:24 2016 +0000 +++ b/hts221_driver.cpp Tue Jul 12 03:11:05 2016 +0000 @@ -8,14 +8,16 @@ #include <string> #include "mbed.h" -I2C i2c(PTC11, PTC10); //SDA, SCL -- define the I2C pins being used +#include "hardware.h" +//I2C i2c(PTC11, PTC10); //SDA, SCL -- define the I2C pins being used // Read a single unsigned char from addressToRead and return it as a unsigned char unsigned char HTS221::readRegister(unsigned char slaveAddress, unsigned char ToRead) { char data = ToRead; - i2c.write(slaveAddress, &data, 1, 0); + //i2c.write(slaveAddress, &data, 1, 0); + i2c.write(slaveAddress, &data, 1, 1); //by Stefan i2c.read(slaveAddress, &data, 1, 0); return data; }
--- a/main.cpp Mon Jul 11 23:54:24 2016 +0000 +++ b/main.cpp Tue Jul 12 03:11:05 2016 +0000 @@ -7,6 +7,9 @@ #include "wnc_control.h" #include "sensors.h" +#include "hardware.h" +I2C i2c(PTC11, PTC10); //SDA, SCL -- define the I2C pins being used + // comment out the following line if color is not supported on the terminal #define USE_COLOR #ifdef USE_COLOR @@ -291,6 +294,8 @@ printf("Temp is: %0.2f F \n\r",CTOF(hts221.readTemperature())); printf("Humid is: %02d %%\n\r",hts221.readHumidity()); + sensors_init(); + // Initialize the modem printf(GRN "Modem initializing... will take up to 60 seconds" DEF "\r\n"); i=mdm_init(); @@ -305,7 +310,6 @@ // Resolve URL to IP address to connect to resolve_mdm(); - sensors_init(); //Create a 1ms timer tick function: OneMsTicker.attach(OneMsFunction, 0.001f) ; iTimer1Interval_ms = 5000; //5 seconds
--- a/mbed.bld Mon Jul 11 23:54:24 2016 +0000 +++ b/mbed.bld Tue Jul 12 03:11:05 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/6c34061e7c34 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/aae6fcc7d9bb \ No newline at end of file
--- a/sensors.cpp Mon Jul 11 23:54:24 2016 +0000 +++ b/sensors.cpp Tue Jul 12 03:11:05 2016 +0000 @@ -5,7 +5,8 @@ #define Si1145_PMOD_I2C_ADDR 0xC0 //this is for 7-bit addr 0x60 for the Si7020 #define Si7020_PMOD_I2C_ADDR 0x80 //this is for 7-bit addr 0x4 for the Si7020 -I2C pmod_i2c(PTC11, PTC10); //SDA, SCL +#include "hardware.h" +//I2C i2c(PTC11, PTC10); //SDA, SCL #include "FXOS8700CQ.h" // Pin names for the motion sensor FRDM-K64F board: @@ -28,7 +29,7 @@ unsigned char I2C_ReadSingleByte(unsigned char ucDeviceAddress) { char rxbuffer [1]; - pmod_i2c.read(ucDeviceAddress, rxbuffer, 1 ); + i2c.read(ucDeviceAddress, rxbuffer, 1 ); return (unsigned char)rxbuffer[0]; } //I2C_ReadSingleByte() @@ -40,8 +41,8 @@ char txbuffer [1]; char rxbuffer [1]; txbuffer[0] = (char)Addr; - pmod_i2c.write(ucDeviceAddress, txbuffer, 1 ); - pmod_i2c.read(ucDeviceAddress, rxbuffer, 1 ); + i2c.write(ucDeviceAddress, txbuffer, 1 ); + i2c.read(ucDeviceAddress, rxbuffer, 1 ); return (unsigned char)rxbuffer[0]; } //I2C_ReadSingleByteFromAddr() @@ -51,7 +52,7 @@ int I2C_ReadMultipleBytes(unsigned char ucDeviceAddress, char *ucData, unsigned char ucLength) { int status; - status = pmod_i2c.read(ucDeviceAddress, ucData, ucLength); + status = i2c.read(ucDeviceAddress, ucData, ucLength); return status; } //I2C_ReadMultipleBytes() @@ -63,7 +64,7 @@ int status; char txbuffer [1]; txbuffer[0] = (char)Data; //data - status = pmod_i2c.write(ucDeviceAddress, txbuffer, 1, !bSendStop); //true: do not send stop + status = i2c.write(ucDeviceAddress, txbuffer, 1, !bSendStop); //true: do not send stop return status; } //I2C_WriteSingleByte() @@ -76,8 +77,8 @@ char txbuffer [2]; txbuffer[0] = (char)Addr; //address txbuffer[1] = (char)Data; //data - //status = pmod_i2c.write(ucDeviceAddress, txbuffer, 2, false); //stop at end - status = pmod_i2c.write(ucDeviceAddress, txbuffer, 2, !bSendStop); //true: do not send stop + //status = i2c.write(ucDeviceAddress, txbuffer, 2, false); //stop at end + status = i2c.write(ucDeviceAddress, txbuffer, 2, !bSendStop); //true: do not send stop return status; } //I2C_WriteSingleByteToAddr() @@ -87,7 +88,7 @@ int I2C_WriteMultipleBytes(unsigned char ucDeviceAddress, char *ucData, unsigned char ucLength, bool bSendStop) { int status; - status = pmod_i2c.write(ucDeviceAddress, ucData, ucLength, !bSendStop); //true: do not send stop + status = i2c.write(ucDeviceAddress, ucData, ucLength, !bSendStop); //true: do not send stop return status; } //I2C_WriteMultipleBytes() @@ -310,34 +311,49 @@ //******************************************************************************************************************************************** //* Read the FXOS8700CQ - 6-axis combo Sensor Accelerometer and Magnetometer //******************************************************************************************************************************************** -void read_motion_sensor() -{ - fxos.get_data(&accel_data, &magn_data); - //printf("Roll=%5d, Pitch=%5d, Yaw=%5d;\r\n", magn_data.x, magn_data.y, magn_data.z); - sprintf(SENSOR_DATA.MagnetometerX, "%5d", magn_data.x); - sprintf(SENSOR_DATA.MagnetometerY, "%5d", magn_data.y); - sprintf(SENSOR_DATA.MagnetometerZ, "%5d", magn_data.z); - - //Try to normalize (/2048) the values so they will match the eCompass output: - float fAccelScaled_x, fAccelScaled_y, fAccelScaled_z; - fAccelScaled_x = (accel_data.x/2048.0); - fAccelScaled_y = (accel_data.y/2048.0); - fAccelScaled_z = (accel_data.z/2048.0); - //printf("Acc: X=%2.3f Y=%2.3f Z=%2.3f;\r\n", fAccelScaled_x, fAccelScaled_y, fAccelScaled_z); - sprintf(SENSOR_DATA.AccelX, "%2.3f", fAccelScaled_x); - sprintf(SENSOR_DATA.AccelY, "%2.3f", fAccelScaled_y); - sprintf(SENSOR_DATA.AccelZ, "%2.3f", fAccelScaled_z); -} //read_motion_sensor - +bool bMotionSensor_present = false; void init_motion_sensor() { - printf("FXOS8700CQ WhoAmI = %X\r\n", fxos.get_whoami()); + int iWhoAmI = fxos.get_whoami(); + + printf("FXOS8700CQ WhoAmI = %X\r\n", iWhoAmI); // Iterrupt for active-low interrupt line from FXOS // Configured with only one interrupt on INT2 signaling Data-Ready //fxos_int2.fall(&trigger_fxos_int2); - fxos.enable(); + if (iWhoAmI != 0xC7) + { + bMotionSensor_present = false; + printf("FXOS8700CQ motion sensor not found\n"); + } + else + { + bMotionSensor_present = true; + fxos.enable(); + } } //init_motion_sensor +void read_motion_sensor() +{ + if (bMotionSensor_present) + { + fxos.get_data(&accel_data, &magn_data); + //printf("Roll=%5d, Pitch=%5d, Yaw=%5d;\r\n", magn_data.x, magn_data.y, magn_data.z); + sprintf(SENSOR_DATA.MagnetometerX, "%5d", magn_data.x); + sprintf(SENSOR_DATA.MagnetometerY, "%5d", magn_data.y); + sprintf(SENSOR_DATA.MagnetometerZ, "%5d", magn_data.z); + + //Try to normalize (/2048) the values so they will match the eCompass output: + float fAccelScaled_x, fAccelScaled_y, fAccelScaled_z; + fAccelScaled_x = (accel_data.x/2048.0); + fAccelScaled_y = (accel_data.y/2048.0); + fAccelScaled_z = (accel_data.z/2048.0); + //printf("Acc: X=%2.3f Y=%2.3f Z=%2.3f;\r\n", fAccelScaled_x, fAccelScaled_y, fAccelScaled_z); + sprintf(SENSOR_DATA.AccelX, "%2.3f", fAccelScaled_x); + sprintf(SENSOR_DATA.AccelY, "%2.3f", fAccelScaled_y); + sprintf(SENSOR_DATA.AccelZ, "%2.3f", fAccelScaled_z); + } //bMotionSensor_present +} //read_motion_sensor + void sensors_init(void) { Init_Si7020();