Created
September 19, 2016 23:42
-
-
Save DrewBarfieldProductions/f713849c6bbae74c8d1895014e46c46f to your computer and use it in GitHub Desktop.
Intel Edison sketch that reports the current temperature.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <WiFi.h> | |
char ssid[] = "YOUR_SSID"; // your network SSID (name) | |
char pass[] = "YOUR_PASS"; // your network password | |
int keyIndex = 0; // your network key Index number (needed only for WEP) | |
int status = WL_IDLE_STATUS; // | |
const int pinTemp = A0; // | |
const int B = 3975; // | |
WiFiServer server(8080); | |
void setup() { | |
pinMode(13, OUTPUT); | |
digitalWrite(13, LOW); | |
//Initialize serial and wait for port to open: | |
Serial.begin(9600); | |
while (!Serial) { | |
} | |
// check for the presence of the shield: | |
if (WiFi.status() == WL_NO_SHIELD) { | |
while(true); | |
} | |
// attempt to connect to Wifi network: | |
while ( status != WL_CONNECTED) { | |
status = WiFi.begin(ssid, pass); | |
delay(10000); | |
} | |
digitalWrite(13, HIGH); | |
server.begin(); | |
} | |
void loop() { | |
// listen for incoming clients | |
WiFiClient client = server.available(); | |
if (client) { | |
// an http request ends with a blank line | |
boolean currentLineIsBlank = true; | |
while (client.connected()) { | |
if (client.available()) { | |
char c = client.read(); | |
if (c == '\n' && currentLineIsBlank) { | |
// send a standard http response header | |
client.println("HTTP/1.1 200 OK"); | |
client.println("Content-Type: text/html"); | |
client.println("Connection: close"); | |
client.println("Refresh: 5"); | |
client.println(); | |
client.println("<!DOCTYPE HTML>"); | |
client.println("<html>"); | |
int val = analogRead(pinTemp); | |
float resistance = (float)(1023-val)*10000/val; | |
float temperature = 1/(log(resistance/10000)/B+1/298.15)-273.15; | |
client.print("<body>"); | |
client.print("<span style='font-size:72pt'>"); | |
client.print(temperature); | |
client.print(" C</span>"); | |
client.print("</body>"); | |
client.println("</html>"); | |
break; | |
} | |
if (c == '\n') { | |
// you're starting a new line | |
currentLineIsBlank = true; | |
} | |
else if (c != '\r') { | |
// you've gotten a character on the current line | |
currentLineIsBlank = false; | |
} | |
} | |
} | |
// give the web browser time to receive the data | |
delay(1); | |
// close the connection: | |
client.stop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment