Final Project Angelica Castro-Mendoza

So my initial project for this final was a poetry generator that got information from Reddit. I wanted it to be bad poetry, because uses would probably figure it was computer generated but I was planning to take it straight from Reddit. The vision was that I’d integrate some kind of physical infrastructure. The idea meandered though due to my  indecisiveness. I planned to serve up the web page using arduino and using the Rita javascript library to scrape from reddit. I wanted to set up an old tv and use a bluetooth signal to trigger the website to change. Despite being super gung ho about this project, I had many problems that ultimately resulted in my work not working.

First, I tried going about familiarizing myself with RiTA library. I tried scrambling words by creating my own grammar rules through coding, which was mistake number one. I should have been using a lexicon or markov chains, I was super coonfused by RiTa’s poor documentation.

So having trouble with this, I decided to work on the physical element of my project. I connected the arduino to an ethernet shield, and set up an infared receiver as opposed to using bluetooth. It was a more reliable alternative to a notoriously unreliable technology(bluetooth, that is). The Ethernet cable was fairly reliable and despite my own computer dying and having to switch computers midway through my project. I was able to serve up a website that was functional and working, which was an easier part of my project. Here was my code to get that working.

#include <SPI.h>
#include <Ethernet.h>
#include <IRSendRev.h>
#define BIT_LEN 0
#define BIT_START_H 1
#define BIT_START_L 2
#define BIT_DATA_H 3
#define BIT_DATA_L 4
#define BIT_DATA_LEN 5
#define BIT_DATA 6

const int pinRecv = 2; // ir receiver connect to D2
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 144);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup(){
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

IR.Init(pinRecv);
Serial.println(“init over”);

// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print(“server is at “);
Serial.println(Ethernet.localIP());
}

unsigned char dta[20];
void loop(){
EthernetClient client = server.available();
if (client) {
Serial.println(“new client”);
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you’ve gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
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”); // the connection will be closed after completion of the response
client.println(“Refresh: 5”); // refresh the page automatically every 5 sec
client.println();
client.println(“<!DOCTYPE HTML>”);
client.println(“<html>”);
// output the value of each analog input pin
for (int digitalChannel = 0; digitalChannel < 6; digitalChannel++) {
int sensorReading = digitalRead(digitalChannel);
client.print(“digital input “);
client.print(digitalChannel);
client.print(” is “);
client.print(sensorReading);
client.println(“<br />”);
}
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();
Serial.println(“client disconnected”);
}

{
if(IR.IsDta()) // get IR data
{
IR.Recv(dta); // receive data to dta

Serial.println(“+——————————————————+”);
Serial.print(“LEN = “);
Serial.println(dta[BIT_LEN]);
Serial.print(“START_H: “);
Serial.print(dta[BIT_START_H]);
Serial.print(“\tSTART_L: “);
Serial.println(dta[BIT_START_L]);

Serial.print(“DATA_H: “);
Serial.print(dta[BIT_DATA_H]);
Serial.print(“\tDATA_L: “);
Serial.println(dta[BIT_DATA_L]);

Serial.print(“\r\nDATA_LEN = “);
Serial.println(dta[BIT_DATA_LEN]);

Serial.print(“DATA: “);
for(int i=0; i<dta[BIT_DATA_LEN]; i++)
{
Serial.print(“0x”);
Serial.print(dta[i+BIT_DATA], HEX);
Serial.print(“\t”);
}
Serial.println();

Serial.print(“DATA: “);
for(int i=0; i<dta[BIT_DATA_LEN]; i++)
{
Serial.print(dta[i+BIT_DATA], DEC);
Serial.print(“\t”);
}
Serial.println();
Serial.println(“+——————————————————+\r\n\r\n”);
}
}
}

Having the physical side working, I really wanted to get the poetry generation side of things working, whether it be scraped from reddit or just generated from from a text file. I then tried using markov chains to scrape reddit. I even got the api key. I kept getting errors about the rita.js library files I was using. I was stumped, because I hoped to just get it to work smoothly and integrate it with my arduino code. No matter what I tried I couldn’t get it to work the way I wanted it to.I was able to get the basic webpage working, but not actually ever calling the reddit API.  I tried moving files, checking directories,using the console, and redownloading the rita libraries to no avail.  Here is some of the code I tried. I modified from Daniel Shiffman’s examples on his website. My modified code with my reddit api key was lost on my other computer, but here is some of the example code I worked off of.

Screen Shot 2017-05-20 at 11.18.05 AMScreen Shot 2017-05-20 at 11.16.17 AM

 

My last resort was just writing all the code on the arduino and having the arduino scramble strings from three separate arrays, add them together, then serve them up when the infared sensor was receiving data.  In theory, this could work. My logic made sense mostly. However, Arduino memory space is super low and I realized I needed to serve up the files from somewhere remote. Here is what I tried though.

#include <SPI.h>
#include <Ethernet.h>
#include <IRSendRev.h>
#define BIT_LEN 0
#define BIT_START_H 1
#define BIT_START_L 2
#define BIT_DATA_H 3
#define BIT_DATA_L 4
#define BIT_DATA_LEN 5
#define BIT_DATA 6

const int pinRecv = 2; // ir receiver connect to D2
char newPoem;
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 144);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

IR.Init(pinRecv);
Serial.println(“init over”);

// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print(“server is at “);
Serial.println(Ethernet.localIP());
}
unsigned char dta[20];
void loop() {
EthernetClient client = server.available();
if (client) {
Serial.println(“new client”);
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you’ve gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
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”); // the connection will be closed after completion of the response
client.println(“Refresh: 5”); // refresh the page automatically every 5 sec
client.println();
client.println(“<!DOCTYPE HTML>”);
client.println(“<html>”);
client.println(“<br />”);
client.println(“Press a button on the remote for a new poem.”);

// output the value of each analog input pin
if (IR.IsDta()) // get IR data
{

client.print(“your new poem”);
client.print(“is”);
client.println(“<br />”);
client.print(“<script>”); var myStrings = [“roses are red”,
“the pool is too cold today”,
“angels cry when they see you”,
“cheeto man has no plan”,
“the moon represents my heart”,
“you ran away and now my heart’s perforated”,
“i am the dancing hippo in fantasia,flailing my limbs around, but with grace”,
“you can’t hold me back”,
“hi,ho,off this bridge i go”,
“He’s a Bukowski stuck in the body of a rodent”,
“listen”,
“i hate your big dumb combat boots”];

var myStrings2 =[ “violets are blue”,
“you are the mac to my cheese”,
“the clock ticks its tocks”,
“my limbs are spilling over my bed”,
“won’t you come home?”,
“carousels keep spinning”,
“wind feels all”,
“sea incapsulates water”,
“bueller?”,
“shades of grey”,
“the light in your room”,
“clear,clear water isn’t really blue”,
“green lights lead me to you”];
var myStrings3=[“who am i?”,
“be a piece of weird furniture in my life.”,
“leave me to drown in the waters of finals.”
“rumble,rumble,thump, thump.”,
“alas, the rivers of life flow on”,
“but o! how i love thee”,
“and i keep staring at the face in your ceiling”,
“keepeth me in thoust heart for eternity.”,
“rose had enough room for jack, goddammit!”,
“wild pangolins hobble through your veins”,
“I can paint with the colors of the wind.”,
“you are like wet socks at amusement parks”,
“the internet sees me.”];

function createPoem(){
var poem;
poem = myStrings[random, 0,10] + myStrings2[random, 0,10]+myStrings3[random, 0,10];
}”</script”);
client.println(“<br />”);
client.println(“Press a button on the remote for a new poem.”);
}

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();
Serial.println(“client disconnected”);

}
//if (digitalChannel == 1) {
// client.println(random);
// }
if (IR.IsDta()) // get IR data
{
IR.Recv(dta); // receive data to dta

Serial.println(“+——————————————————+”);
Serial.print(“LEN = “);
Serial.println(dta[BIT_LEN]);
Serial.print(“START_H: “);
Serial.print(dta[BIT_START_H]);
Serial.print(“\tSTART_L: “);
Serial.println(dta[BIT_START_L]);

Serial.print(“DATA_H: “);
Serial.print(dta[BIT_DATA_H]);
Serial.print(“\tDATA_L: “);
Serial.println(dta[BIT_DATA_L]);

Serial.print(“\r\nDATA_LEN = “);
Serial.println(dta[BIT_DATA_LEN]);

Serial.print(“DATA: “);
for (int i = 0; i < dta[BIT_DATA_LEN]; i++)
{
Serial.print(“0x”);
Serial.print(dta[i + BIT_DATA], HEX);
Serial.print(“\t”);
}
Serial.println();

Serial.print(“DATA: “);
for (int i = 0; i < dta[BIT_DATA_LEN]; i++)
{
Serial.print(dta[i + BIT_DATA], DEC);
Serial.print(“\t”);
}
Serial.println();
Serial.println(“+——————————————————+\r\n\r\n”);
}
}

Mei you memory!! So then I was encouraged to use an SD card, and then try to use an ajax example. I think the ajax strategy legitimately would have worked if I had my own computer. Since ITS wouldn’t allow me to install node. js, that idea was down the drain. Scott stayed calm and told me to use NAS server space. I figured this would work. I was so excited! Maybe, my efforts would result in a working final project. Sadly, my computer from ITS didn’t even have cyberduck on it. I couldn’t even upload the javascript files I had written to the NAS. At this point, it was IMA showtime. I was busy scamming people into my haunted house for staging fright. I threw in the towel and didn’t look back. I honestly tried super hard to make this project work, but in the end, things fell apart. I would say I was misguided in trying to do what I did. I should have just stuck with what I KNEW I could accomplish in two weeks. Given my two other IMA projects, I should have done something that seemed more tangible. I don’t regret challenging myself by working alone, but I definitely should have been smarter about what I could realistically achieve given my time constraints. I also got a more real sense of where things are served up. You can’t just expect arduino magically can serve and store. Plus, I learned that Murphy’s law is just that:a law. It is true. When you most need your computer, it will break. And ITS will have no empathy. And then your phone will die, too, the night of the show, rendering all your documentation pictures useless. IT COULD HAPPEN TO YOU. SO BE WEARY.

 

Leave a Reply