First version work in progress
Dependencies: SDFileSystem WIZnetInterface mbed
Revision 2:348703f5ce0e, committed 2017-09-30
- Comitter:
- erlingl
- Date:
- Sat Sep 30 19:01:44 2017 +0000
- Parent:
- 1:fa7f5224886b
- Child:
- 3:7fd5a67a03d5
- Commit message:
- Not finished
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ReadSensors/readsensor.cpp Sat Sep 30 19:01:44 2017 +0000
@@ -0,0 +1,74 @@
+/*
+ * readsensor.cpp
+ *
+ *
+ */
+
+
+#include "mbed.h"
+#include <stdint.h>
+
+/** Read all sensors and store them in a virtual filesystem
+ *
+ * @code
+ * #include "mbed.h"
+ * #include "readsensor.h"
+ *
+ * ReadSensor sensorRead(); //
+ *
+ *
+ * }
+ * @endcode
+ */
+
+DigitalOut myled(LED1);
+AnalogIn CDS(A0);
+AnalogIn Sensor0(A1);
+AnalogIn Sensor1(A2);
+AnalogIn Sensor2(A3);
+#include "readsensor.h"
+
+#define DHT_DATA_BIT_COUNT 41
+
+ReadSensor::ReadSensor(PinName pin) {
+ _pin = pin;
+ _firsttime=true;
+}
+
+ReadSensor::~ReadSensor() {
+}
+
+int ReadSensor::readData() {
+ int retryCount,b;
+
+// eError err = ERROR_NONE;
+ time_t currentTime = time(NULL);
+
+ DigitalInOut temp_io(_pin);
+
+
+
+ if (retryCount > 125) {
+ }
+ retryCount ++;
+ wait_us(2);
+ retryCount++;
+ wait_us(1);
+
+
+ b=0;
+
+ return 0;
+
+}
+
+
+//
+//
+//
+int ReadSensor::readPower()
+{
+ int i = 0;
+ return i;
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ReadSensors/readsensor.h Sat Sep 30 19:01:44 2017 +0000
@@ -0,0 +1,48 @@
+/*
+ * readsensor.h
+ *
+ *
+ */
+
+#ifndef READSENSOR_H
+#define READSENSOR_H
+
+#include "mbed.h"
+#include <stdint.h>
+
+#include "readsensor.h"
+
+class ReadSensor {
+
+public:
+ ReadSensor(PinName pin);
+ ~ReadSensor();
+
+ /** Create sensor object
+ *
+ */
+
+// virtual int sensor_initialize();
+// virtual int sensor_status();
+// virtual int sensor_read(uint8_t * buffer, uint64_t block_number);
+ int readData();
+ int readPower();
+
+private:
+ time_t _lastReadTime;
+ float _lastTemperature;
+ float _lastHumidity;
+
+ PinName _pin;
+ bool _firsttime;
+
+
+ int initialise_sensor();
+
+ int _read(uint8_t * buffer, uint32_t length);
+
+
+// DigitalOut _cs;
+};
+
+#endif
\ No newline at end of file
--- a/main.cpp Sat Sep 30 15:28:45 2017 +0000
+++ b/main.cpp Sat Sep 30 19:01:44 2017 +0000
@@ -1,5 +1,6 @@
#include "mbed.h"
#include "EthernetInterface.h"
+#include "readsensors.h"
#include "SDFileSystem.h"
#include <stdio.h>
#include <string.h>
@@ -18,23 +19,24 @@
#define HTTPD_MAX_DNAME_LENGTH 127
Serial uart(USBTX, USBRX);
+Serial aurdino(D1,D0);
-//SDFileSystem sd(p5, p6, p7, p8, "sd"); // LPC1768 MBD2PMD
-//SDFileSystem sd(P0_18, P0_17, P0_15, P0_16, "sd"); // Seeeduino Arch Pro SPI2SD
-//SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // K64F
SDFileSystem sd(PB_3, PB_2, PB_1, PB_0, "sd"); // WIZwiki-W7500
EthernetInterface eth;
TCPSocketServer server;
TCPSocketConnection client;
+ReadSensors sensor;
char buffer[HTTPD_MAX_REQ_LENGTH+1];
+char sensorBuffer[42];
char httpHeader[HTTPD_MAX_HDR_LENGTH+1];
char fileName[HTTPD_MAX_FNAME_LENGTH+1];
char dirName[HTTPD_MAX_DNAME_LENGTH+1];
char *uristr;
char *eou;
char *qrystr;
+char *sensorData;
FILE *fp;
int rdCnt;
@@ -94,6 +96,9 @@
uart.printf("Sending: header");
sprintf(httpHeader,"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: Close\r\n\r\n");
client.send(httpHeader,strlen(httpHeader));
+
+ sprintf(httpHeader,"Temp sensors %s\r\n\r\n", sensorBuffer);
+ client.send(httpHeader,strlen(httpHeader));
uart.printf(" file");
while ((rdCnt = fread(buffer, sizeof( char ), 1024, fp)) == 1024) {
client.send(buffer, rdCnt);
@@ -112,6 +117,7 @@
// Serial Interface eth;
uart.baud(115200);
uart.printf("Initializing\n");
+ aurdino.baud(9600);
// Check File System
uart.printf("Checking File System\n");
@@ -122,10 +128,7 @@
uart.printf("SD Card Root Directory Not Found\n");
}
-// EthernetInterface eth;
uart.printf("Initializing Ethernet\n");
- //eth.init(); //Use DHCP
- //eth.init((uint8_t*)MAC); // Use DHCP for WIZnetInterface
eth.init((uint8_t*)MAC,IP,MASK,GATEWAY); //IP,mask,Gateway
uart.printf("Connecting\n");
eth.connect();
@@ -165,6 +168,7 @@
} else {
*eou = 0;
get_file(uristr);
+ sensor.readData(sensorData);
}
}
}