I need to “send” a tSet (temperature setting / desired room temperaure) to the Arduino. I can set the tSet using buttons on the breadboard, but I certainly would like to set the tSet through a wifi connection over the internet. Ideally, I would have a web based (or mobile android based) app that “pushes” the tSet variable to the Arduino. That seems really difficult, but I would love to try if anybody has any advice for pursuing that (java applet that pushes tSet to Arduino acting as a client…???).
The simpler plan I am proceeding with (one week until project day) is to just type my desired tSet on a webpage and have the Arduino “get” that webpage and read the tSet number. My idea is to use a google doc as the page to upload my tSet, because google docs are easy to edit and upload (maybe this is my bad decision). Here is the google doc I am using for this. It is freely viewable.
https://docs.google.com/document/d/1zzZiicQ5zlc0evlxEkyygvefJj1YpEUcgnJ2B5pdoFw/edit
So to “get” this page, I use the following code in my program:
client.println("GET /document/d/1zzZiicQ5zlc0evlxEkyygvefJj1YpEUcgnJ2B5pdoFw/edit HTTP/1.1");
client.println("Host: docs.google.com");
(Entire Code attached at bottom)
(I have tried this with and without the “edit” at the end of the address)
But I get an unexpected response to this “get” statement. Instead of getting the webpage contents, I get a “HTTP/1.1 301 Moved Permanently” error. The error tells me the page has moved, but then gives me back the exact page address that I was trying to get. Here is the full response to the “get” command:
HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=UTF-8
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Sat, 22 Aug 2015 07:16:01 GMT
Location: https://docs.google.com/document/d/1zzZiicQ5zlc0evlxEkyygvefJj1YpEUcgnJ2B5pdoFw/edit
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Accept-Ranges: none
Vary: Accept-Encoding
Connection: close
<HTML>
<HEAD>
<TITLE>Moved Permanently</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Moved Permanently</H1>
The document has moved <A HREF="https://docs.google.com/document/d/1zzZiicQ5zlc0evlxEkyygvefJj1YpEUcgnJ2B5pdoFw/edit">here</A>.
</BODY>
</HTML>
So my questions are:
- Any idea why my query to docs.google.com doesn’t work and how to make it work?
or - If the problem is inherent to docs.google.com any other domain suggestion where the page is easily editable?
or - Any tips to pursue my “ideal” solution of actually “push” the tSet variable to the Arduino?
Thanks,
Drew
(entire code here)
/*
Web client
This sketch connects to a website using a WiFi shield.
*/
#include <SPI.h>
#include <WiFi.h>
char ssid[] = "twosom2F"; // your network SSID (name)
char pass[] = "027421008"; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0; // your network key Index number (needed only for WEP)
int status = WL_IDLE_STATUS;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
char server[] = "docs.google.com";
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
WiFiClient client;
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while(true);
}
// attempt to connect to Wifi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 5 seconds for connection:
delay(5000);
}
Serial.println("Connected to wifi");
printWifiStatus();
Serial.println("\nStarting connection to server...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected to server");
// Make a HTTP request:
client.println("GET /document/d/1zzZiicQ5zlc0evlxEkyygvefJj1YpEUcgnJ2B5pdoFw/edit HTTP/1.1");
client.println("Host: docs.google.com");
client.println("Connection: close");
client.println();
}
}
void loop() {
// if there are incoming bytes available
// from the server, read them and print them:
while (client.available()) {
char c = client.read();
Serial.write(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting from server.");
client.stop();
// do nothing forevermore:
while(true);
}
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}