Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*******************************************************************
- * Use the getPrintJob() function to get the current print job on
- * your 3D printer being managed by OctoPrint. Output the current
- * progress of the job on a strip (or circle!) of 'Neopixel' LEDs
- * such as WS2812B. Uses the FastLED library to drive pixels.
- *
- * You will need the IP or hostname of your OctoPrint server, a
- * port number (will be 80 unless you are reaching it from an
- * external source) and an API key from the OctoPrint
- * installation - http://docs.octoprint.org/en/master/api/general.html#authorization
- * You will also need to enable CORS - http://docs.octoprint.org/en/master/api/general.html#cross-origin-requests
- *
- * OctoprintApi by Stephen Ludgate https://www.youtube.com/channel/UCVEEuAouZ6ua4oetLjjHAuw
- *
- * Example based on original work written by A. Fichtner - https://github.com/anfichtn
- *******************************************************************/
- #include <OctoPrintAPI.h> //This is where the magic happens... shazam!
- #include <ESP8266WiFi.h>
- #include <WiFiClient.h>
- #define FASTLED_ESP8266_RAW_PIN_ORDER
- #define FASTLED_INTERRUPT_RETRY_COUNT 0
- #include <FastLED.h> // Uses FastLED Library to drive WS2812B 'Neopixel' LEDs
- #define LED_PIN D4 // The pin connected to Data In on the strip
- #define NUM_LEDS 5 // Number of LED's on your strip
- #define LED_BRIGHTNESS 80 // set Brightness value
- #define MILLI_AMPS 4000 // Maximum current your power source can deliver in mA
- #define CONNECTION_COLOR 0xFF4500 // Purple WiFi connection status color
- CRGB leds[NUM_LEDS];
- const char* ssid = ""; // your network SSID (name)
- const char* password = ""; // your network password
- WiFiClient client;
- // You only need to set one of the of follwowing:
- // IPAddress ip(192, 168, 1, 174); // Your IP address of your OctoPrint server (inernal or external)
- char* octoprint_host = "octopi.local"; // Or your hostname. Comment out one or the other.
- const int octoprint_httpPort = 80; //If you are connecting through a router this will work, but you need a random port forwarded to the OctoPrint server from your router. Enter that port here if you are external
- String octoprint_apikey = ""; //See top of file or GIT Readme about getting API key
- unsigned long api_mtbs = 10000; //mean time between api requests (10 seconds)
- unsigned long api_lasttime = 0; //last time api request has been done
- byte connection_retry = 0;
- byte point = 0;
- long printed_timeout = 3600000; //60 mins in milliseconds - timeout after printing completed, to clear strip
- long printed_timeout_timer = printed_timeout;
- // Use one of the following:
- //OctoprintApi api; //Be sure to call init in setup.
- //OctoprintApi api(client, ip, octoprint_httpPort, octoprint_apikey); //If using IP address
- OctoprintApi api(client, octoprint_host, octoprint_httpPort, octoprint_apikey); //If using hostname. Comment out one or the other.
- void setup() {
- Serial.begin(115200);
- FastLED.addLeds<WS2811, LED_PIN, GRB>(leds, NUM_LEDS);
- FastLED.setDither(false);
- FastLED.setCorrection(TypicalLEDStrip);
- FastLED.setBrightness(LED_BRIGHTNESS);
- FastLED.setMaxPowerInVoltsAndMilliamps(5, MILLI_AMPS);
- fill_solid(leds, NUM_LEDS, CRGB::Black);
- delay(100);
- FastLED.show();
- fill_solid(leds, NUM_LEDS, CRGB::Red);
- delay(1000);
- FastLED.show();
- fill_solid(leds, NUM_LEDS, CRGB::Yellow);
- delay(1000);
- FastLED.show();
- fill_solid(leds, NUM_LEDS, CRGB::Green);
- delay(1000);
- FastLED.show();
- /* Explicitly set the ESP8266 to be a WiFi-client, otherwise, it by default,
- would try to act as both a client and an access-point and could cause
- network-issues with your other WiFi-devices on your WiFi-network. */
- WiFi.mode(WIFI_STA);
- // disconnect if previously connected
- WiFi.disconnect();
- delay(100);
- // We start by connecting to a WiFi network
- Serial.println();
- Serial.println();
- Serial.print("Connecting to ");
- Serial.println(ssid);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(400);
- Serial.print(".");
- fill_solid(leds, NUM_LEDS, CRGB::Black);
- leds[connection_retry] = CONNECTION_COLOR;
- delay(100);
- FastLED.show();
- if (connection_retry == NUM_LEDS) {
- connection_retry = 0;
- } else {
- connection_retry++;
- }
- }
- //Use one of these Only if you have not initialized the api object above with parameters"
- //api.init(client, ip, octoprint_httpPort, octoprint_apikey); //If using IP address
- //api.init(client, octoprint_host, octoprint_httpPort, octoprint_apikey);//If using hostname. Comment out one or the other.
- //if you get here you have connected to the WiFi
- fill_solid(leds, NUM_LEDS, CRGB::Black);
- FastLED.show();
- Serial.println("");
- Serial.println("WiFi connected");
- Serial.println("IP address: ");
- Serial.println(WiFi.localIP());
- }
- void loop() {
- Serial.println("black");
- fill_solid(leds, NUM_LEDS, CRGB::Black);
- FastLED.show();
- delay(2000);
- Serial.println("Red");
- fill_solid(leds, NUM_LEDS, CRGB::Red);
- FastLED.show();
- delay(2000);
- Serial.println("Yellow");
- fill_solid(leds, NUM_LEDS, CRGB::Yellow);
- FastLED.show();
- delay(2000);
- Serial.println("Greenck");
- fill_solid(leds, NUM_LEDS, CRGB::Green);
- FastLED.show();
- delay(2000);
- }
Advertisement
Add Comment
Please, Sign In to add comment