Browse Source

Code basically ready for testing on SBC.

master
Your Name 5 years ago
parent
commit
be80b3d79c
9 changed files with 298 additions and 6 deletions
  1. +1
    -0
      code/ethernet_test2/webSrv_plus/webSrv_plus.ino
  2. +8
    -0
      code/ethernet_test_fin/ethernet_test_fin/dtostrf.c
  3. +9
    -0
      code/ethernet_test_fin/ethernet_test_fin/dtostrf.h
  4. +173
    -0
      code/ethernet_test_fin/ethernet_test_fin/ethernet_test_fin.ino
  5. +44
    -0
      code/ethernet_test_fin/ethernet_test_fin/pgmspace.h
  6. +62
    -5
      code/sensortest/sensortest.ino
  7. +0
    -1
      docs/.~lock.AirQualityDocs14.odt#
  8. +1
    -0
      docs/.~lock.AirQualityDocs15.odt#
  9. BIN
      docs/AirQualityDocs15.odt

+ 1
- 0
code/ethernet_test2/webSrv_plus/webSrv_plus.ino View File

@ -73,6 +73,7 @@ void loop() {
//Serial.println(concentration);
//lowpulseoccupancy = 0;
starttime = millis();
Serial.println("DataGet");
}
if ( eElib.available() )

+ 8
- 0
code/ethernet_test_fin/ethernet_test_fin/dtostrf.c View File

@ -0,0 +1,8 @@
#include <stdio.h>
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;
}

+ 9
- 0
code/ethernet_test_fin/ethernet_test_fin/dtostrf.h View File

@ -0,0 +1,9 @@
#ifdef __cplusplus
extern "C" {
#endif
char *dtostrf (double val, signed char width, unsigned char prec, char *sout);
#ifdef __cplusplus
}
#endif

+ 173
- 0
code/ethernet_test_fin/ethernet_test_fin/ethernet_test_fin.ino View File

@ -0,0 +1,173 @@
#include <math.h>
//--- made by SKA ---
//--- test EtherEncLib
// adapted by Renato Aloi
// May 2015
// removed SD Card part for future implementation
#include <SPI.h>
#include <EtherEncLib.h>
#if (ESP8266)
#include <pgmspace.h>
#else
#include <avr/pgmspace.h>
#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<toplimit; x++){
sum = sum + reading[x];
}
average = sum / toplimit;
//see work docs. Bit shift to allow for lower resolution for built in print functions.
//outputting an int - 16 bit, but we originally have a 32 bit)
sumcutdown = sum >> 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<toplimit; x++){
reading[x] = 0;
}
starttime = millis();
}
if ( eElib.available() )
{
Serial.println(eElib.getParams());
eElib.print((char *)&resp200Txt[0],strlen_P(&resp200Txt[0]));
if (eElib.isIndexHtml)
{
eElib.print("<pre><H1>Hello World!</H1>");
//eElib.print("<form method=POST>");
eElib.print("<br>");
eElib.print("The Sum is: ");
eElib.print((unsigned)sumcutdown);
//eElib.print("</form></body>");
eElib.print("</pre>");
}
/*
else if (eElib.isPost)
{
eElib.print("<HTML><body><H1>POST Params: ");
eElib.print(eElib.getParams());
eElib.print("</H1></body>");
eElib.print("</HTML>");
}
else if (eElib.isGet)
{
eElib.print("<HTML><body><H1>GET Params: ");
eElib.print(eElib.getParams());
eElib.print("</H1></body>");
eElib.print("</HTML>");
}*/
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;
}*/

+ 44
- 0
code/ethernet_test_fin/ethernet_test_fin/pgmspace.h View File

@ -0,0 +1,44 @@
#ifndef __PGMSPACE_H_
#define __PGMSPACE_H_ 1
#include <inttypes.h>
#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

+ 62
- 5
code/sensortest/sensortest.ino View File

@ -1,12 +1,19 @@
#include <math.h>
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<toplimit; x++){
sum = sum + airreading[x];
}
average = sum / toplimit;
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
//reset everything after a minute
sum = 0;
average = 0;
x = 0;
toplimit = 0;
for (x=0; x<toplimit; x++){
airreading[x] = 0;
}
starttime = millis();
}
}

+ 0
- 1
docs/.~lock.AirQualityDocs14.odt# View File

@ -1 +0,0 @@
,dev,dev.dev,25.01.2019 01:59,file:///home/dev/.config/libreoffice/4;

+ 1
- 0
docs/.~lock.AirQualityDocs15.odt# View File

@ -0,0 +1 @@
,dev,dev.dev,25.01.2019 23:46,file:///home/dev/.config/libreoffice/4;

BIN
docs/AirQualityDocs15.odt View File


Loading…
Cancel
Save