Last active
January 3, 2017 23:51
Revisions
-
ajfisher revised this gist
Mar 18, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ Video: https://www.youtube.com/watch?v=BeIQ47WBVXs ## Acknowledgements Thanks to [Andy Gelme](http://github.com/geekscape) for his [excellent workshop on the ESP8266](https://github.com/geekscape/nodemcu_esp8266) and getting me up to speed on the Lua side. ## Directions -
ajfisher revised this gist
Mar 18, 2015 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,6 +16,10 @@ Video: https://www.youtube.com/watch?v=BeIQ47WBVXs * ESPlora * Pebble SDK and command line tools ## Acknowledgements Thanks to [Andy Gelme](http://github.com/geekscape) for his excellent workshop on the ESP8266 and getting me up to speed on the Lua side. ## Directions * Using ESPTool, flash the ESP8266 with NodeMCU development branch (bins are in this gist) so it has WS8212 support. -
ajfisher revised this gist
Mar 18, 2015 . 2 changed files with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ This is the general instructions for how to get a pebble watch to talk to an ESP8266 and turn NeoPixels different colours.  Video: https://www.youtube.com/watch?v=BeIQ47WBVXs Binary file not shown. -
ajfisher revised this gist
Mar 18, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ This is the general instructions for how to get a pebble watch to talk to an ESP8266 and turn NeoPixels different colours.  Video: https://www.youtube.com/watch?v=BeIQ47WBVXs -
ajfisher revised this gist
Mar 18, 2015 . 2 changed files with 2 additions and 4 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,8 @@ This is the general instructions for how to get a pebble watch to talk to an ESP8266 and turn NeoPixels different colours.  Video: https://www.youtube.com/watch?v=BeIQ47WBVXs ## Prereqs LoadingSorry, something went wrong. Reload?Sorry, we cannot display this file.Sorry, this file is invalid so it cannot be displayed. -
ajfisher revised this gist
Mar 18, 2015 . 1 changed file with 35 additions and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,41 @@ This is the general instructions for how to get a pebble watch to talk to an ESP8266 and turn NeoPixels different colours.  Video: <iframe width="560" height="315" src="https://www.youtube.com/embed/BeIQ47WBVXs" frameborder="0" allowfullscreen></iframe> ## Prereqs * Pebble watch * ESP8266 ESP-01 * NeoPixel strip (or ring or matrix or single pixel) ## Software needed * ESPTool * ESPlora * Pebble SDK and command line tools ## Directions * Using ESPTool, flash the ESP8266 with NodeMCU development branch (bins are in this gist) so it has WS8212 support. * Using ESPlora, change config.lua to have SSID / PASSWORD of your network in them - upload all lua files to the ESP8266 * Wire up the WS2812 strip so data line is connected to GPIO 2 (change this in server.lua if you use a different pin). * Reset the ESP8266 and note it's IP address in ESPlora when it comes up. You should now be able to hit the web server using ``` curl --data "red=255&green=0&blue=255" http://<IP address> ``` * Using CloudPebble, copy app.js contents into the app.js file (make a watch app project and use Pebble JS) * Change the HOST IP address to that of your ESP8266 * Compile and then download the PBW file * Use the developer configuration (as documented by Pebble SDK setup) to run: ``` pebble install watch_led.pbw ``` That's it - you should be able to hit it as expected. -
ajfisher revised this gist
Mar 17, 2015 . 8 changed files with 188 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,64 @@ /** Pebble - ESP8266 - NeoPixel controller Author: Andrew Fisher Licence: MIT **/ var UI = require('ui'); var ajax = require('ajax'); var HOST = '<<IP>>'; // Connect to the ESP8266 and post the data function colour_request(r, g, b) { //console.log("Making request"); //console.log("r:" + r + " g: " + g); var req = { url: HOST, method: 'post', data: {red:r, green:g, blue:b} }; //console.log(JSON.stringify(req)); ajax(req, function(data, status, request) { console.log(data); }, function(data, status, request) { console.log('The ajax request failed: ' + data + status + JSON.stringify(request)); } ); } // Make a list of the colours to select var colours = [ { title: "OFF", r: 0, g: 0, b: 0, }, { title: "RED", r: 255, g: 0, b: 0, }, { title: "GREEN", r: 0, g: 255, b: 0, }, { title: "BLUE", r: 0, g: 0, b: 255, }, { title: "YELLOW", r: 255, g: 255, b: 0, }, { title: "MAGENTA", r: 255, g: 0, b: 255, }, { title: "CYAN", r: 0, g: 255, b: 255, }, { title: "WHITE", r: 255, g: 255, b: 255, }, ]; // Create the Menu var menu = new UI.Menu({ sections: [{ title: 'Choose LED colour', items: colours }] }); // Send command when menu item is selected menu.on('select', function(e) { colour_request(e.item.r, e.item.g, e.item.b); }); menu.show(); This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ local module = {} function module.start() print("application start") print("IP address: " .. wifi.sta.getip()) dofile("server.lua") end return module This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ local module = {} module.SSID = {} module.SSID["SSID"] = "PASSWORD" return module This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ app = require("application") config = require("config") require("setup").start() Binary file not shown.Binary file not shown.This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,73 @@ local PORT = 80 local LED_PIN = 4 -- GPIO 2 local BRIGHTNESS = 0.2 -- NeoPixels are BRIGHT. local NO_PIXELS = 17 if server then print("Closing existing server") server:close() end print("Starting server on: " .. wifi.sta.getip() .. ":" .. PORT) server = net.createServer(net.TCP) server:listen(PORT, function(conn) conn:on("receive", function(client, payload) -- print(payload) local head = "" local body = "" local colours = {} colours["red"] = 0 colours["green"] = 0 colours["blue"] = 0 if (string.sub(payload, 1, 4) == "POST") then head = head .. "HTTP/1.1 200 OK\r\n" head = head .. "Content-Type: application/json\r\n" -- now we find the RGB components. Going to do this simply -- by ripping them out with a find statement for c, v in pairs(colours) do local match = c .. "=(%d*)" _, _, colours[c] = string.find(payload, match) -- put in a catch here incase it goes nil end set_led_colour(colours, NO_PIXELS) -- send the JSON back to confirm body = body .. "{\"r\":" .. colours["red"] .. ", " body = body .. "\"g\":" .. colours["green"] .. ", " body = body .. "\"b\":" .. colours["blue"] .. "}" else head = head .. "HTTP/1.1 500 Server Error\r\n" body = body .. "Please ensure you use a POST method" end body = body .. "\r\n" -- just tidy up the end of the file head = head .. "Content-Length: " .. string.len(body) .. "\r\n\r\n" --print(head .. body) client:send(head .. body) end) conn:on("sent", function(client) client:close() end) end) function create_colour(red, green, blue) -- takes the colours and makes single value for writing to the LEDs local colour = string.char(green * BRIGHTNESS, red * BRIGHTNESS, blue * BRIGHTNESS) return colour end function set_led_colour(colours, pixels) -- takes the colour values and writes that to the number of pixels -- assmues a table colours{"red":val, "green":val, "blue":val} ws2812.write(LED_PIN, create_colour(colours["red"], colours["green"], colours["blue"]):rep(pixels)) end This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ local module = {} local function wifi_wait_ip() if wifi.sta.getip() then tmr.stop(1) -- print("wifi ready: " .. wifi.sta.getip()) app.start() end end local function wifi_start(aps) for key,value in pairs(aps) do -- print("wifi AP: " .. key .. ": " .. value) if config.SSID and config.SSID[key] then wifi.sta.config(key, config.SSID[key]) wifi.sta.connect() config.SSID = nil -- more secure and save memory tmr.alarm(1, 2500, 1, wifi_wait_ip) end end end function module.start() wifi.setmode(wifi.STATION); wifi.sta.getap(wifi_start) end return module -
ajfisher created this gist
Mar 15, 2015 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ _This is a placeholder at the moment. Just watch this Gist for code etc coming over the next day or so_ ## Prereqs * Pebble watch * ESP8266 ESP-01 * NeoPixel strip (or ring or matrix or single pixel) *