Remote Writing IoT Data to Influx-DB over HTTP-API.
Fork of AvnetATT_shape_hackathon by
Revision 1:af7a42f7d465, committed 2016-07-09
- Comitter:
- JMF
- Date:
- Sat Jul 09 00:45:53 2016 +0000
- Parent:
- 0:9d5134074d84
- Child:
- 2:0e2ef866af95
- Commit message:
- Adding string encode/decode;
Changed in this revision
--- a/HTS221Reg.h Fri Jul 08 23:52:38 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ - -#ifndef HTS221REG_H_ -#define HTS221REG_H_ - - -#define HTS221_ADDRESS 0x5F - -//Define a few of the registers that we will be accessing on the HTS221 -#define WHO_AM_I 0x0F -#define WHO_AM_I_RETURN 0xBC //This read-only register contains the device identifier, set to BCh - -#define AVERAGE_REG 0x10 // To configure humidity/temperature average. -#define AVERAGE_DEFAULT 0x1B - -/* - * [7] PD: power down control - * (0: power-down mode; 1: active mode) - * - * [6:3] Reserved - * - * [2] BDU: block data update - * (0: continuous update; 1: output registers not updated until MSB and LSB reading) -The BDU bit is used to inhibit the output register update between the reading of the upper -and lower register parts. In default mode (BDU = ?0?), the lower and upper register parts are -updated continuously. If it is not certain whether the read will be faster than output data rate, -it is recommended to set the BDU bit to ?1?. In this way, after the reading of the lower (upper) -register part, the content of that output register is not updated until the upper (lower) part is -read also. - * - * [1:0] ODR1, ODR0: output data rate selection (see table 17) - */ -#define CTRL_REG1 0x20 -#define POWER_UP 0x80 -#define BDU_SET 0x4 -#define ODR0_SET 0x1 // setting sensor reading period 1Hz - -#define CTRL_REG2 0x21 -#define CTRL_REG3 0x22 -#define REG_DEFAULT 0x00 - -#define STATUS_REG 0x27 -#define TEMPERATURE_READY 0x1 -#define HUMIDITY_READY 0x2 - -#define HUMIDITY_L_REG 0x28 -#define HUMIDITY_H_REG 0x29 -#define TEMP_L_REG 0x2A -#define TEMP_H_REG 0x2B -/* - * calibration registry should be read for temperature and humidity calculation. - * Before the first calculation of temperature and humidity, - * the master reads out the calibration coefficients. - * will do at init phase - */ -#define CALIB_START 0x30 -#define CALIB_END 0x3F -/* -#define CALIB_T0_DEGC_X8 0x32 -#define CALIB_T1_DEGC_X8 0x33 -#define CALIB_T1_T0_MSB 0x35 -#define CALIB_T0_OUT_L 0x3C -#define CALIB_T0_OUT_H 0x3D -#define CALIB_T1_OUT_L 0x3E -#define CALIB_T1_OUT_H 0x3F - */ - - - -#endif /* HTS221REG_H_ */
--- a/hts221_driver.cpp Fri Jul 08 23:52:38 2016 +0000 +++ b/hts221_driver.cpp Sat Jul 09 00:45:53 2016 +0000 @@ -32,12 +32,12 @@ //jmf end // ------------------------------------------------------------------------------ -static inline int humidityReady(uint8_t data) { - return (data & 0x02); -} -static inline int temperatureReady(uint8_t data) { - return (data & 0x01); -} +//static inline int humidityReady(uint8_t data) { +// return (data & 0x02); +//} +//static inline int temperatureReady(uint8_t data) { +// return (data & 0x01); +//} HTS221::HTS221(void) : _address(HTS221_ADDRESS)
--- a/main.cpp Fri Jul 08 23:52:38 2016 +0000 +++ b/main.cpp Sat Jul 09 00:45:53 2016 +0000 @@ -63,10 +63,12 @@ // int DecodeASCIIstr(string& ins, string& outs) { int val, n = 0; - char ts[2]; + char ts[] = {0,0,0}; while(n<ins.length()) { - val = atoi((const char*)ins[n])*16+atoi((const char*)ins[n+1]); + ts[0] = ins[n]; + ts[1] = ins[n+1]; + sscanf(ts,"%X",&val); sprintf(ts,"%c",val); outs.append(ts); n += 2; @@ -85,19 +87,19 @@ // will only accept up to 1500 characters, and the converted srings will be 2x the // input string since the hex representation of 1 character is a two digit hex value. // -int CreateASCIIstr(string& in, string& out) { +int CreateASCIIstr(string& ins, string& outs) { int i = 0; char ts[3]; - - if( in.length() > 749 ) + + if( ins.length() > 749 ) return 0; - while(in[i] != 0x00) { - sprintf(ts,"%02X", in[i]); - out.append(ts); + while(ins[i] != 0x00) { + sprintf(ts,"%02X", ins[i]); + outs.append(ts); i++; } - return out.length(); + return outs.length(); } @@ -220,7 +222,7 @@ void hts221_init(void); - pc.printf(BLU "Hello World from AT&T Shape!\r\n"); + pc.printf(BLU "Hello World from AT&T Shape!\r\n\n\r"); pc.printf(GRN "Initialize the HTS221\n\r"); i = hts221.begin(); @@ -231,6 +233,15 @@ printf("Temp is: %0.2f F \n\r",CTOF(hts221.readTemperature())); printf("Humid is: %02d %%\n\r",hts221.readHumidity()); + + string newstr, outstr, instr = "0123456789aAbBcCdDeEfFxXyYzZ"; + pc.printf("\n\rTest ASCII String creation: \n\r"); + i = CreateASCIIstr(instr,outstr); + pc.printf(">Initially the string is '%s' (%d long)\n\r>after encode it is '%s' (%d characters long).\n\r", + instr.c_str(),instr.length(),outstr.c_str(),i); + i = DecodeASCIIstr(outstr, newstr); + pc.printf(">after decoding the encoded string, it is '%s' (%d long)\n\r\n\r",newstr.c_str(),i); + // Initialize the modem printf(GRN "Modem initializing... will take up to 60 seconds" DEF "\r\n");