Stripping out CC3000 and HTTP stuff
This commit is contained in:
parent
20338148e2
commit
961617ecd7
13 changed files with 5 additions and 425 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
teensy/build-*/
|
||||||
|
|
|
@ -6,10 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "lua.hpp"
|
#include "lua.hpp"
|
||||||
#include "wifi.h"
|
|
||||||
#include "http_lib.h"
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "leds.h"
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// initialize the digital pin as an output.
|
// initialize the digital pin as an output.
|
||||||
|
@ -19,18 +16,8 @@ void setup() {
|
||||||
delay(10000);
|
delay(10000);
|
||||||
|
|
||||||
l_init();
|
l_init();
|
||||||
setup_cc3000();
|
|
||||||
start_http();
|
|
||||||
setup_leds();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
l_frame();
|
l_frame();
|
||||||
listen_http();
|
|
||||||
loop_leds();
|
|
||||||
|
|
||||||
//digitalWrite(13, HIGH); // set the LED on
|
|
||||||
//delay(100); // wait for a second
|
|
||||||
//digitalWrite(13, LOW); // set the LED off
|
|
||||||
//delay(100); // wait for a second
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
BOARD_TAG = teensy31
|
BOARD_TAG = teensy31
|
||||||
ARDUINO_LIBS = Adafruit_CC3000 FastLED SPI
|
ARDUINO_LIBS = SPI Adafruit_GFX RGBmatrixPanel
|
||||||
ARDUINO_DIR = /home/ryan/arduino/arduino-1.6.5
|
ARDUINO_DIR = /home/ryan/arduino/1.0.6/arduino-1.0.6/
|
||||||
|
|
||||||
#AVR_TOOLS_DIR=/home/ryan/arduino/gcc-4.9/prefix/
|
#AVR_TOOLS_DIR=/home/ryan/arduino/gcc-4.9/prefix/
|
||||||
|
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
|
|
||||||
#include <avr/pgmspace.h>
|
|
||||||
|
|
||||||
#define HANDLER(meth, num) void handle_ ## meth (Adafruit_CC3000_ClientRef &client) { \
|
|
||||||
uint8_t buffer[64]; \
|
|
||||||
memset(buffer, 0, 63); \
|
|
||||||
\
|
|
||||||
for (uint8_t p = 0; p < 63; p++) { \
|
|
||||||
buffer[p] = client.read(); \
|
|
||||||
\
|
|
||||||
if (buffer[p] == ' ' || buffer[p] == '?') { \
|
|
||||||
buffer[p] = 0; \
|
|
||||||
break; \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
debug_log("GOT URL: "); \
|
|
||||||
debug_log((const char *) buffer); \
|
|
||||||
\
|
|
||||||
uint16_t length = sizeof(meth ## _LIST)/sizeof(meth ## _LIST[0]); \
|
|
||||||
\
|
|
||||||
debug_log("GET_LIST SIZE: "); \
|
|
||||||
debug_log(length); \
|
|
||||||
\
|
|
||||||
for (size_t i = 0; i < length; i++) { \
|
|
||||||
debug_log("Checking: "); \
|
|
||||||
debug_log(i); \
|
|
||||||
char path[64]; \
|
|
||||||
strncpy_P(path, meth ## _LIST[i].path, 63); \
|
|
||||||
debug_log("Path: "); \
|
|
||||||
debug_log(path); \
|
|
||||||
debug_logf((int) meth ## _LIST[i].path, HEX); \
|
|
||||||
debug_logf((int) root_path, HEX); \
|
|
||||||
\
|
|
||||||
if (!strncmp_P((const char *)buffer, meth ## _LIST[i].path, 63)) { \
|
|
||||||
skip_headers(client, num); \
|
|
||||||
(* meth ## _LIST[i].function)(client, num); \
|
|
||||||
client.println(F("\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n")); \
|
|
||||||
return; \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
give_404(client, 0); \
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define PUSH(x) for(int i=0; i<3; i++) buffer[i] = buffer[i+1]; buffer[3]=x;
|
|
||||||
#define CHECK_BUF (buffer[0] == '\r' && buffer[1] == '\n' && buffer[2] == '\r' && buffer[3] == '\n')
|
|
||||||
|
|
||||||
METHOD(skip_headers) {
|
|
||||||
uint8_t buffer[4] = {0,0,0,0};
|
|
||||||
uint8_t c;
|
|
||||||
|
|
||||||
// Look for a \r\n\r\n pattern in the incoming data, that'll be the end of the headers
|
|
||||||
while(! CHECK_BUF) {
|
|
||||||
c = client.read();
|
|
||||||
PUSH(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HANDLER(GET, 0);
|
|
||||||
HANDLER(POST, 1);
|
|
|
@ -1,170 +0,0 @@
|
||||||
#include "docs.h"
|
|
||||||
#include "log.h"
|
|
||||||
#include "lua.hpp"
|
|
||||||
|
|
||||||
const int GET = 0;
|
|
||||||
const int POST = 1;
|
|
||||||
|
|
||||||
#define METHOD(x) void x (Adafruit_CC3000_ClientRef &client, int method)
|
|
||||||
|
|
||||||
METHOD(give_200) {
|
|
||||||
client.fastrprint("HTTP/1.0 200 OK\r\n"
|
|
||||||
"Server: MiniC HTTPD 0.1\r\n"
|
|
||||||
"\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
METHOD(give_400) {
|
|
||||||
client.fastrprint("HTTP/1.0 400 Bad Request\r\n"
|
|
||||||
"Server: MiniC HTTPD 0.1\r\n"
|
|
||||||
"\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
METHOD(give_404) {
|
|
||||||
client.fastrprint("HTTP/1.0 404 Not Found\r\n"
|
|
||||||
"Server: MiniC HTTPD 0.1\r\n"
|
|
||||||
"\r\n");
|
|
||||||
client.fastrprint("Not found\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
METHOD(give_200_gzip) {
|
|
||||||
client.fastrprint("HTTP/1.0 200 OK\r\n"
|
|
||||||
"Server: MiniC HTTPD 0.1\r\n"
|
|
||||||
"Content-Encoding: gzip\r\n"
|
|
||||||
"\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helpers
|
|
||||||
int read_name(Adafruit_CC3000_ClientRef &client, char *str) {
|
|
||||||
uint8_t i = 0,c = 0;
|
|
||||||
for (i=0; i<16 && c != '='; i++) {
|
|
||||||
c = client.read();
|
|
||||||
str[i] = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
str[i-1] = 0; // end the string
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
int read_value(Adafruit_CC3000_ClientRef &client, char *str) {
|
|
||||||
uint8_t i = 0,c = 0;
|
|
||||||
|
|
||||||
for (i=0; i<16 && c != '&' && client.available(); i++) {
|
|
||||||
c = client.read();
|
|
||||||
str[i] = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (str[i-1] == '&')
|
|
||||||
str[i-1] = 0;
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
// METHODS
|
|
||||||
METHOD(root) {
|
|
||||||
give_200_gzip(client, method);
|
|
||||||
|
|
||||||
for (uint16_t i = 0; i < sizeof(doc_gzip); i++)
|
|
||||||
client.write(pgm_read_byte(&doc_gzip[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Converts a hex character to its integer value */
|
|
||||||
char from_hex(char ch) {
|
|
||||||
return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
METHOD(interface) {
|
|
||||||
if (method == GET) {
|
|
||||||
give_200(client, method);
|
|
||||||
for (uint16_t i = 0; i < sizeof(inter_head); i++)
|
|
||||||
client.write(pgm_read_byte(&inter_head[i]));
|
|
||||||
|
|
||||||
for (uint16_t i = 0; i < sizeof(l_prog_buff) && l_prog_buff[i]; i++)
|
|
||||||
client.write(pgm_read_byte(&l_prog_buff[i]));
|
|
||||||
|
|
||||||
for (uint16_t i = 0; i < sizeof(inter_foot); i++)
|
|
||||||
client.write(pgm_read_byte(&inter_foot[i]));
|
|
||||||
} else {
|
|
||||||
if (client.available()) {
|
|
||||||
char name[16];
|
|
||||||
read_name(client, name);
|
|
||||||
|
|
||||||
if (!strncmp(name, "prgm", 16)) {
|
|
||||||
int i = 0;
|
|
||||||
char c;
|
|
||||||
memset(l_prog_buff, 0, sizeof(l_prog_buff));
|
|
||||||
for (i = 0; i < sizeof(l_prog_buff) && client.available(); i++) {
|
|
||||||
c = client.read();
|
|
||||||
|
|
||||||
if (c != '+' && c != '%') { // non-encoded char
|
|
||||||
l_prog_buff[i] = c;
|
|
||||||
} else if (c == '+') { // url encoded space
|
|
||||||
l_prog_buff[i] = ' ';
|
|
||||||
} else if (c == '%') { // % encoded string
|
|
||||||
char a, b;
|
|
||||||
a = client.read();
|
|
||||||
b = client.read();
|
|
||||||
|
|
||||||
c = from_hex(a) << 4 | from_hex(b);
|
|
||||||
l_prog_buff[i] = c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
output_log("\n");
|
|
||||||
output_log("Program loaded, compiling...\n");
|
|
||||||
l_stop();
|
|
||||||
l_start(l_prog_buff);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface(client, GET); // give back the same GET output that we had before
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
METHOD(output) {
|
|
||||||
give_200(client, method);
|
|
||||||
|
|
||||||
char *p = log_curpos+1;
|
|
||||||
if (p - log_ringbuffer >= LOG_RINGSIZE)
|
|
||||||
p = log_ringbuffer;
|
|
||||||
|
|
||||||
|
|
||||||
client.fastrprint("<html><head><meta http-equiv=\"refresh\" content=\"5\"><body><pre>");
|
|
||||||
while(p != log_curpos) {
|
|
||||||
if (*p)
|
|
||||||
client.write(*p);
|
|
||||||
|
|
||||||
p++;
|
|
||||||
|
|
||||||
if (p - log_ringbuffer >= LOG_RINGSIZE)
|
|
||||||
p = log_ringbuffer;
|
|
||||||
}
|
|
||||||
client.fastrprint("</pre></body></html>");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup the path resolver
|
|
||||||
struct method_resolve {
|
|
||||||
const prog_char *path;
|
|
||||||
void (*function)(Adafruit_CC3000_ClientRef&, int method);
|
|
||||||
};
|
|
||||||
|
|
||||||
#define FPATH(x) const prog_char x [] PROGMEM
|
|
||||||
#define ROUTE(m, p) {(const prog_char *) &p [0], m}
|
|
||||||
|
|
||||||
FPATH(root_path) = "/";
|
|
||||||
FPATH(output_path) = "/output";
|
|
||||||
FPATH(interface_path) = "/interface";
|
|
||||||
|
|
||||||
method_resolve GET_LIST[] = {
|
|
||||||
ROUTE(root, root_path),
|
|
||||||
ROUTE(output, output_path),
|
|
||||||
ROUTE(interface, interface_path),
|
|
||||||
};
|
|
||||||
|
|
||||||
method_resolve POST_LIST[] = {
|
|
||||||
ROUTE(root, root_path),
|
|
||||||
ROUTE(interface, interface_path),
|
|
||||||
};
|
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
#include "log.h"
|
|
||||||
#include "http_lib.h"
|
|
||||||
#include "handlers.h"
|
|
||||||
#include "dispatch.h"
|
|
||||||
#include <Adafruit_CC3000.h>
|
|
||||||
|
|
||||||
Adafruit_CC3000_Server httpServer(80);
|
|
||||||
|
|
||||||
void start_http() {
|
|
||||||
httpServer.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
void read_method(Adafruit_CC3000_ClientRef &client) {
|
|
||||||
uint8_t method[9];
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 8; i++) {
|
|
||||||
method[i] = client.read();
|
|
||||||
if (method[i] == ' ') {
|
|
||||||
method[i] = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!strncmp((const char *) method, "GET", 8)) {
|
|
||||||
handle_GET(client);
|
|
||||||
} else if (!strncmp((const char *) method, "POST", 8)) {
|
|
||||||
handle_POST(client);
|
|
||||||
} else {
|
|
||||||
// return a 400 to anything else.
|
|
||||||
client.fastrprint("HTTP/1.0 400 Bad Request\r\n"
|
|
||||||
"Server: MiniC HTTPD 0.1\r\n"
|
|
||||||
"\r\n"
|
|
||||||
"The fuck is wrong with you trying other methods?\r\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void listen_http() {
|
|
||||||
Adafruit_CC3000_ClientRef client = httpServer.available();
|
|
||||||
|
|
||||||
if (client) {
|
|
||||||
debug_log("GOT REQUEST, READING METHOD");
|
|
||||||
read_method(client);
|
|
||||||
client.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
client.close();
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
#ifndef __LUALIGHTS_HTTP_LIB_H
|
|
||||||
#define __LUALIGHTS_HTTP_LIB_H
|
|
||||||
|
|
||||||
#include <Adafruit_CC3000.h>
|
|
||||||
|
|
||||||
extern Adafruit_CC3000_Server httpServer;
|
|
||||||
void start_http();
|
|
||||||
void listen_http();
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,21 +0,0 @@
|
||||||
#include "leds.h"
|
|
||||||
#include <FastLED.h>
|
|
||||||
|
|
||||||
CRGB led_data[MAX_NUM_LEDS];
|
|
||||||
|
|
||||||
// For led chips like Neopixels, which have a data line, ground, and power, you just
|
|
||||||
// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
|
|
||||||
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
|
|
||||||
#define DATA_PIN 6
|
|
||||||
#define CLOCK_PIN 7
|
|
||||||
|
|
||||||
void setup_leds() {
|
|
||||||
FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(led_data, MAX_NUM_LEDS);
|
|
||||||
};
|
|
||||||
|
|
||||||
void loop_leds() {
|
|
||||||
// for(int i = 0; i < 10; i++)
|
|
||||||
// led_data[i] = CRGB::White;
|
|
||||||
|
|
||||||
FastLED.show();
|
|
||||||
};
|
|
|
@ -1,13 +0,0 @@
|
||||||
#ifndef __LUALIGHTS_LEDS_H
|
|
||||||
#define __LUALIGHTS_LEDS_H
|
|
||||||
|
|
||||||
#include <FastLED.h>
|
|
||||||
|
|
||||||
#define MAX_NUM_LEDS 500
|
|
||||||
|
|
||||||
extern CRGB led_data[];
|
|
||||||
|
|
||||||
void setup_leds();
|
|
||||||
void loop_leds();
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -3,7 +3,7 @@
|
||||||
// This line defines a "Uart" object to access the serial port
|
// This line defines a "Uart" object to access the serial port
|
||||||
// HardwareSerial CommOut = HardwareSerial();
|
// HardwareSerial CommOut = HardwareSerial();
|
||||||
// usb_serial_class LogOut = Serial;
|
// usb_serial_class LogOut = Serial;
|
||||||
#define LogOut Serial
|
#define LogOut Serial3
|
||||||
#define LOG_RINGSIZE 4096
|
#define LOG_RINGSIZE 4096
|
||||||
|
|
||||||
extern char log_ringbuffer[LOG_RINGSIZE + 1]; // ring buffer for the output log
|
extern char log_ringbuffer[LOG_RINGSIZE + 1]; // ring buffer for the output log
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "leds.h"
|
|
||||||
#include "lua.hpp"
|
#include "lua.hpp"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
|
@ -1,81 +0,0 @@
|
||||||
#include <Adafruit_CC3000.h>
|
|
||||||
#include "log.h"
|
|
||||||
|
|
||||||
// These are the interrupt and control pins
|
|
||||||
#define ADAFRUIT_CC3000_IRQ 8 // MUST be an interrupt pin!
|
|
||||||
// These can be any two pins
|
|
||||||
#define ADAFRUIT_CC3000_VBAT 9
|
|
||||||
#define ADAFRUIT_CC3000_CS 10
|
|
||||||
// Use hardware SPI for the remaining pins
|
|
||||||
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11
|
|
||||||
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
|
|
||||||
SPI_CLOCK_DIV4); // you can change this clock speed but DI
|
|
||||||
|
|
||||||
#define WLAN_SSID "Scalar24" // cannot be longer than 32 characters!
|
|
||||||
#define WLAN_PASS "Fb274Gh@12G1"
|
|
||||||
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
|
|
||||||
#define WLAN_SECURITY WLAN_SEC_WPA2
|
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/*!
|
|
||||||
@brief Tries to read the IP address and other connection details
|
|
||||||
*/
|
|
||||||
/**************************************************************************/
|
|
||||||
bool displayConnectionDetails(void)
|
|
||||||
{
|
|
||||||
uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
|
|
||||||
|
|
||||||
if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
|
|
||||||
{
|
|
||||||
// Useless for this to be in the output buffer, you couldn't see it
|
|
||||||
debug_log("Unable to retrieve the IP Address!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
char buff[64];
|
|
||||||
sprintf(buff, "IP Addr: %d.%d.%d.%d", (uint) (ipAddress & 0xFF000000) >> 24, (uint) (ipAddress & 0xFF0000) >> 16, (uint) (ipAddress & 0xFF00) >> 8, (uint) (ipAddress & 0xFF));
|
|
||||||
debug_log(buff);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup_cc3000() {
|
|
||||||
/* Initialise the module */
|
|
||||||
|
|
||||||
cc3000.setPrinter(NULL); //dynamic_cast<Print *>(&LogOut));
|
|
||||||
if (!cc3000.begin())
|
|
||||||
{
|
|
||||||
debug_log("Unable to initialise the CC3000! Check your wiring?");
|
|
||||||
while(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Attempt to connect to an access point */
|
|
||||||
if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
|
|
||||||
debug_log("Failed to connect to AP!");
|
|
||||||
while(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!cc3000.checkDHCP())
|
|
||||||
{
|
|
||||||
delay(100); // ToDo: Insert a DHCP timeout!, could use the motion counter if i init that first..
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Display the IP address DNS, Gateway, etc. */
|
|
||||||
while (! displayConnectionDetails()) {
|
|
||||||
delay(1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t mdns = 0;
|
|
||||||
void loop_wifi() {
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (!(motion_countup & 0xF) && !mdns) {
|
|
||||||
LogOut.println(F("mDNS send"));
|
|
||||||
mdnsAdvertiser(1, "Kitchen", sizeof("Kitchen"));
|
|
||||||
mdns = 1;
|
|
||||||
} else {
|
|
||||||
mdns = 0;
|
|
||||||
}*/
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
bool displayConnectionDetails(void);
|
|
||||||
void setup_cc3000();
|
|
||||||
void loop_wifi();
|
|
Loading…
Add table
Reference in a new issue