Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "SD.h"
- #include "Ethernet.h"
- #include "SPI.h"
- #include "WebServer.h"
- File MioFile;
- template<class T>
- inline Print &operator <<(Print &obj, T arg)
- {
- obj.print(arg);
- return obj;
- }
- static byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
- static byte ip[] = { 10, 0, 1, 100 };
- #define PREFIX ""
- WebServer webserver(PREFIX, 80);
- void outputJson(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) {
- server.httpSuccess("application/json");
- if (type == WebServer::HEAD)
- return;
- server << "{";
- server << "\"temperature\": " << checkTemperature(0) << ", ";
- server << " }";
- }
- void initSD() {
- if (SD.begin(4) == true) {
- if (SD.exists("conf/conf.txt")) {
- MioFile = SD.open("conf/conf.txt", FILE_READ);
- if (MioFile == true) {
- while (MioFile.available())
- {
- Serial.write(MioFile.read());
- }
- MioFile.close();
- }
- }
- else {
- SD.mkdir("conf");
- MioFile = SD.open("conf/conf.txt", FILE_WRITE);
- if (MioFile != false)
- MioFile.println("empty.");
- }
- }
- else {
- Serial.println("Errore nella lettura della SD Card.");
- }
- }
- float checkTemperature(int tempPin) {
- float temp;
- temp = analogRead(tempPin);
- temp = temp * 0.48828125;
- delay(200);
- return temp;
- }
- void setup() {
- Serial.begin(9600);
- //updateIpAddress();
- initSD();
- Ethernet.begin(mac, ip);
- webserver.begin();
- webserver.setDefaultCommand(&outputJson);
- }
- void loop() {
- //float temp = checkTemperature(0);
- webserver.processConnection();
- //checkIpAddress();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement