Skip to content

Instantly share code, notes, and snippets.

@erinzm
Created May 9, 2015 02:43
Show Gist options
  • Save erinzm/ae049a7c440e1e12798e to your computer and use it in GitHub Desktop.
Save erinzm/ae049a7c440e1e12798e to your computer and use it in GitHub Desktop.
Phant from an ESP8266
#include <ESP8266WiFi.h>
const char *ssid = "*redacted*";
const char *password = "*redacted*";
const char *phant_public_key = "pwz6Xgv697hdJdoMA9qm";
const char *phant_private_key = "*redacted*";
const char *phant_host = "data.sparkfun.com";
void setup() {
Serial.begin(115200);
delay(10);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("Wifi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
WiFiClient client;
if (!client.connect(phant_host, 80)) {
Serial.println("connection failed");
return;
}
client.print("GET /input/");
delay(10);
client.print(phant_public_key);
delay(10);
client.print("?private_key=");
delay(10);
client.print(phant_private_key);
delay(10);
client.print("&light=");
delay(10);
client.print(analogRead(0));
delay(10);
client.println(" HTTP/1.1");
delay(10);
client.print("Host: ");
delay(10);
client.println(phant_host);
delay(10);
client.println("Connection: close");
delay(10);
client.println();
delay(10);
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
client.flush();
client.stop();
yield();
delay(5000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment