diff --git a/code/ethernet_test2/webSrv_plus/webSrv_plus.ino b/code/ethernet_test2/webSrv_plus/webSrv_plus.ino index 1d0381c..5dd21f1 100644 --- a/code/ethernet_test2/webSrv_plus/webSrv_plus.ino +++ b/code/ethernet_test2/webSrv_plus/webSrv_plus.ino @@ -73,6 +73,7 @@ void loop() { //Serial.println(concentration); //lowpulseoccupancy = 0; starttime = millis(); + Serial.println("DataGet"); } if ( eElib.available() ) diff --git a/code/ethernet_test_fin/ethernet_test_fin/dtostrf.c b/code/ethernet_test_fin/ethernet_test_fin/dtostrf.c new file mode 100644 index 0000000..c4fd9ec --- /dev/null +++ b/code/ethernet_test_fin/ethernet_test_fin/dtostrf.c @@ -0,0 +1,8 @@ +#include + +char *dtostrf (double val, signed char width, unsigned char prec, char *sout) { + char fmt[20]; + sprintf(fmt, "%%%d.%df", width, prec); + sprintf(sout, fmt, val); + return sout; +} diff --git a/code/ethernet_test_fin/ethernet_test_fin/dtostrf.h b/code/ethernet_test_fin/ethernet_test_fin/dtostrf.h new file mode 100644 index 0000000..99f2cab --- /dev/null +++ b/code/ethernet_test_fin/ethernet_test_fin/dtostrf.h @@ -0,0 +1,9 @@ +#ifdef __cplusplus +extern "C" { +#endif + +char *dtostrf (double val, signed char width, unsigned char prec, char *sout); + +#ifdef __cplusplus +} +#endif diff --git a/code/ethernet_test_fin/ethernet_test_fin/ethernet_test_fin.ino b/code/ethernet_test_fin/ethernet_test_fin/ethernet_test_fin.ino new file mode 100644 index 0000000..2f214d3 --- /dev/null +++ b/code/ethernet_test_fin/ethernet_test_fin/ethernet_test_fin.ino @@ -0,0 +1,173 @@ +#include + +//--- made by SKA --- +//--- test EtherEncLib +// adapted by Renato Aloi +// May 2015 +// removed SD Card part for future implementation + +#include +#include +#if (ESP8266) +#include +#else +#include +#endif + + + +static unsigned char ipaddr[] = { 192, 168, 1, 125 }; +static unsigned char macaddr[] = { 0x00, 0x11, 0x22, 0x44, 0x00, 0x25 }; + +EtherEncLib eElib(80); + +const PROGMEM char resp200Txt[] = {"HTTP/1.0 200 OK\n\rContent-Type: text/html\n\rPragma: no-cache\n\r\n\r"}; + +//sensor start + +int DustSensePin = 13; + +//copy and paste for 50 zeros +//this should probably not be global... +//Int means max 65535 or so. May need to move to long +//making this too high runs into memory problems +//This resolution will be relatively good enough for now. + +//If we need more space, then store only the first value in an unsigned int or long, then +//bit shift it down to reduce size, and store in array in a lower size var. +unsigned int reading[30] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +unsigned long sampletime_ms = 60000;//sample 30s ; +unsigned long starttime = 0; +unsigned char x = 0; +unsigned char toplimit = 0; +unsigned long sum = 0; //highest number possible - 32 bit unsigned, so 4 billion +unsigned int average = 0; +unsigned int sumcutdown = 0; + + +void setup() +{ + Serial.println(F("Setup begin")); +#if (ESP8266) + Serial.begin(115200); + pinMode(5,OUTPUT); //--- ? -- SS pin must be output # by Renato Aloi +#else + Serial.begin(9600); + pinMode(8,OUTPUT); //--- ? -- SS pin must be output # by Renato Aloi +#endif + + eElib.begin(ipaddr,macaddr); + Serial.println(F("------ program start -----------")); + //Serial.println(F("NO SDCARD version")); // by Renato Aloi + + pinMode(DustSensePin,INPUT); + starttime = millis();//get the current time; +} + +void loop() { + + reading[x] = pulseIn(DustSensePin, LOW, 500000); + + + //Print out readings on serial, as they come + if (reading[x] != 0){ + Serial.println(reading[x]); + x=x+1; + if(x>50){ + x = 0; + } + } + + + + if ((millis()-starttime) > sampletime_ms){ + //reset these, no need to display on webpage anymore + sum = 0; + average = 0; + + + toplimit = x; // don't read the zeros + + /* + if(toplimit == 0){ + toplimit = 1; //to avoid divide by zero, in case sum / toplimit is both zero + } + */ + for (x=0; x> 4; + //Serial.print("Average Get!: "); + //Serial.println(average); //average when 0 is 65535, so it's invalid (dividing by zero - sum divided by top limit which are both zero) + //but we don't even want the average. It's just for testing here. + Serial.print("Sum Get!: "); + Serial.println(sum); //this is what we care about + Serial.print("Sumcutdown Get!: "); + Serial.println(sumcutdown); //bit shifted + + //reset everything that can be reset after a minute + + x = 0; + toplimit = 0; + for (x=0; x

Hello World!

"); + //eElib.print("
"); + eElib.print("
"); + eElib.print("The Sum is: "); + + eElib.print((unsigned)sumcutdown); + //eElib.print("
"); + eElib.print(""); + } + /* + else if (eElib.isPost) + { + eElib.print("

POST Params: "); + eElib.print(eElib.getParams()); + eElib.print("

"); + eElib.print(""); + } + else if (eElib.isGet) + { + eElib.print("

GET Params: "); + eElib.print(eElib.getParams()); + eElib.print("

"); + eElib.print(""); + }*/ + eElib.close(); + } +} + + +//unused +/* +int ipow(int base, int exp) +{ + int result = 1; + for (;;) + { + if (exp & 1) + result *= base; + exp >>= 1; + if (!exp) + break; + base *= base; + } + + return result; +}*/ diff --git a/code/ethernet_test_fin/ethernet_test_fin/pgmspace.h b/code/ethernet_test_fin/ethernet_test_fin/pgmspace.h new file mode 100644 index 0000000..9b344c9 --- /dev/null +++ b/code/ethernet_test_fin/ethernet_test_fin/pgmspace.h @@ -0,0 +1,44 @@ +#ifndef __PGMSPACE_H_ +#define __PGMSPACE_H_ 1 + +#include + +#define PROGMEM +#define PGM_P const char * +#define PSTR(str) (str) + +#define _SFR_BYTE(n) (n) + +typedef void prog_void; +typedef char prog_char; +typedef unsigned char prog_uchar; +typedef int8_t prog_int8_t; +typedef uint8_t prog_uint8_t; +typedef int16_t prog_int16_t; +typedef uint16_t prog_uint16_t; +typedef int32_t prog_int32_t; +typedef uint32_t prog_uint32_t; + +#define memcpy_P(dest, src, num) memcpy((dest), (src), (num)) +#define strcpy_P(dest, src) strcpy((dest), (src)) +#define strcat_P(dest, src) strcat((dest), (src)) +#define strcmp_P(a, b) strcmp((a), (b)) +#define strstr_P(a, b) strstr((a), (b)) +#define strlen_P(a) strlen((a)) +#define sprintf_P(s, f, ...) sprintf((s), (f), __VA_ARGS__) + +#define pgm_read_byte(addr) (*(const unsigned char *)(addr)) +#define pgm_read_word(addr) (*(const unsigned short *)(addr)) +#define pgm_read_dword(addr) (*(const unsigned long *)(addr)) +#define pgm_read_float(addr) (*(const float *)(addr)) + +#define pgm_read_byte_near(addr) pgm_read_byte(addr) +#define pgm_read_word_near(addr) pgm_read_word(addr) +#define pgm_read_dword_near(addr) pgm_read_dword(addr) +#define pgm_read_float_near(addr) pgm_read_float(addr) +#define pgm_read_byte_far(addr) pgm_read_byte(addr) +#define pgm_read_word_far(addr) pgm_read_word(addr) +#define pgm_read_dword_far(addr) pgm_read_dword(addr) +#define pgm_read_float_far(addr) pgm_read_float(addr) + +#endif diff --git a/code/sensortest/sensortest.ino b/code/sensortest/sensortest.ino index 5228004..89225b4 100644 --- a/code/sensortest/sensortest.ino +++ b/code/sensortest/sensortest.ino @@ -1,12 +1,19 @@ #include int DustSensePin = 13; -unsigned long duration; -unsigned long starttime; -unsigned long sampletime_ms = 30000;//sample 30s ; + +//let's start with 100 readings. (copy and paste) +unsigned int airreading[100] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +unsigned long starttime = 0; +unsigned long sampletime_ms = 60000;//sample 60s == 60000 ; unsigned long lowpulseoccupancy = 0; float ratio = 0; float concentration = 0; +unsigned int x = 0; +unsigned int toplimit = 0; +unsigned long sum = 0; //highest number possible - 32 bit unsigned, so 4 billion +unsigned int average = 0; + void setup() { @@ -18,8 +25,10 @@ void setup() void loop() { - duration = pulseIn(DustSensePin, LOW); - lowpulseoccupancy = lowpulseoccupancy+duration; + + airreading[x] = pulseIn(DustSensePin, LOW, 500000); + + /*lowpulseoccupancy = lowpulseoccupancy+duration; if ((millis()-starttime) > sampletime_ms)//if the sample time == 30s { @@ -33,4 +42,52 @@ void loop() lowpulseoccupancy = 0; starttime = millis(); } + */ + //if ((millis()-starttime) > sampletime_ms){ + + //KISS. Relative readings only. + //Something else keeps the time. + if (airreading[x] != 0){ + Serial.println(airreading[x]); + x=x+1; + if(x>100){ + x = 0; + } + } + + //starttime = millis(); + //} + + + //KISS. Average for a minute, and store that data in a webpage (that part will be in ethernet sensor test 3). + // + if ((millis()-starttime) > sampletime_ms){ + toplimit = x; // don't read the zeros + + + if(toplimit == 0){ + toplimit = 1; //to avoid divide by zero, in case sum / toplimit is both zero + } + + for (x=0; x