-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtvduino.ino
More file actions
64 lines (58 loc) · 1.61 KB
/
Copy pathtvduino.ino
File metadata and controls
64 lines (58 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* TVduino
*
* This program exposes an REST API to multiple readings
* to retrieve the status of a television
*
* Filipe Caldas (fcaldas@canalplus.fr)
*/
#include <TimerOne.h>
#include <SPI.h>
#include <EthernetUdp.h>
#include <EthernetServer.h>
#include <Ethernet.h>
#include "restapi.h"
#include "jsonParser.h"
#include "timeinter.h"
#include "zapTime.h"
#include "powerSwitch.h"
//Network configuration for arduino
//byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte mac[] = { 0x2A, 0x2C, 0x39, 0x30, 0x30, 0x30 };
byte ip[] = {10, 0, 1, 160};
byte gateway[] = { 10, 0, 0, 1 };
byte subnet[] = { 255, 255, 0, 0 };
restServer *myServer;
EthernetClient http_client;
/*
* Simple callback that returns readings of the two photoresistors
* in ports A4 and A5.
*/
void getVideo(EthernetClient *client, char args[]){
int v1 = analogRead(A4);
int v2 = analogRead(A5);
client->print("{\"video1\":");
client->print(v1);
client->print(",\"video2\":");
client->print(v2);
client->println("}");
}
void setup() {
Serial.begin(9600);
myServer = new restServer(mac, ip, gateway, subnet,80);
delay(1000);
//create routes on our rest server
myServer->addRoute("/video", GET, &getVideo);
myServer->addRoute("/getlivestatus", POST, &getLiveStatus);
myServer->addRoute("/status", POST, &stbState);
myServer->addRoute("/zap", POST, &dozap);
myServer->addRoute("/wakeup", POST, &power);
//Configure time interruptions for 50ms
//this will be used to measure the time to switch
//channels.
Serial.println("Starting TVduino");
TimeInterruption::init(50000);
}
void loop() {
myServer->serve();
}