j

Dependencies:   mbed yeswecancoap C12832 LM75B

Committer:
arnedesmet
Date:
Fri Oct 23 14:58:08 2015 +0000
Revision:
1:92958e26bf2e
Parent:
0:92d2ef9f009d
mlkj;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
arnedesmet 0:92d2ef9f009d 1 #include "mbed.h"
arnedesmet 0:92d2ef9f009d 2 #include "coap.h"
arnedesmet 0:92d2ef9f009d 3 #include "Color.h"
arnedesmet 0:92d2ef9f009d 4 #include "RGB.h"
arnedesmet 1:92958e26bf2e 5 #include "LM75B.h"
arnedesmet 1:92958e26bf2e 6 #include "C12832.h"
arnedesmet 1:92958e26bf2e 7
arnedesmet 1:92958e26bf2e 8 RGB* led = new RGB(p23,p24,p25);
arnedesmet 1:92958e26bf2e 9 LM75B sensor(p28,p27);
arnedesmet 1:92958e26bf2e 10 C12832 lcd(p5, p7, p6, p8, p11);
arnedesmet 1:92958e26bf2e 11 DigitalIn fire(p14);
arnedesmet 1:92958e26bf2e 12 PwmOut spkr(p26);
arnedesmet 0:92d2ef9f009d 13
arnedesmet 0:92d2ef9f009d 14 void get_hello(Request* req, Response* res)
arnedesmet 0:92d2ef9f009d 15 {
arnedesmet 0:92d2ef9f009d 16
arnedesmet 0:92d2ef9f009d 17
arnedesmet 0:92d2ef9f009d 18 res->setContent("Hello World\r\n", 13);
arnedesmet 0:92d2ef9f009d 19 res->setCode(CONTENT);
arnedesmet 0:92d2ef9f009d 20 //res->setType(NON_CONFIRMABLE);
arnedesmet 0:92d2ef9f009d 21 }
arnedesmet 0:92d2ef9f009d 22
arnedesmet 0:92d2ef9f009d 23 void post_led(Request* req, Response* res)
arnedesmet 0:92d2ef9f009d 24 {
arnedesmet 0:92d2ef9f009d 25
arnedesmet 1:92958e26bf2e 26
arnedesmet 0:92d2ef9f009d 27 led->setColor(255,0,0);
arnedesmet 0:92d2ef9f009d 28
arnedesmet 0:92d2ef9f009d 29 if(req->hasContent()){
arnedesmet 0:92d2ef9f009d 30 printf("Content: %s\r\n", req->getContent());
arnedesmet 0:92d2ef9f009d 31 int x;
arnedesmet 0:92d2ef9f009d 32 x = strtol(req->getContent(), NULL, 16);
arnedesmet 0:92d2ef9f009d 33 led->setColor(x);
arnedesmet 0:92d2ef9f009d 34 }
arnedesmet 0:92d2ef9f009d 35 res->setCode(CHANGED);
arnedesmet 0:92d2ef9f009d 36 //res->setType(NON_CONFIRMABLE);
arnedesmet 0:92d2ef9f009d 37 }
arnedesmet 0:92d2ef9f009d 38
arnedesmet 0:92d2ef9f009d 39
arnedesmet 1:92958e26bf2e 40 void get_led(Request* req, Response* res)
arnedesmet 1:92958e26bf2e 41 {
arnedesmet 1:92958e26bf2e 42
arnedesmet 1:92958e26bf2e 43 char temp[100];
arnedesmet 1:92958e26bf2e 44 int color = led->getColor()->getHex();
arnedesmet 1:92958e26bf2e 45 int size = sprintf(temp, "%06x \r\n", color);
arnedesmet 1:92958e26bf2e 46
arnedesmet 1:92958e26bf2e 47 res->setContent( temp, size);
arnedesmet 1:92958e26bf2e 48 res->setCode(CONTENT);
arnedesmet 1:92958e26bf2e 49 //res->setType(NON_CONFIRMABLE);
arnedesmet 1:92958e26bf2e 50 }
arnedesmet 1:92958e26bf2e 51
arnedesmet 1:92958e26bf2e 52
arnedesmet 1:92958e26bf2e 53 void get_temperature(Request* req, Response* res)
arnedesmet 1:92958e26bf2e 54 {
arnedesmet 1:92958e26bf2e 55
arnedesmet 1:92958e26bf2e 56
arnedesmet 1:92958e26bf2e 57 char temp[100];
arnedesmet 1:92958e26bf2e 58 int size = sprintf(temp, "temperatuur: %0.3f", sensor.read());
arnedesmet 1:92958e26bf2e 59
arnedesmet 1:92958e26bf2e 60 res->setContent( temp, size);
arnedesmet 1:92958e26bf2e 61 res->setCode(CONTENT);
arnedesmet 1:92958e26bf2e 62 //res->setType(NON_CONFIRMABLE);
arnedesmet 1:92958e26bf2e 63
arnedesmet 1:92958e26bf2e 64 }
arnedesmet 1:92958e26bf2e 65
arnedesmet 1:92958e26bf2e 66
arnedesmet 1:92958e26bf2e 67 void post_lcd(Request* req, Response* res)
arnedesmet 1:92958e26bf2e 68 {
arnedesmet 1:92958e26bf2e 69
arnedesmet 1:92958e26bf2e 70 if(req->hasContent()){
arnedesmet 1:92958e26bf2e 71 lcd.cls();
arnedesmet 1:92958e26bf2e 72 lcd.locate(0,3);
arnedesmet 1:92958e26bf2e 73 lcd.printf(req->getContent());
arnedesmet 1:92958e26bf2e 74 }
arnedesmet 1:92958e26bf2e 75 res->setCode(CHANGED);
arnedesmet 1:92958e26bf2e 76 //res->setType(NON_CONFIRMABLE);
arnedesmet 1:92958e26bf2e 77
arnedesmet 1:92958e26bf2e 78 }
arnedesmet 1:92958e26bf2e 79
arnedesmet 1:92958e26bf2e 80
arnedesmet 1:92958e26bf2e 81 void post_biep(Request* req, Response* res)
arnedesmet 1:92958e26bf2e 82 {
arnedesmet 1:92958e26bf2e 83
arnedesmet 1:92958e26bf2e 84 if(req->hasContent()){
arnedesmet 1:92958e26bf2e 85 for (float i=2000.0; i<10000.0; i+=100) {
arnedesmet 1:92958e26bf2e 86 spkr.period(1.0/i);
arnedesmet 1:92958e26bf2e 87 spkr=0.5;
arnedesmet 1:92958e26bf2e 88 wait(0.1);
arnedesmet 1:92958e26bf2e 89 }
arnedesmet 1:92958e26bf2e 90 res->setCode(CHANGED);
arnedesmet 1:92958e26bf2e 91 //res->setType(NON_CONFIRMABLE);
arnedesmet 1:92958e26bf2e 92
arnedesmet 1:92958e26bf2e 93 }
arnedesmet 0:92d2ef9f009d 94
arnedesmet 0:92d2ef9f009d 95 int main()
arnedesmet 0:92d2ef9f009d 96 {
arnedesmet 0:92d2ef9f009d 97 Server server;
arnedesmet 1:92958e26bf2e 98
arnedesmet 1:92958e26bf2e 99 server.enableBroadcast();
arnedesmet 1:92958e26bf2e 100
arnedesmet 0:92d2ef9f009d 101 server.add("/hello", &get_hello, GET);
arnedesmet 1:92958e26bf2e 102 server.add("/led", &get_led, GET);
arnedesmet 0:92d2ef9f009d 103 server.add("/led", &post_led, POST);
arnedesmet 1:92958e26bf2e 104 server.add("/temperature", &get_temperature, GET);
arnedesmet 1:92958e26bf2e 105 server.add("/lcd", &post_lcd, POST);
arnedesmet 1:92958e26bf2e 106 server.add("/biep", &post_lcd, POST);
arnedesmet 0:92d2ef9f009d 107 while(1){
arnedesmet 0:92d2ef9f009d 108 server.waitForRequest();
arnedesmet 0:92d2ef9f009d 109 }
arnedesmet 0:92d2ef9f009d 110
arnedesmet 0:92d2ef9f009d 111 }