A system to control fan speed according to temperature values.

Dependencies:   mbed-rtos mbed

Fork of Home_Monitoring_System by Saad Habach

Committer:
wmerghan
Date:
Wed Mar 22 22:52:54 2017 +0000
Revision:
1:5245173228f2
Parent:
0:4c4db81e5752
Child:
2:3f45a93a19e5
Took off the Tempretaure value printf statement

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wmerghan 0:4c4db81e5752 1 #include "mbed.h"
wmerghan 0:4c4db81e5752 2 #include "M2XStreamClient.h"
wmerghan 0:4c4db81e5752 3 #include "EthernetInterface.h"
wmerghan 0:4c4db81e5752 4
wmerghan 0:4c4db81e5752 5 AnalogIn temp(A0);
wmerghan 0:4c4db81e5752 6 DigitalOut test(D3, 0);
wmerghan 0:4c4db81e5752 7 InterruptIn motion(D2);
wmerghan 0:4c4db81e5752 8 Serial pc(USBTX, USBRX); // tx, rx
wmerghan 0:4c4db81e5752 9
wmerghan 0:4c4db81e5752 10 int motion_detected = 0;
wmerghan 0:4c4db81e5752 11 char deviceId[] = "db9efa47cfb6502a21e51cdc97a3cdb4"; // Device you want to push to
wmerghan 0:4c4db81e5752 12 char streamTemp[] = "Temprature"; // Stream you want to push to
wmerghan 0:4c4db81e5752 13 char streamInt[] = "Intruder";
wmerghan 0:4c4db81e5752 14 char streamInts[] = "Intruders";
wmerghan 0:4c4db81e5752 15 char m2xKey[] = "d647418357fc21e8ab3672210493efe6"; // Your M2X API Key or Master API Key
wmerghan 0:4c4db81e5752 16
wmerghan 0:4c4db81e5752 17
wmerghan 0:4c4db81e5752 18 void irq_handler(void)
wmerghan 0:4c4db81e5752 19 {
wmerghan 0:4c4db81e5752 20 motion_detected = 1;
wmerghan 0:4c4db81e5752 21 }
wmerghan 0:4c4db81e5752 22
wmerghan 0:4c4db81e5752 23
wmerghan 0:4c4db81e5752 24 int main(void)
wmerghan 0:4c4db81e5752 25 {
wmerghan 0:4c4db81e5752 26 int motion_cnt = 0;
wmerghan 0:4c4db81e5752 27
wmerghan 0:4c4db81e5752 28 //time_t is used to store the calender time format
wmerghan 0:4c4db81e5752 29 time_t rawtime;
wmerghan 0:4c4db81e5752 30 struct tm *timeinfo;
wmerghan 0:4c4db81e5752 31
wmerghan 0:4c4db81e5752 32 double tempC, tempF;
wmerghan 0:4c4db81e5752 33
wmerghan 0:4c4db81e5752 34 pc.printf("Started\r\n");
wmerghan 0:4c4db81e5752 35
wmerghan 0:4c4db81e5752 36 motion.rise(&irq_handler);
wmerghan 0:4c4db81e5752 37
wmerghan 0:4c4db81e5752 38 // Intialize Ethernet connection
wmerghan 0:4c4db81e5752 39 EthernetInterface eth;
wmerghan 0:4c4db81e5752 40 eth.init();
wmerghan 0:4c4db81e5752 41 eth.connect();
wmerghan 0:4c4db81e5752 42 printf("Success. Connected!. Device IP Address is %s\r\n", eth.getIPAddress());
wmerghan 0:4c4db81e5752 43
wmerghan 0:4c4db81e5752 44 // Initialize the M2X client
wmerghan 0:4c4db81e5752 45 Client client;
wmerghan 0:4c4db81e5752 46 M2XStreamClient m2xClient(&client, m2xKey);
wmerghan 0:4c4db81e5752 47
wmerghan 0:4c4db81e5752 48 while(1)
wmerghan 0:4c4db81e5752 49 {
wmerghan 0:4c4db81e5752 50 tempC = (temp*330);
wmerghan 0:4c4db81e5752 51 tempF = (9.0*tempC)/5.0 + 32.0;
wmerghan 1:5245173228f2 52
wmerghan 0:4c4db81e5752 53
wmerghan 0:4c4db81e5752 54 m2xClient.updateStreamValue(deviceId, streamTemp, tempF);
wmerghan 0:4c4db81e5752 55
wmerghan 0:4c4db81e5752 56 wait(1);
wmerghan 0:4c4db81e5752 57
wmerghan 0:4c4db81e5752 58 if(motion_detected)
wmerghan 0:4c4db81e5752 59 {
wmerghan 0:4c4db81e5752 60 //get the current time
wmerghan 0:4c4db81e5752 61 time(&rawtime);
wmerghan 0:4c4db81e5752 62 timeinfo = localtime(&rawtime);
wmerghan 0:4c4db81e5752 63
wmerghan 0:4c4db81e5752 64 motion_cnt++;
wmerghan 0:4c4db81e5752 65 motion_detected = 0;
wmerghan 0:4c4db81e5752 66 pc.printf("Motion %d Detected at %d:%d:%d \n\r", motion_cnt, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
wmerghan 0:4c4db81e5752 67 m2xClient.updateStreamValue(deviceId, streamInt, motion_cnt);
wmerghan 0:4c4db81e5752 68 m2xClient.updateStreamValue(deviceId, streamInts, motion_cnt);
wmerghan 0:4c4db81e5752 69 }
wmerghan 0:4c4db81e5752 70
wmerghan 0:4c4db81e5752 71 if(tempC > 25)
wmerghan 0:4c4db81e5752 72 {
wmerghan 0:4c4db81e5752 73 pc.printf("Temperature is %.2f C %.2f F\n\r", tempC, tempF);
wmerghan 0:4c4db81e5752 74 DigitalOut test(D3,1);
wmerghan 0:4c4db81e5752 75
wmerghan 0:4c4db81e5752 76 }
wmerghan 0:4c4db81e5752 77 else
wmerghan 0:4c4db81e5752 78 {
wmerghan 0:4c4db81e5752 79 DigitalOut test(D3,0);
wmerghan 0:4c4db81e5752 80
wmerghan 0:4c4db81e5752 81 }
wmerghan 0:4c4db81e5752 82 }
wmerghan 0:4c4db81e5752 83 }