Wednesday, November 30, 2016

TI-99/4A & Woods WiOn IOT Home Automation Testing

So, I decided that I would expand on this past experiment:
Woods WiOn Indoor Wi-Fi Outlet Modification (Amazon Echo Too!)

***NOTE*** This is a work in progress, and who knows where it will go as it is just BSing around.

I wrote a different program, utilizing the Arduino IDE, that would allow my TI-99/4A to make a connection to this device, utilizing Stuart's Web Browser.

WiOn_TI99 ESP8266 Arduino Code:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

const char* ssid = "FrogFi";
const char* password = "**********";

ESP8266WebServer server(80);

const int relay = 15;

void handleRoot() { 
  Serial.println("test");
  server.send(200, "text/html", "<99ml><p>TEST</p></99ml>");
}
void handleNotFound(){
  digitalWrite(relay, 1);
  String message = "<99ml><p>File Not Found</p></99ml>";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET)?"GET":"POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i=0; i<server.args(); i++){
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  server.send(404, "text/plain", message);
  digitalWrite(relay, 0);
}

void setup(void){
  pinMode(relay, OUTPUT);
  digitalWrite(relay, 0);
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  if (MDNS.begin("esp8266")) {
    Serial.println("MDNS responder started");
  }

  server.on("/", handleRoot);

  server.on("/on", [](){
    server.send(200, "text/html", "<99ml><p>ON</p></99ml>");
    digitalWrite(relay, 1);
  });

  server.on("/off", [](){
    server.send(200, "text/plain", "<99ml><p>OFF</p></99ml>");
    digitalWrite(relay, 0);
  });

  server.onNotFound(handleNotFound);

  server.begin();
  Serial.println("HTTP server started");
}

void loop(void){
  server.handleClient();
}

I did run into some problems, that I am still working through.  This little web-server not being kind to the older & slower TI.

I figured this out by utilizing telnet.  I would telnet into port 80, on the device, and I noticed that it didn't give very much time to issue HTTP commands like: [GET / HTTP/1.1]

I have been working though the timing by messing with ESP8266WebServer.h, that is part of the esp8266/Arduino libraries.

ESP8266WebServer.h
...
#define HTTP_DOWNLOAD_UNIT_SIZE 1460
#define HTTP_UPLOAD_BUFLEN 2048
#define HTTP_MAX_DATA_WAIT 1000 //ms to wait for the client to send the request
#define HTTP_MAX_POST_WAIT 1000 //ms to wait for POST data to arrive
#define HTTP_MAX_CLOSE_WAIT 200 //ms to wait for the client to close the connection
...

HTTP_MAX_DATA_WAIT is the value that seems to give the TI some time.

I noticed the ESP8266WebServer.h out in the GitHub project has some more timing settings:

I may want to upgrade the packages that I am using.

The good news is, I was able to turn a lamp on, from my TI-99/4A. :)

It is probably a better idea to have a modern server talk to the ESP8266 devices, and have the TI go through that.  That would allow more devices, and a centralized website created for all of them.   It would also eliminate having to play around with the timing on these.

Friday, April 29, 2016

Woods WiOn Indoor Wi-Fi Outlet Modification (Amazon Echo Too!)

I've acquired one of these smart device controlled outlets. It's really cool. You can turn 120v devices on and off, remotely, from your mobile device.

Modified WiOn:


I decided to open it up to see what is inside. I noticed that it uses the same module as the Adafruit Industries HUZZAH ESP8266 breakout board, that I happened to have bought last year.

I had to add the wiring, and push button, that would allow me to reprogram this device via USB.  I specifically utilized the Arduino IDE.

Pinout: