├── .gitattributes ├── DrawBot_Badge ├── BTconfig.cpp ├── BTconfig.h ├── DrawBot_Badge.ino ├── commands.cpp ├── commands.h ├── config.h ├── coolant_control.cpp ├── coolant_control.h ├── cpu_map.h ├── data │ ├── favicon.ico │ └── index.html.gz ├── defaults.h ├── eeprom.cpp ├── eeprom.h ├── espresponse.cpp ├── espresponse.h ├── gcode.cpp ├── gcode.h ├── grbl.h ├── grbl_sd.cpp ├── grbl_sd.h ├── jog.cpp ├── jog.h ├── limits.cpp ├── limits.h ├── motion_control.cpp ├── motion_control.h ├── nofile.h ├── nuts_bolts.cpp ├── nuts_bolts.h ├── planner.cpp ├── planner.h ├── print.cpp ├── print.h ├── probe.cpp ├── probe.h ├── protocol.cpp ├── protocol.h ├── report.cpp ├── report.h ├── serial.cpp ├── serial.h ├── serial2socket.cpp ├── serial2socket.h ├── servo.cpp ├── servo.h ├── settings.cpp ├── settings.h ├── spindle_control.cpp ├── spindle_control.h ├── stepper.cpp ├── stepper.h ├── system.cpp ├── system.h ├── tdef.h ├── telnet_server.cpp ├── telnet_server.h ├── web_server.cpp ├── web_server.h ├── wificonfig.cpp ├── wificonfig.h ├── wifiservices.cpp └── wifiservices.h ├── README.md ├── SourceFiles ├── GCode │ ├── Hackaday_logo.nc │ ├── OSHW_Logo.nc │ ├── PS1_Logo.gcode │ └── PS1_Logo.nc ├── PDF │ └── Schematic_v1p1.pdf ├── STEP │ └── DrawBot_Badge_assy.stp └── STL │ ├── drawbadge_base.stl │ ├── drawbadge_base_simple.stl │ ├── drawbadge_linkage.stl │ ├── drawbadge_pen_arm.stl │ ├── drawbadge_servo_a_arm.stl │ ├── drawbadge_servo_b_arm.stl │ ├── drawbadge_servo_box.stl │ ├── drawbadge_z_cam.stl │ └── knob_5mm_screw.stl ├── doc └── csv │ ├── alarm_codes_en_US.csv │ ├── build_option_codes_en_US.csv │ ├── error_codes_en_US.csv │ └── setting_codes_en_US.csv ├── embedded ├── build.bat ├── gulpfile.js ├── install.bat ├── out.h ├── package.json ├── tool.html.gz └── www │ ├── css │ └── style.css │ ├── js │ └── script.js │ └── tool.html └── libraries ├── ESP32SSDP ├── ESP32SSDP.cpp ├── ESP32SSDP.h ├── README.rst ├── examples │ └── SSDP │ │ └── SSDP.ino ├── keywords.txt └── library.properties └── arduinoWebSockets ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── examples ├── Nginx │ └── esp8266.ssl.reverse.proxy.conf ├── avr │ └── WebSocketClientAVR │ │ └── WebSocketClientAVR.ino ├── esp32 │ ├── WebSocketClient │ │ └── WebSocketClient.ino │ ├── WebSocketClientSSL │ │ └── WebSocketClientSSL.ino │ └── WebSocketServer │ │ └── WebSocketServer.ino ├── esp8266 │ ├── WebSocketClient │ │ └── WebSocketClient.ino │ ├── WebSocketClientSSL │ │ └── WebSocketClientSSL.ino │ ├── WebSocketClientSocketIO │ │ └── WebSocketClientSocketIO.ino │ ├── WebSocketClientStomp │ │ └── WebSocketClientStomp.ino │ ├── WebSocketClientStompOverSockJs │ │ └── WebSocketClientStompOverSockJs.ino │ ├── WebSocketServer │ │ └── WebSocketServer.ino │ ├── WebSocketServerAllFunctionsDemo │ │ └── WebSocketServerAllFunctionsDemo.ino │ ├── WebSocketServerFragmentation │ │ └── WebSocketServerFragmentation.ino │ ├── WebSocketServerHttpHeaderValidation │ │ └── WebSocketServerHttpHeaderValidation.ino │ └── WebSocketServer_LEDcontrol │ │ └── WebSocketServer_LEDcontrol.ino └── particle │ └── ParticleWebSocketClient │ └── application.cpp ├── library.json ├── library.properties ├── src ├── WebSockets.cpp ├── WebSockets.h ├── WebSocketsClient.cpp ├── WebSocketsClient.h ├── WebSocketsServer.cpp ├── WebSocketsServer.h ├── libb64 │ ├── AUTHORS │ ├── LICENSE │ ├── cdecode.c │ ├── cdecode_inc.h │ ├── cencode.c │ └── cencode_inc.h └── libsha1 │ ├── libsha1.c │ └── libsha1.h ├── tests ├── webSocket.html └── webSocketServer │ ├── index.js │ └── package.json └── travis └── common.sh /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /DrawBot_Badge/BTconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | BTconfig.h - Bluetooth functions class 3 | 4 | Copyright (c) 2014 Luc Lebosse. All rights reserved. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED) 21 | #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it 22 | #endif 23 | 24 | //Preferences entries 25 | #define BT_NAME_ENTRY "BT_NAME" 26 | 27 | //defaults values 28 | #define DEFAULT_BT_NAME "btgrblesp" 29 | 30 | 31 | //boundaries 32 | #define MAX_BTNAME_LENGTH 32 33 | #define MIN_BTNAME_LENGTH 1 34 | 35 | #define BT_EVENT_DISCONNECTED 0 36 | #define BT_EVENT_CONNECTED 1 37 | 38 | 39 | #ifndef _BT_CONFIG_H 40 | #define _BT_CONFIG_H 41 | #include "BluetoothSerial.h" 42 | extern BluetoothSerial SerialBT; 43 | 44 | class BTConfig { 45 | public: 46 | BTConfig(); 47 | ~BTConfig(); 48 | static const char *info(); 49 | static void BTEvent(uint8_t event); 50 | static bool isBTnameValid (const char * hostname); 51 | static uint32_t IP_int_from_string(String & s); 52 | static String BTname(){return _btname;} 53 | static const char* device_address(); 54 | static void begin(); 55 | static void end(); 56 | static void handle(); 57 | static void reset_settings(); 58 | static bool Is_BT_on(); 59 | private : 60 | static String _btname; 61 | }; 62 | 63 | extern BTConfig bt_config; 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /DrawBot_Badge/DrawBot_Badge.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Grbl_ESP32.ino - Header for system level commands and real-time processes 3 | Part of Grbl 4 | Copyright (c) 2014-2016 Sungeun K. Jeon for Gnea Research LLC 5 | 6 | 2018 - Bart Dring This file was modified for use on the ESP32 7 | CPU. Do not use this with Grbl for atMega328P 8 | 9 | Grbl is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #include "grbl.h" 22 | 23 | // Declare system global variable structure 24 | system_t sys; 25 | int32_t sys_position[N_AXIS]; // Real-time machine (aka home) position vector in steps. 26 | int32_t sys_probe_position[N_AXIS]; // Last probe position in machine coordinates and steps. 27 | volatile uint8_t sys_probe_state; // Probing state value. Used to coordinate the probing cycle with stepper ISR. 28 | volatile uint8_t sys_rt_exec_state; // Global realtime executor bitflag variable for state management. See EXEC bitmasks. 29 | volatile uint8_t sys_rt_exec_alarm; // Global realtime executor bitflag variable for setting various alarms. 30 | volatile uint8_t sys_rt_exec_motion_override; // Global realtime executor bitflag variable for motion-based overrides. 31 | volatile uint8_t sys_rt_exec_accessory_override; // Global realtime executor bitflag variable for spindle/coolant overrides. 32 | #ifdef DEBUG 33 | volatile uint8_t sys_rt_exec_debug; 34 | #endif 35 | 36 | void setup() { 37 | 38 | serial_init(); // Setup serial baud rate and interrupts 39 | settings_init(); // Load Grbl settings from EEPROM 40 | 41 | stepper_init(); // Configure stepper pins and interrupt timers 42 | system_ini(); // Configure pinout pins and pin-change interrupt (Renamed due to conflict with esp32 files) 43 | 44 | memset(sys_position,0,sizeof(sys_position)); // Clear machine position. 45 | 46 | servo_init(); // DrawBot_Badge 47 | 48 | // Initialize system state. 49 | #ifdef FORCE_INITIALIZATION_ALARM 50 | // Force Grbl into an ALARM state upon a power-cycle or hard reset. 51 | sys.state = STATE_ALARM; 52 | #else 53 | sys.state = STATE_IDLE; 54 | #endif 55 | 56 | // Check for power-up and set system alarm if homing is enabled to force homing cycle 57 | // by setting Grbl's alarm state. Alarm locks out all g-code commands, including the 58 | // startup scripts, but allows access to settings and internal commands. Only a homing 59 | // cycle '$H' or kill alarm locks '$X' will disable the alarm. 60 | // NOTE: The startup script will run after successful completion of the homing cycle, but 61 | // not after disabling the alarm locks. Prevents motion startup blocks from crashing into 62 | // things uncontrollably. Very bad. 63 | #ifdef HOMING_INIT_LOCK 64 | if (bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) { sys.state = STATE_ALARM; } 65 | #endif 66 | #ifdef ENABLE_WIFI 67 | wifi_config.begin(); 68 | #endif 69 | #ifdef ENABLE_BLUETOOTH 70 | bt_config.begin(); 71 | #endif 72 | 73 | } 74 | 75 | void loop() { 76 | 77 | // Reset system variables. 78 | uint8_t prior_state = sys.state; 79 | memset(&sys, 0, sizeof(system_t)); // Clear system struct variable. 80 | sys.state = prior_state; 81 | sys.f_override = DEFAULT_FEED_OVERRIDE; // Set to 100% 82 | sys.r_override = DEFAULT_RAPID_OVERRIDE; // Set to 100% 83 | sys.spindle_speed_ovr = DEFAULT_SPINDLE_SPEED_OVERRIDE; // Set to 100% 84 | memset(sys_probe_position,0,sizeof(sys_probe_position)); // Clear probe position. 85 | sys_probe_state = 0; 86 | sys_rt_exec_state = 0; 87 | sys_rt_exec_alarm = 0; 88 | sys_rt_exec_motion_override = 0; 89 | sys_rt_exec_accessory_override = 0; 90 | 91 | // Reset Grbl primary systems. 92 | serial_reset_read_buffer(CLIENT_ALL); // Clear serial read buffer 93 | 94 | gc_init(); // Set g-code parser to default state 95 | 96 | spindle_init(); 97 | coolant_init(); 98 | limits_init(); 99 | probe_init(); 100 | 101 | plan_reset(); // Clear block buffer and planner variables 102 | st_reset(); // Clear stepper subsystem variables 103 | // Sync cleared gcode and planner positions to current system position. 104 | plan_sync_position(); 105 | gc_sync_position(); 106 | 107 | 108 | 109 | // put your main code here, to run repeatedly: 110 | report_init_message(CLIENT_ALL); 111 | 112 | // Start Grbl main loop. Processes program inputs and executes them. 113 | protocol_main_loop(); 114 | 115 | } 116 | -------------------------------------------------------------------------------- /DrawBot_Badge/commands.h: -------------------------------------------------------------------------------- 1 | /* 2 | commands.h - ESP3D configuration class 3 | 4 | Copyright (c) 2014 Luc Lebosse. All rights reserved. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef COMMANDS_h 22 | #define COMMANDS_h 23 | #include "config.h" 24 | 25 | //Authentication level 26 | typedef enum { 27 | LEVEL_GUEST = 0, 28 | LEVEL_USER = 1, 29 | LEVEL_ADMIN = 2 30 | } level_authenticate_type; 31 | 32 | // Define line flags. Includes comment type tracking and line overflow detection. 33 | #define LINE_FLAG_OVERFLOW bit(0) 34 | #define LINE_FLAG_COMMENT_PARENTHESES bit(1) 35 | #define LINE_FLAG_COMMENT_SEMICOLON bit(2) 36 | 37 | class ESPResponseStream; 38 | 39 | 40 | class COMMANDS 41 | { 42 | public: 43 | static bool check_command (const char *, int * cmd, String & cmd_params); 44 | static String get_param (String & cmd_params, const char * id, bool withspace); 45 | static bool execute_internal_command (int cmd, String cmd_params, level_authenticate_type auth_level = LEVEL_GUEST , ESPResponseStream *espresponse= NULL); 46 | static void wait(uint32_t milliseconds); 47 | static void handle(); 48 | static void restart_ESP(); 49 | #ifdef ENABLE_AUTHENTICATION 50 | static bool isadmin (String & cmd_params); 51 | static bool isuser (String & cmd_params); 52 | static bool isLocalPasswordValid (const char * password); 53 | #endif 54 | private : 55 | static bool restart_ESP_module; 56 | }; 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /DrawBot_Badge/coolant_control.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | coolant_control.c - coolant control methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC 6 | 7 | 2018 - Bart Dring This file was modifed for use on the ESP32 8 | CPU. Do not use this with Grbl for atMega328P 9 | 10 | Grbl is free software: you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation, either version 3 of the License, or 13 | (at your option) any later version. 14 | 15 | Grbl is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with Grbl. If not, see . 22 | */ 23 | 24 | #include "grbl.h" 25 | 26 | 27 | void coolant_init() 28 | { 29 | #ifdef COOLANT_FLOOD_PIN 30 | pinMode(COOLANT_FLOOD_PIN, OUTPUT); 31 | #endif 32 | 33 | 34 | #ifdef COOLANT_MIST_PIN 35 | pinMode(COOLANT_MIST_PIN, OUTPUT); 36 | #endif 37 | coolant_stop(); 38 | } 39 | 40 | 41 | // Returns current coolant output state. Overrides may alter it from programmed state. 42 | uint8_t coolant_get_state() 43 | { 44 | uint8_t cl_state = COOLANT_STATE_DISABLE; 45 | 46 | #ifdef COOLANT_FLOOD_PIN 47 | #ifdef INVERT_COOLANT_FLOOD_PIN 48 | if (! digitalRead(COOLANT_FLOOD_PIN)) { 49 | #else 50 | if (digitalRead(COOLANT_FLOOD_PIN)) { 51 | #endif 52 | cl_state |= COOLANT_STATE_FLOOD; 53 | } 54 | #endif 55 | 56 | 57 | #ifdef COOLANT_MIST_PIN 58 | #ifdef INVERT_COOLANT_MIST_PIN 59 | if (! digitalRead(COOLANT_MIST_PIN)) { 60 | #else 61 | if (digitalRead(COOLANT_MIST_PIN)) { 62 | #endif 63 | cl_state |= COOLANT_STATE_MIST; 64 | } 65 | #endif 66 | 67 | return(cl_state); 68 | 69 | } 70 | 71 | 72 | // Directly called by coolant_init(), coolant_set_state(), and mc_reset(), which can be at 73 | // an interrupt-level. No report flag set, but only called by routines that don't need it. 74 | void coolant_stop() 75 | { 76 | #ifdef COOLANT_FLOOD_PIN 77 | #ifdef INVERT_COOLANT_FLOOD_PIN 78 | digitalWrite(COOLANT_FLOOD_PIN, 1); 79 | #else 80 | digitalWrite(COOLANT_FLOOD_PIN, 0); 81 | #endif 82 | #endif 83 | 84 | #ifdef COOLANT_MIST_PIN 85 | #ifdef INVERT_COOLANT_MIST_PIN 86 | digitalWrite(COOLANT_MIST_PIN, 1); 87 | #else 88 | digitalWrite(COOLANT_MIST_PIN, 0); 89 | #endif 90 | #endif 91 | } 92 | 93 | 94 | // Main program only. Immediately sets flood coolant running state and also mist coolant, 95 | // if enabled. Also sets a flag to report an update to a coolant state. 96 | // Called by coolant toggle override, parking restore, parking retract, sleep mode, g-code 97 | // parser program end, and g-code parser coolant_sync(). 98 | void coolant_set_state(uint8_t mode) 99 | { 100 | if (sys.abort) { return; } // Block during abort. 101 | 102 | if (mode == COOLANT_DISABLE) { 103 | 104 | coolant_stop(); 105 | 106 | } else { 107 | 108 | #ifdef COOLANT_FLOOD_PIN 109 | if (mode & COOLANT_FLOOD_ENABLE) { 110 | #ifdef INVERT_COOLANT_FLOOD_PIN 111 | digitalWrite(COOLANT_FLOOD_PIN, 0); 112 | #else 113 | digitalWrite(COOLANT_FLOOD_PIN, 1); 114 | #endif 115 | } 116 | #endif 117 | 118 | #ifdef COOLANT_MIST_PIN 119 | if (mode & COOLANT_MIST_ENABLE) { 120 | #ifdef INVERT_COOLANT_MIST_PIN 121 | digitalWrite(COOLANT_MIST_PIN, 0); 122 | #else 123 | digitalWrite(COOLANT_MIST_PIN, 1); 124 | #endif 125 | } 126 | #endif 127 | 128 | } 129 | sys.report_ovr_counter = 0; // Set to report change immediately 130 | } 131 | 132 | 133 | // G-code parser entry-point for setting coolant state. Forces a planner buffer sync and bails 134 | // if an abort or check-mode is active. 135 | void coolant_sync(uint8_t mode) 136 | { 137 | if (sys.state == STATE_CHECK_MODE) { return; } 138 | protocol_buffer_synchronize(); // Ensure coolant turns on when specified in program. 139 | coolant_set_state(mode); 140 | } 141 | -------------------------------------------------------------------------------- /DrawBot_Badge/coolant_control.h: -------------------------------------------------------------------------------- 1 | /* 2 | coolant_control.h - spindle control methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC 6 | 7 | 2018 - Bart Dring This file was modifed for use on the ESP32 8 | CPU. Do not use this with Grbl for atMega328P 9 | 10 | Grbl is free software: you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation, either version 3 of the License, or 13 | (at your option) any later version. 14 | 15 | Grbl is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with Grbl. If not, see . 22 | */ 23 | 24 | #ifndef coolant_control_h 25 | #define coolant_control_h 26 | 27 | #define COOLANT_NO_SYNC false 28 | #define COOLANT_FORCE_SYNC true 29 | 30 | #define COOLANT_STATE_DISABLE 0 // Must be zero 31 | #define COOLANT_STATE_FLOOD bit(0) 32 | #define COOLANT_STATE_MIST bit(1) 33 | 34 | 35 | // Initializes coolant control pins. 36 | void coolant_init(); 37 | 38 | // Returns current coolant output state. Overrides may alter it from programmed state. 39 | uint8_t coolant_get_state(); 40 | 41 | // Immediately disables coolant pins. 42 | void coolant_stop(); 43 | 44 | // Sets the coolant pins according to state specified. 45 | void coolant_set_state(uint8_t mode); 46 | 47 | // G-code parser entry-point for setting coolant states. Checks for and executes additional conditions. 48 | void coolant_sync(uint8_t mode); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /DrawBot_Badge/data/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdring/DrawBot_Badge/3a02d0541c2c60a1747d8ce8d9c7996ca49383f0/DrawBot_Badge/data/favicon.ico -------------------------------------------------------------------------------- /DrawBot_Badge/data/index.html.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdring/DrawBot_Badge/3a02d0541c2c60a1747d8ce8d9c7996ca49383f0/DrawBot_Badge/data/index.html.gz -------------------------------------------------------------------------------- /DrawBot_Badge/defaults.h: -------------------------------------------------------------------------------- 1 | /* 2 | defaults.h - defaults settings configuration file 3 | Part of Grbl 4 | 5 | Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC 6 | 7 | 2018 - Bart Dring This file was modifed for use on the ESP32 8 | CPU. Do not use this with Grbl for atMega328P 9 | 10 | Grbl is free software: you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation, either version 3 of the License, or 13 | (at your option) any later version. 14 | 15 | Grbl is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with Grbl. If not, see . 22 | */ 23 | 24 | /* The defaults.h file serves as a central default settings selector for different machine 25 | types, from DIY CNC mills to CNC conversions of off-the-shelf machines. The settings 26 | files listed here are supplied by users, so your results may vary. However, this should 27 | give you a good starting point as you get to know your machine and tweak the settings for 28 | your nefarious needs. 29 | NOTE: Ensure one and only one of these DEFAULTS_XXX values is defined in config.h */ 30 | 31 | #ifndef defaults_h 32 | 33 | #ifdef DEFAULTS_DRAWBOT_BADGE 34 | 35 | // Grbl generic default settings. Should work across different machines. 36 | #define DEFAULT_STEP_PULSE_MICROSECONDS 3 37 | #define DEFAULT_STEPPER_IDLE_LOCK_TIME 255 // msec (0-254, 255 keeps steppers enabled) 38 | 39 | #define DEFAULT_STEPPING_INVERT_MASK 0 // uint8_t 40 | #define DEFAULT_DIRECTION_INVERT_MASK 0 // uint8_t 41 | #define DEFAULT_INVERT_ST_ENABLE 0 // boolean 42 | #define DEFAULT_INVERT_LIMIT_PINS 1 // boolean 43 | #define DEFAULT_INVERT_PROBE_PIN 1 // boolean // 1 = Badge mode !!! 44 | 45 | #define DEFAULT_STATUS_REPORT_MASK 2 // MPos enabled 46 | 47 | #define DEFAULT_JUNCTION_DEVIATION 0.01 // mm 48 | #define DEFAULT_ARC_TOLERANCE 0.002 // mm 49 | #define DEFAULT_REPORT_INCHES 0 // false 50 | 51 | #define DEFAULT_SOFT_LIMIT_ENABLE 0 // false 52 | #define DEFAULT_HARD_LIMIT_ENABLE 0 // false 53 | 54 | #define DEFAULT_HOMING_ENABLE 0 // false 55 | #define DEFAULT_HOMING_DIR_MASK 3 // move positive dir Z, negative X,Y 56 | #define DEFAULT_HOMING_FEED_RATE 200.0 // mm/min 57 | #define DEFAULT_HOMING_SEEK_RATE 2000.0 // mm/min 58 | #define DEFAULT_HOMING_DEBOUNCE_DELAY 250 // msec (0-65k) 59 | #define DEFAULT_HOMING_PULLOFF 1.0 // mm 60 | 61 | #define DEFAULT_SPINDLE_RPM_MAX 1000.0 // rpm 62 | #define DEFAULT_SPINDLE_RPM_MIN 0.0 // rpm 63 | 64 | #define DEFAULT_LASER_MODE 0 // false 65 | 66 | #define DEFAULT_X_STEPS_PER_MM 100.0 67 | #define DEFAULT_Y_STEPS_PER_MM 100.0 68 | #define DEFAULT_Z_STEPS_PER_MM 100.0 69 | 70 | #define DEFAULT_X_MAX_RATE 1000.0 // mm/min 71 | #define DEFAULT_Y_MAX_RATE 1000.0 // mm/min 72 | #define DEFAULT_Z_MAX_RATE 500.0 // mm/min 73 | 74 | #define DEFAULT_X_ACCELERATION (50.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 75 | #define DEFAULT_Y_ACCELERATION (50.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 76 | #define DEFAULT_Z_ACCELERATION (50.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 77 | 78 | #define DEFAULT_X_MAX_TRAVEL 100.0 // mm NOTE: Must be a positive value. 79 | #define DEFAULT_Y_MAX_TRAVEL 100.0 // mm NOTE: Must be a positive value. 80 | #define DEFAULT_Z_MAX_TRAVEL 100.0 // mm NOTE: Must be a positive value. 81 | 82 | #endif 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /DrawBot_Badge/eeprom.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | eeprom.cpp - Header for system level commands and real-time processes 3 | Part of Grbl 4 | Copyright (c) 2014-2016 Sungeun K. Jeon for Gnea Research LLC 5 | 6 | 2018 - Bart Dring This file was modifed for use on the ESP32 7 | CPU. Do not use this with Grbl for atMega328P 8 | 9 | Grbl is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #include "grbl.h" 22 | 23 | void memcpy_to_eeprom_with_checksum(unsigned int destination, char *source, unsigned int size) { 24 | unsigned char checksum = 0; 25 | for(; size > 0; size--) { 26 | checksum = (checksum << 1) || (checksum >> 7); 27 | checksum += *source; 28 | EEPROM.write(destination++, *(source++)); 29 | } 30 | EEPROM.write(destination, checksum); 31 | EEPROM.commit(); 32 | } 33 | 34 | int memcpy_from_eeprom_with_checksum(char *destination, unsigned int source, unsigned int size) { 35 | unsigned char data, checksum = 0; 36 | for(; size > 0; size--) { 37 | data = EEPROM.read(source++); 38 | checksum = (checksum << 1) || (checksum >> 7); 39 | checksum += data; 40 | *(destination++) = data; 41 | } 42 | return(checksum == EEPROM.read(source)); 43 | } 44 | -------------------------------------------------------------------------------- /DrawBot_Badge/eeprom.h: -------------------------------------------------------------------------------- 1 | /* 2 | eeprom.h - Header for system level commands and real-time processes 3 | Part of Grbl 4 | Copyright (c) 2014-2016 Sungeun K. Jeon for Gnea Research LLC 5 | 6 | 2018 - Bart Dring This file was modifed for use on the ESP32 7 | CPU. Do not use this with Grbl for atMega328P 8 | 9 | Grbl is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #ifndef eeprom_h 22 | #define eeprom_h 23 | 24 | #include "grbl.h" 25 | 26 | //unsigned char eeprom_get_char(unsigned int addr); 27 | //void eeprom_put_char(unsigned int addr, unsigned char new_value); 28 | void memcpy_to_eeprom_with_checksum(unsigned int destination, char *source, unsigned int size); 29 | int memcpy_from_eeprom_with_checksum(char *destination, unsigned int source, unsigned int size); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /DrawBot_Badge/espresponse.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | espresponse.cpp - GRBL_ESP response class 3 | 4 | Copyright (c) 2014 Luc Lebosse. All rights reserved. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #include "config.h" 21 | #include "espresponse.h" 22 | #if defined (ENABLE_HTTP) && defined(ENABLE_WIFI) 23 | #include "web_server.h" 24 | #include 25 | #endif 26 | 27 | #if defined (ENABLE_HTTP) && defined(ENABLE_WIFI) 28 | ESPResponseStream::ESPResponseStream(WebServer * webserver){ 29 | _header_sent=false; 30 | _webserver = webserver; 31 | _client = CLIENT_WEBUI; 32 | } 33 | #endif 34 | 35 | ESPResponseStream::ESPResponseStream(uint8_t client){ 36 | _client = client; 37 | #if defined (ENABLE_HTTP) && defined(ENABLE_WIFI) 38 | _header_sent=false; 39 | _webserver = NULL; 40 | #endif 41 | } 42 | 43 | void ESPResponseStream::println(const char *data){ 44 | print(data); 45 | if (_client == CLIENT_TELNET) print("\r\n"); 46 | else print("\n"); 47 | } 48 | 49 | //helper to format size to readable string 50 | String ESPResponseStream::formatBytes (uint32_t bytes) 51 | { 52 | if (bytes < 1024) { 53 | return String (bytes) + " B"; 54 | } else if (bytes < (1024 * 1024) ) { 55 | return String (bytes / 1024.0) + " KB"; 56 | } else if (bytes < (1024 * 1024 * 1024) ) { 57 | return String (bytes / 1024.0 / 1024.0) + " MB"; 58 | } else { 59 | return String (bytes / 1024.0 / 1024.0 / 1024.0) + " GB"; 60 | } 61 | } 62 | 63 | void ESPResponseStream::print(const char *data){ 64 | #if defined (ENABLE_HTTP) && defined(ENABLE_WIFI) 65 | if (_webserver) { 66 | if (!_header_sent) { 67 | _webserver->setContentLength(CONTENT_LENGTH_UNKNOWN); 68 | _webserver->sendHeader("Content-Type","text/html"); 69 | _webserver->sendHeader("Cache-Control","no-cache"); 70 | _webserver->send(200); 71 | _header_sent = true; 72 | } 73 | _buffer+=data; 74 | if (_buffer.length() > 1200) { 75 | //send data 76 | _webserver->sendContent(_buffer); 77 | //reset buffer 78 | _buffer = ""; 79 | } 80 | return; 81 | } 82 | #endif 83 | if (_client == CLIENT_WEBUI) return; //this is sanity check 84 | grbl_send(_client, data); 85 | } 86 | 87 | void ESPResponseStream::flush(){ 88 | #if defined (ENABLE_HTTP) && defined(ENABLE_WIFI) 89 | if (_webserver) { 90 | if(_header_sent) { 91 | //send data 92 | if(_buffer.length() > 0)_webserver->sendContent(_buffer); 93 | //close connection 94 | _webserver->sendContent(""); 95 | } 96 | _header_sent = false; 97 | _buffer = ""; 98 | } 99 | #endif 100 | } 101 | -------------------------------------------------------------------------------- /DrawBot_Badge/espresponse.h: -------------------------------------------------------------------------------- 1 | /* 2 | espresponse.h - GRBL_ESP response class 3 | 4 | Copyright (c) 2014 Luc Lebosse. All rights reserved. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef ESPRESPONSE_h 22 | #define ESPRESPONSE_h 23 | #include "config.h" 24 | 25 | #if defined (ENABLE_HTTP) && defined(ENABLE_WIFI) 26 | class WebServer; 27 | #endif 28 | 29 | class ESPResponseStream{ 30 | public: 31 | void print(const char *data); 32 | void println(const char *data); 33 | void flush(); 34 | static String formatBytes (uint32_t bytes); 35 | uint8_t client() {return _client;} 36 | #if defined (ENABLE_HTTP) && defined(ENABLE_WIFI) 37 | ESPResponseStream(WebServer * webserver); 38 | #endif 39 | ESPResponseStream(uint8_t client); 40 | private: 41 | uint8_t _client; 42 | #if defined (ENABLE_HTTP) && defined(ENABLE_WIFI) 43 | bool _header_sent; 44 | WebServer * _webserver; 45 | String _buffer; 46 | #endif 47 | }; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /DrawBot_Badge/grbl.h: -------------------------------------------------------------------------------- 1 | /* 2 | grbl.h - Header for system level commands and real-time processes 3 | Part of Grbl 4 | Copyright (c) 2014-2016 Sungeun K. Jeon for Gnea Research LLC 5 | 6 | 2018 - Bart Dring This file was modifed for use on the ESP32 7 | CPU. Do not use this with Grbl for atMega328P 8 | 9 | Grbl is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | // Grbl versioning system 22 | #define GRBL_VERSION "1.1f" 23 | #define GRBL_VERSION_BUILD "20180917" 24 | 25 | //#include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "driver/timer.h" 33 | 34 | // Define the Grbl system include files. NOTE: Do not alter organization. 35 | #include "config.h" 36 | #include "nuts_bolts.h" 37 | #include "cpu_map.h" 38 | #include "tdef.h" 39 | 40 | #include "defaults.h" 41 | #include "settings.h" 42 | #include "system.h" 43 | 44 | #include "planner.h" 45 | #include "coolant_control.h" 46 | #include "eeprom.h" 47 | #include "gcode.h" 48 | #include "limits.h" 49 | #include "motion_control.h" 50 | #include "print.h" 51 | #include "probe.h" 52 | #include "protocol.h" 53 | #include "report.h" 54 | #include "serial.h" 55 | #include "spindle_control.h" 56 | #include "stepper.h" 57 | #include "jog.h" 58 | #include "servo.h" // DrawBot_Badge 59 | 60 | #ifdef ENABLE_BLUETOOTH 61 | #include "BTconfig.h" 62 | #endif 63 | 64 | #ifdef ENABLE_SD_CARD 65 | #include "grbl_sd.h" 66 | #endif 67 | 68 | #ifdef ENABLE_WIFI 69 | #include "wificonfig.h" 70 | #ifdef ENABLE_HTTP 71 | #include "serial2socket.h" 72 | #endif 73 | #ifdef ENABLE_TELNET 74 | #include "telnet_server.h" 75 | #endif 76 | #endif 77 | -------------------------------------------------------------------------------- /DrawBot_Badge/grbl_sd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Connect the SD card to the following pins: 3 | * 4 | * SD Card | ESP32 5 | * D2 - 6 | * D3 SS 7 | * CMD MOSI 8 | * VSS GND 9 | * VDD 3.3V 10 | * CLK SCK 11 | * VSS GND 12 | * D0 MISO 13 | * D1 - 14 | */ 15 | 16 | #ifndef grbl_sd_h 17 | #define grbl_sd_h 18 | 19 | 20 | #include "grbl.h" 21 | #include "FS.h" 22 | #include "SD.h" 23 | #include "SPI.h" 24 | 25 | #define FILE_TYPE_COUNT 5 // number of acceptable gcode file types in array 26 | 27 | #define SDCARD_DET_PIN -1 28 | #define SDCARD_DET_VAL 0 29 | 30 | #define SDCARD_IDLE 0 31 | #define SDCARD_NOT_PRESENT 1 32 | #define SDCARD_BUSY_PRINTING 2 33 | #define SDCARD_BUSY_UPLOADING 4 34 | #define SDCARD_BUSY_PARSING 8 35 | 36 | 37 | 38 | extern bool SD_ready_next; // Grbl has processed a line and is waiting for another 39 | 40 | bool sd_mount(); 41 | uint8_t get_sd_state(bool refresh); 42 | uint8_t set_sd_state(uint8_t flag); 43 | void listDir(fs::FS &fs, const char * dirname, uint8_t levels); 44 | boolean openFile(fs::FS &fs, const char * path); 45 | boolean closeFile(); 46 | boolean readFileLine(char *line); 47 | void readFile(fs::FS &fs, const char * path); 48 | float sd_report_perc_complete(); 49 | uint32_t sd_get_current_line_number(); 50 | void sd_get_current_filename(char* name); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /DrawBot_Badge/jog.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | jog.h - Jogging methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2016 Sungeun K. Jeon for Gnea Research LLC 6 | 7 | 2018 - Bart Dring This file was modifed for use on the ESP32 8 | CPU. Do not use this with Grbl for atMega328P 9 | 10 | Grbl is free software: you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation, either version 3 of the License, or 13 | (at your option) any later version. 14 | 15 | Grbl is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with Grbl. If not, see . 22 | */ 23 | 24 | #include "grbl.h" 25 | 26 | 27 | // Sets up valid jog motion received from g-code parser, checks for soft-limits, and executes the jog. 28 | uint8_t jog_execute(plan_line_data_t *pl_data, parser_block_t *gc_block) 29 | { 30 | // Initialize planner data struct for jogging motions. 31 | // NOTE: Spindle and coolant are allowed to fully function with overrides during a jog. 32 | pl_data->feed_rate = gc_block->values.f; 33 | pl_data->condition |= PL_COND_FLAG_NO_FEED_OVERRIDE; 34 | #ifdef USE_LINE_NUMBERS 35 | pl_data->line_number = gc_block->values.n; 36 | #endif 37 | 38 | if (bit_istrue(settings.flags,BITFLAG_SOFT_LIMIT_ENABLE)) { 39 | if (system_check_travel_limits(gc_block->values.xyz)) { return(STATUS_TRAVEL_EXCEEDED); } 40 | } 41 | 42 | // Valid jog command. Plan, set state, and execute. 43 | mc_line(gc_block->values.xyz,pl_data); 44 | if (sys.state == STATE_IDLE) { 45 | if (plan_get_current_block() != NULL) { // Check if there is a block to execute. 46 | sys.state = STATE_JOG; 47 | st_prep_buffer(); 48 | st_wake_up(); // NOTE: Manual start. No state machine required. 49 | } 50 | } 51 | 52 | return(STATUS_OK); 53 | } 54 | -------------------------------------------------------------------------------- /DrawBot_Badge/jog.h: -------------------------------------------------------------------------------- 1 | /* 2 | jog.h - Jogging methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2016 Sungeun K. Jeon for Gnea Research LLC 6 | 2018 - Bart Dring This file was modifed for use on the ESP32 7 | CPU. Do not use this with Grbl for atMega328P 8 | 9 | Grbl is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | Grbl is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with Grbl. If not, see . 21 | */ 22 | 23 | #ifndef jog_h 24 | #define jog_h 25 | 26 | #include "grbl.h" 27 | 28 | 29 | // System motion line numbers must be zero. 30 | #define JOG_LINE_NUMBER 0 31 | 32 | // Sets up valid jog motion received from g-code parser, checks for soft-limits, and executes the jog. 33 | uint8_t jog_execute(plan_line_data_t *pl_data, parser_block_t *gc_block); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /DrawBot_Badge/limits.h: -------------------------------------------------------------------------------- 1 | /* 2 | limits.h - code pertaining to limit-switches and performing the homing cycle 3 | Part of Grbl 4 | 5 | Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | 2018 - Bart Dring This file was modifed for use on the ESP32 9 | CPU. Do not use this with Grbl for atMega328P 10 | 11 | Grbl is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | Grbl is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with Grbl. If not, see . 23 | */ 24 | 25 | #ifndef limits_h 26 | #define limits_h 27 | 28 | 29 | // Initialize the limits module 30 | void limits_init(); 31 | 32 | // Disables hard limits. 33 | void limits_disable(); 34 | 35 | // Returns limit state as a bit-wise uint8 variable. 36 | uint8_t limits_get_state(); 37 | 38 | // Perform one portion of the homing cycle based on the input settings. 39 | void limits_go_home(uint8_t cycle_mask); 40 | 41 | // Check for soft limit violations 42 | void limits_soft_check(float *target); 43 | 44 | void isr_limit_switches(); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /DrawBot_Badge/motion_control.h: -------------------------------------------------------------------------------- 1 | /* 2 | motion_control.h - high level interface for issuing motion commands 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2015 Sungeun K. Jeon 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | 2018 - Bart Dring This file was modifed for use on the ESP32 9 | CPU. Do not use this with Grbl for atMega328P 10 | 11 | Grbl is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | Grbl is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with Grbl. If not, see . 23 | */ 24 | 25 | 26 | 27 | #ifndef motion_control_h 28 | #define motion_control_h 29 | 30 | #include "grbl.h" 31 | 32 | 33 | // System motion commands must have a line number of zero. 34 | #define HOMING_CYCLE_LINE_NUMBER 0 35 | #define PARKING_MOTION_LINE_NUMBER 0 36 | 37 | #define HOMING_CYCLE_ALL 0 // Must be zero. 38 | #define HOMING_CYCLE_X bit(X_AXIS) 39 | #define HOMING_CYCLE_Y bit(Y_AXIS) 40 | #define HOMING_CYCLE_Z bit(Z_AXIS) 41 | #define HOMING_CYCLE_A bit(A_AXIS) 42 | #define HOMING_CYCLE_B bit(B_AXIS) 43 | #define HOMING_CYCLE_C bit(C_AXIS) 44 | 45 | 46 | // Execute linear motion in absolute millimeter coordinates. Feed rate given in millimeters/second 47 | // unless invert_feed_rate is true. Then the feed_rate means that the motion should be completed in 48 | // (1 minute)/feed_rate time. 49 | void mc_line(float *target, plan_line_data_t *pl_data); 50 | 51 | // Execute an arc in offset mode format. position == current xyz, target == target xyz, 52 | // offset == offset from current xyz, axis_XXX defines circle plane in tool space, axis_linear is 53 | // the direction of helical travel, radius == circle radius, is_clockwise_arc boolean. Used 54 | // for vector transformation direction. 55 | void mc_arc(float *target, plan_line_data_t *pl_data, float *position, float *offset, float radius, 56 | uint8_t axis_0, uint8_t axis_1, uint8_t axis_linear, uint8_t is_clockwise_arc); 57 | 58 | // Dwell for a specific number of seconds 59 | void mc_dwell(float seconds); 60 | 61 | // Perform homing cycle to locate machine zero. Requires limit switches. 62 | void mc_homing_cycle(uint8_t cycle_mask); 63 | 64 | // Perform tool length probe cycle. Requires probe switch. 65 | uint8_t mc_probe_cycle(float *target, plan_line_data_t *pl_data, uint8_t parser_flags); 66 | 67 | // Plans and executes the single special motion case for parking. Independent of main planner buffer. 68 | void mc_parking_motion(float *parking_target, plan_line_data_t *pl_data); 69 | 70 | // Performs system reset. If in motion state, kills all motion and sets system alarm. 71 | void mc_reset(); 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /DrawBot_Badge/nuts_bolts.h: -------------------------------------------------------------------------------- 1 | /* 2 | nuts_bolts.h - Header for system level commands and real-time processes 3 | Part of Grbl 4 | Copyright (c) 2014-2016 Sungeun K. Jeon for Gnea Research LLC 5 | 6 | 2018 - Bart Dring This file was modifed for use on the ESP32 7 | CPU. Do not use this with Grbl for atMega328P 8 | 9 | Grbl is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #ifndef nuts_bolts_h 22 | #define nuts_bolts_h 23 | 24 | #define false 0 25 | #define true 1 26 | 27 | #define SOME_LARGE_VALUE 1.0E+38 28 | 29 | // Axis array index values. Must start with 0 and be continuous. 30 | #define N_AXIS 3 // Number of axes 31 | #define X_AXIS 0 // Axis indexing value. 32 | #define Y_AXIS 1 33 | #define Z_AXIS 2 34 | // #define A_AXIS 3 35 | 36 | // CoreXY motor assignments. DO NOT ALTER. 37 | // NOTE: If the A and B motor axis bindings are changed, this effects the CoreXY equations. 38 | #define A_MOTOR X_AXIS // Must be X_AXIS 39 | #define B_MOTOR Y_AXIS // Must be Y_AXIS 40 | 41 | 42 | 43 | // Conversions 44 | #define MM_PER_INCH (25.40) 45 | #define INCH_PER_MM (0.0393701) 46 | #define TICKS_PER_MICROSECOND (F_STEPPER_TIMER/1000000) // Different from AVR version 47 | 48 | #define DELAY_MODE_DWELL 0 49 | #define DELAY_MODE_SYS_SUSPEND 1 50 | 51 | // Useful macros 52 | #define clear_vector(a) memset(a, 0, sizeof(a)) 53 | #define clear_vector_float(a) memset(a, 0.0, sizeof(float)*N_AXIS) 54 | // #define clear_vector_long(a) memset(a, 0.0, sizeof(long)*N_AXIS) 55 | #define MAX(a,b) (((a) > (b)) ? (a) : (b)) // changed to upper case to remove conflicts with other libraries 56 | #define MIN(a,b) (((a) < (b)) ? (a) : (b)) // changed to upper case to remove conflicts with other libraries 57 | #define isequal_position_vector(a,b) !(memcmp(a, b, sizeof(float)*N_AXIS)) 58 | 59 | // Bit field and masking macros 60 | //Arduino.h:104:0: note: this is the location of the previous definition 61 | //#define bit(n) (1 << n) 62 | #define bit_true(x,mask) (x) |= (mask) 63 | #define bit_false(x,mask) (x) &= ~(mask) 64 | #define bit_istrue(x,mask) ((x & mask) != 0) 65 | #define bit_isfalse(x,mask) ((x & mask) == 0) 66 | 67 | // Read a floating point value from a string. Line points to the input buffer, char_counter 68 | // is the indexer pointing to the current character of the line, while float_ptr is 69 | // a pointer to the result variable. Returns true when it succeeds 70 | uint8_t read_float(char *line, uint8_t *char_counter, float *float_ptr); 71 | 72 | // Non-blocking delay function used for general operation and suspend features. 73 | void delay_sec(float seconds, uint8_t mode); 74 | 75 | // Delays variable-defined milliseconds. Compiler compatibility fix for _delay_ms(). 76 | void delay_ms(uint16_t ms); 77 | 78 | // Computes hypotenuse, avoiding avr-gcc's bloated version and the extra error checking. 79 | float hypot_f(float x, float y); 80 | 81 | float convert_delta_vector_to_unit_vector(float *vector); 82 | float limit_value_by_axis_maximum(float *max_value, float *unit_vec); 83 | 84 | //int constrain(int val, int min, int max); 85 | //long map(long x, long in_min, long in_max, long out_min, long out_max); 86 | float mapConstrain(float x, float in_min, float in_max, float out_min, float out_max); // DrawBot_Badge 87 | 88 | float map_float(float x, float in_min, float in_max, float out_min, float out_max); // DrawBot_Badge 89 | float constrain_float(float in, float min, float max); // DrawBot_Badge 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /DrawBot_Badge/print.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | print.c - Functions for formatting output strings 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | 2018 - Bart Dring This file was modifed for use on the ESP32 9 | CPU. Do not use this with Grbl for atMega328P 10 | 11 | Grbl is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | Grbl is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with Grbl. If not, see . 23 | */ 24 | 25 | #include "grbl.h" 26 | 27 | 28 | 29 | 30 | // void printIntegerInBase(unsigned long n, unsigned long base) 31 | // { 32 | // unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. 33 | // unsigned long i = 0; 34 | // 35 | // if (n == 0) { 36 | // serial_write('0'); 37 | // return; 38 | // } 39 | // 40 | // while (n > 0) { 41 | // buf[i++] = n % base; 42 | // n /= base; 43 | // } 44 | // 45 | // for (; i > 0; i--) 46 | // serial_write(buf[i - 1] < 10 ? 47 | // '0' + buf[i - 1] : 48 | // 'A' + buf[i - 1] - 10); 49 | // } 50 | 51 | 52 | // Prints an uint8 variable in base 10. 53 | void print_uint8_base10(uint8_t n) 54 | { 55 | uint8_t digit_a = 0; 56 | uint8_t digit_b = 0; 57 | if (n >= 100) { // 100-255 58 | digit_a = '0' + n % 10; 59 | n /= 10; 60 | } 61 | if (n >= 10) { // 10-99 62 | digit_b = '0' + n % 10; 63 | n /= 10; 64 | } 65 | serial_write('0' + n); 66 | if (digit_b) { serial_write(digit_b); } 67 | if (digit_a) { serial_write(digit_a); } 68 | } 69 | 70 | 71 | // Prints an uint8 variable in base 2 with desired number of desired digits. 72 | void print_uint8_base2_ndigit(uint8_t n, uint8_t digits) { 73 | unsigned char buf[digits]; 74 | uint8_t i = 0; 75 | 76 | for (; i < digits; i++) { 77 | buf[i] = n % 2 ; 78 | n /= 2; 79 | } 80 | 81 | for (; i > 0; i--) 82 | Serial.print('0' + buf[i - 1]); 83 | } 84 | 85 | 86 | void print_uint32_base10(uint32_t n) 87 | { 88 | if (n == 0) { 89 | Serial.print('0'); 90 | return; 91 | } 92 | 93 | unsigned char buf[10]; 94 | uint8_t i = 0; 95 | 96 | while (n > 0) { 97 | buf[i++] = n % 10; 98 | n /= 10; 99 | } 100 | 101 | for (; i > 0; i--) 102 | Serial.print('0' + buf[i-1]); 103 | } 104 | 105 | 106 | void printInteger(long n) 107 | { 108 | if (n < 0) { 109 | Serial.print('-'); 110 | print_uint32_base10(-n); 111 | } else { 112 | print_uint32_base10(n); 113 | } 114 | } 115 | 116 | 117 | // Convert float to string by immediately converting to a long integer, which contains 118 | // more digits than a float. Number of decimal places, which are tracked by a counter, 119 | // may be set by the user. The integer is then efficiently converted to a string. 120 | // NOTE: AVR '%' and '/' integer operations are very efficient. Bitshifting speed-up 121 | // techniques are actually just slightly slower. Found this out the hard way. 122 | void printFloat(float n, uint8_t decimal_places) 123 | { 124 | Serial.print(n, decimal_places); 125 | } 126 | 127 | 128 | // Floating value printing handlers for special variables types used in Grbl and are defined 129 | // in the config.h. 130 | // - CoordValue: Handles all position or coordinate values in inches or mm reporting. 131 | // - RateValue: Handles feed rate and current velocity in inches or mm reporting. 132 | void printFloat_CoordValue(float n) { 133 | if (bit_istrue(settings.flags,BITFLAG_REPORT_INCHES)) { 134 | printFloat(n*INCH_PER_MM,N_DECIMAL_COORDVALUE_INCH); 135 | } else { 136 | printFloat(n,N_DECIMAL_COORDVALUE_MM); 137 | } 138 | } 139 | 140 | void printFloat_RateValue(float n) { 141 | if (bit_istrue(settings.flags,BITFLAG_REPORT_INCHES)) { 142 | printFloat(n*INCH_PER_MM,N_DECIMAL_RATEVALUE_INCH); 143 | } else { 144 | printFloat(n,N_DECIMAL_RATEVALUE_MM); 145 | } 146 | } 147 | 148 | // Debug tool to print free memory in bytes at the called point. 149 | // NOTE: Keep commented unless using. Part of this function always gets compiled in. 150 | // void printFreeMemory() 151 | // { 152 | // extern int __heap_start, *__brkval; 153 | // uint16_t free; // Up to 64k values. 154 | // free = (int) &free - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 155 | // printInteger((int32_t)free); 156 | // printString(" "); 157 | // } 158 | -------------------------------------------------------------------------------- /DrawBot_Badge/print.h: -------------------------------------------------------------------------------- 1 | /* 2 | print.h - Functions for formatting output strings 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | 2018 - Bart Dring This file was modifed for use on the ESP32 9 | CPU. Do not use this with Grbl for atMega328P 10 | 11 | Grbl is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | Grbl is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with Grbl. If not, see . 23 | */ 24 | 25 | #ifndef print_h 26 | #define print_h 27 | 28 | 29 | void printString(const char *s); 30 | 31 | void printPgmString(const char *s); 32 | 33 | void printInteger(long n); 34 | 35 | void print_uint32_base10(uint32_t n); 36 | 37 | // Prints an uint8 variable in base 10. 38 | void print_uint8_base10(uint8_t n); 39 | 40 | // Prints an uint8 variable in base 2 with desired number of desired digits. 41 | void print_uint8_base2_ndigit(uint8_t n, uint8_t digits); 42 | 43 | void printFloat(float n, uint8_t decimal_places); 44 | 45 | // Floating value printing handlers for special variables types used in Grbl. 46 | // - CoordValue: Handles all position or coordinate values in inches or mm reporting. 47 | // - RateValue: Handles feed rate and current velocity in inches or mm reporting. 48 | void printFloat_CoordValue(float n); 49 | void printFloat_RateValue(float n); 50 | 51 | // Debug tool to print free memory in bytes at the called point. Not used otherwise. 52 | void printFreeMemory(); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /DrawBot_Badge/probe.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | probe.c - code pertaining to probing methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2014-2016 Sungeun K. Jeon for Gnea Research LLC 6 | 7 | 2018 - Bart Dring This file was modifed for use on the ESP32 8 | CPU. Do not use this with Grbl for atMega328P 9 | 10 | Grbl is free software: you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation, either version 3 of the License, or 13 | (at your option) any later version. 14 | 15 | Grbl is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with Grbl. If not, see . 22 | */ 23 | 24 | #include "grbl.h" 25 | 26 | 27 | // Inverts the probe pin state depending on user settings and probing cycle mode. 28 | uint8_t probe_invert_mask; 29 | 30 | 31 | // Probe pin initialization routine. 32 | void probe_init() 33 | { 34 | #ifdef PROBE_PIN 35 | #ifdef DISABLE_PROBE_PIN_PULL_UP 36 | pinMode(PROBE_PIN, INPUT); 37 | #else 38 | pinMode(PROBE_PIN, INPUT_PULLUP); // Enable internal pull-up resistors. Normal high operation. 39 | #endif 40 | 41 | 42 | probe_configure_invert_mask(false); // Initialize invert mask. 43 | #endif 44 | } 45 | 46 | 47 | // Called by probe_init() and the mc_probe() routines. Sets up the probe pin invert mask to 48 | // appropriately set the pin logic according to setting for normal-high/normal-low operation 49 | // and the probing cycle modes for toward-workpiece/away-from-workpiece. 50 | void probe_configure_invert_mask(uint8_t is_probe_away) 51 | { 52 | probe_invert_mask = 0; // Initialize as zero. 53 | if (bit_isfalse(settings.flags,BITFLAG_INVERT_PROBE_PIN)) { probe_invert_mask ^= PROBE_MASK; } 54 | if (is_probe_away) { probe_invert_mask ^= PROBE_MASK; } 55 | } 56 | 57 | // Returns the probe pin state. Triggered = true. Called by gcode parser and probe state monitor. 58 | uint8_t probe_get_state() 59 | { 60 | #ifdef PROBE_PIN 61 | return((digitalRead(PROBE_PIN)) ^ probe_invert_mask); 62 | #else 63 | return false; 64 | #endif 65 | } 66 | 67 | 68 | // Monitors probe pin state and records the system position when detected. Called by the 69 | // stepper ISR per ISR tick. 70 | // NOTE: This function must be extremely efficient as to not bog down the stepper ISR. 71 | void probe_state_monitor() 72 | { 73 | if (probe_get_state()) { 74 | sys_probe_state = PROBE_OFF; 75 | memcpy(sys_probe_position, sys_position, sizeof(sys_position)); 76 | bit_true(sys_rt_exec_state, EXEC_MOTION_CANCEL); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /DrawBot_Badge/probe.h: -------------------------------------------------------------------------------- 1 | /* 2 | probe.h - code pertaining to probing methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2014-2016 Sungeun K. Jeon for Gnea Research LLC 6 | 7 | 2018 - Bart Dring This file was modifed for use on the ESP32 8 | CPU. Do not use this with Grbl for atMega328P 9 | 10 | Grbl is free software: you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation, either version 3 of the License, or 13 | (at your option) any later version. 14 | 15 | Grbl is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with Grbl. If not, see . 22 | */ 23 | 24 | #ifndef probe_h 25 | #define probe_h 26 | 27 | // Values that define the probing state machine. 28 | #define PROBE_OFF 0 // Probing disabled or not in use. (Must be zero.) 29 | #define PROBE_ACTIVE 1 // Actively watching the input pin. 30 | 31 | // Probe pin initialization routine. 32 | void probe_init(); 33 | 34 | // Called by probe_init() and the mc_probe() routines. Sets up the probe pin invert mask to 35 | // appropriately set the pin logic according to setting for normal-high/normal-low operation 36 | // and the probing cycle modes for toward-workpiece/away-from-workpiece. 37 | void probe_configure_invert_mask(uint8_t is_probe_away); 38 | 39 | // Returns probe pin state. Triggered = true. Called by gcode parser and probe state monitor. 40 | uint8_t probe_get_state(); 41 | 42 | // Monitors probe pin state and records the system position when detected. Called by the 43 | // stepper ISR per ISR tick. 44 | void probe_state_monitor(); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /DrawBot_Badge/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | protocol.h - controls Grbl execution protocol and procedures 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | 2018 - Bart Dring This file was modifed for use on the ESP32 9 | CPU. Do not use this with Grbl for atMega328P 10 | 11 | Grbl is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | Grbl is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with Grbl. If not, see . 23 | */ 24 | 25 | #ifndef protocol_h 26 | #define protocol_h 27 | 28 | // Line buffer size from the serial input stream to be executed. 29 | // NOTE: Not a problem except for extreme cases, but the line buffer size can be too small 30 | // and g-code blocks can get truncated. Officially, the g-code standards support up to 256 31 | // characters. In future versions, this will be increased, when we know how much extra 32 | // memory space we can invest into here or we re-write the g-code parser not to have this 33 | // buffer. 34 | #ifndef LINE_BUFFER_SIZE 35 | #define LINE_BUFFER_SIZE 80 36 | #endif 37 | 38 | // Starts Grbl main loop. It handles all incoming characters from the serial port and executes 39 | // them as they complete. It is also responsible for finishing the initialization procedures. 40 | void protocol_main_loop(); 41 | 42 | // Checks and executes a realtime command at various stop points in main program 43 | void protocol_execute_realtime(); 44 | void protocol_exec_rt_system(); 45 | 46 | // Executes the auto cycle feature, if enabled. 47 | void protocol_auto_cycle_start(); 48 | 49 | // Block until all buffered steps are executed 50 | void protocol_buffer_synchronize(); 51 | 52 | // Executes the auto cycle feature, if enabled. 53 | void protocol_auto_cycle_start(); 54 | 55 | #endif 56 | 57 | -------------------------------------------------------------------------------- /DrawBot_Badge/serial.h: -------------------------------------------------------------------------------- 1 | /* 2 | serial.h - Header for system level commands and real-time processes 3 | Part of Grbl 4 | Copyright (c) 2014-2016 Sungeun K. Jeon for Gnea Research LLC 5 | 6 | 2018 - Bart Dring This file was modifed for use on the ESP32 7 | CPU. Do not use this with Grbl for atMega328P 8 | 9 | Grbl is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #ifndef serial_h 22 | #define serial_h 23 | 24 | #include "grbl.h" 25 | 26 | #ifndef RX_BUFFER_SIZE 27 | #define RX_BUFFER_SIZE 128 28 | #endif 29 | #ifndef TX_BUFFER_SIZE 30 | #ifdef USE_LINE_NUMBERS 31 | #define TX_BUFFER_SIZE 112 32 | #else 33 | #define TX_BUFFER_SIZE 104 34 | #endif 35 | #endif 36 | 37 | #define SERIAL_NO_DATA 0xff 38 | 39 | // a task to read for incoming data from serial port 40 | void serialCheckTask(void *pvParameters); 41 | 42 | void serialCheck(); 43 | 44 | void serial_write(uint8_t data); 45 | // Fetches the first byte in the serial read buffer. Called by main program. 46 | uint8_t serial_read(uint8_t client); 47 | 48 | // See if the character is an action command like feedhold or jogging. If so, do the action and return true 49 | uint8_t check_action_command(uint8_t data); 50 | 51 | void serial_init(); 52 | void serial_reset_read_buffer(uint8_t client); 53 | 54 | // Returns the number of bytes available in the RX serial buffer. 55 | uint8_t serial_get_rx_buffer_available(uint8_t client); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /DrawBot_Badge/serial2socket.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | serial2socket.cpp - serial 2 socket functions class 3 | 4 | Copyright (c) 2014 Luc Lebosse. All rights reserved. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | 22 | #ifdef ARDUINO_ARCH_ESP32 23 | 24 | //#include "grbl.h" 25 | #include "config.h" 26 | 27 | #if defined (ENABLE_WIFI) && defined(ENABLE_HTTP) 28 | 29 | 30 | #include "serial2socket.h" 31 | #include "web_server.h" 32 | #include 33 | #include 34 | Serial_2_Socket Serial2Socket; 35 | 36 | 37 | Serial_2_Socket::Serial_2_Socket(){ 38 | _web_socket = NULL; 39 | _TXbufferSize = 0; 40 | _RXbufferSize = 0; 41 | _RXbufferpos = 0; 42 | } 43 | Serial_2_Socket::~Serial_2_Socket(){ 44 | if (_web_socket) detachWS(); 45 | _TXbufferSize = 0; 46 | _RXbufferSize = 0; 47 | _RXbufferpos = 0; 48 | } 49 | void Serial_2_Socket::begin(long speed){ 50 | _TXbufferSize = 0; 51 | _RXbufferSize = 0; 52 | _RXbufferpos = 0; 53 | } 54 | 55 | void Serial_2_Socket::end(){ 56 | _TXbufferSize = 0; 57 | _RXbufferSize = 0; 58 | _RXbufferpos = 0; 59 | } 60 | 61 | long Serial_2_Socket::baudRate(){ 62 | return 0; 63 | } 64 | 65 | bool Serial_2_Socket::attachWS(void * web_socket){ 66 | if (web_socket) { 67 | _web_socket = web_socket; 68 | _TXbufferSize=0; 69 | return true; 70 | } 71 | return false; 72 | } 73 | 74 | bool Serial_2_Socket::detachWS(){ 75 | _web_socket = NULL; 76 | return true; 77 | } 78 | 79 | Serial_2_Socket::operator bool() const 80 | { 81 | return true; 82 | } 83 | int Serial_2_Socket::available(){ 84 | return _RXbufferSize; 85 | } 86 | 87 | 88 | size_t Serial_2_Socket::write(uint8_t c) 89 | { 90 | if(!_web_socket) return 0; 91 | write(&c,1); 92 | return 1; 93 | } 94 | 95 | size_t Serial_2_Socket::write(const uint8_t *buffer, size_t size) 96 | { 97 | if((buffer == NULL) ||(!_web_socket)) { 98 | if(buffer == NULL){ 99 | log_i("[SOCKET]No buffer"); 100 | } 101 | if(!_web_socket){ 102 | log_i("[SOCKET]No socket"); 103 | } 104 | return 0; 105 | } 106 | #if defined(ENABLE_SERIAL2SOCKET_OUT) 107 | if (_TXbufferSize==0)_lastflush = millis(); 108 | //send full line 109 | if (_TXbufferSize + size > TXBUFFERSIZE) flush(); 110 | //need periodic check to force to flush in case of no end 111 | for (int i = 0; i < size;i++){ 112 | _TXbuffer[_TXbufferSize] = buffer[i]; 113 | _TXbufferSize++; 114 | } 115 | log_i("[SOCKET]buffer size %d",_TXbufferSize); 116 | handle_flush(); 117 | #endif 118 | return size; 119 | } 120 | 121 | int Serial_2_Socket::peek(void){ 122 | if (_RXbufferSize > 0)return _RXbuffer[_RXbufferpos]; 123 | else return -1; 124 | } 125 | 126 | bool Serial_2_Socket::push (const char * data){ 127 | #if defined(ENABLE_SERIAL2SOCKET_IN) 128 | int data_size = strlen(data); 129 | if ((data_size + _RXbufferSize) <= RXBUFFERSIZE){ 130 | int current = _RXbufferpos + _RXbufferSize; 131 | if (current > RXBUFFERSIZE) current = current - RXBUFFERSIZE; 132 | for (int i = 0; i < data_size; i++){ 133 | if (current > (RXBUFFERSIZE-1)) current = 0; 134 | _RXbuffer[current] = data[i]; 135 | current ++; 136 | } 137 | _RXbufferSize+=strlen(data); 138 | return true; 139 | } 140 | return false; 141 | #else 142 | return true; 143 | #endif 144 | } 145 | 146 | int Serial_2_Socket::read(void){ 147 | if (_RXbufferSize > 0) { 148 | int v = _RXbuffer[_RXbufferpos]; 149 | _RXbufferpos++; 150 | if (_RXbufferpos > (RXBUFFERSIZE-1))_RXbufferpos = 0; 151 | _RXbufferSize--; 152 | return v; 153 | } else return -1; 154 | } 155 | 156 | void Serial_2_Socket::handle_flush() { 157 | if (_TXbufferSize > 0) { 158 | if ((_TXbufferSize>=TXBUFFERSIZE) || ((millis()- _lastflush) > FLUSHTIMEOUT)) { 159 | log_i("[SOCKET]need flush, buffer size %d",_TXbufferSize); 160 | flush(); 161 | } 162 | } 163 | } 164 | void Serial_2_Socket::flush(void){ 165 | if (_TXbufferSize > 0){ 166 | //if ((((AsyncWebSocket *)_web_socket)->count() > 0) && (((AsyncWebSocket *)_web_socket)->availableForWriteAll())) { 167 | log_i("[SOCKET]flush data, buffer size %d",_TXbufferSize); 168 | ((WebSocketsServer *)_web_socket)->broadcastBIN(_TXbuffer,_TXbufferSize); 169 | // } else { 170 | // log_i("[SOCKET]Cannot flush, buffer size %d",_TXbufferSize); 171 | // } 172 | //refresh timout 173 | _lastflush = millis(); 174 | //reset buffer 175 | _TXbufferSize = 0; 176 | } 177 | } 178 | 179 | #endif // ENABLE_WIFI 180 | 181 | #endif // ARDUINO_ARCH_ESP32 182 | -------------------------------------------------------------------------------- /DrawBot_Badge/serial2socket.h: -------------------------------------------------------------------------------- 1 | /* 2 | serial2socket.h - serial 2 socket functions class 3 | 4 | Copyright (c) 2014 Luc Lebosse. All rights reserved. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | 22 | #ifndef _SERIAL_2_SOCKET_H_ 23 | #define _SERIAL_2_SOCKET_H_ 24 | 25 | #include "Print.h" 26 | #define TXBUFFERSIZE 1200 27 | #define RXBUFFERSIZE 128 28 | #define FLUSHTIMEOUT 500 29 | class Serial_2_Socket: public Print{ 30 | public: 31 | Serial_2_Socket(); 32 | ~Serial_2_Socket(); 33 | size_t write(uint8_t c); 34 | size_t write(const uint8_t *buffer, size_t size); 35 | 36 | inline size_t write(const char * s) 37 | { 38 | return write((uint8_t*) s, strlen(s)); 39 | } 40 | inline size_t write(unsigned long n) 41 | { 42 | return write((uint8_t) n); 43 | } 44 | inline size_t write(long n) 45 | { 46 | return write((uint8_t) n); 47 | } 48 | inline size_t write(unsigned int n) 49 | { 50 | return write((uint8_t) n); 51 | } 52 | inline size_t write(int n) 53 | { 54 | return write((uint8_t) n); 55 | } 56 | long baudRate(); 57 | void begin(long speed); 58 | void end(); 59 | int available(); 60 | int peek(void); 61 | int read(void); 62 | bool push (const char * data); 63 | void flush(void); 64 | void handle_flush(); 65 | operator bool() const; 66 | bool attachWS(void * web_socket); 67 | bool detachWS(); 68 | private: 69 | uint32_t _lastflush; 70 | void * _web_socket; 71 | uint8_t _TXbuffer[TXBUFFERSIZE]; 72 | uint16_t _TXbufferSize; 73 | uint8_t _RXbuffer[RXBUFFERSIZE]; 74 | uint16_t _RXbufferSize; 75 | uint16_t _RXbufferpos; 76 | }; 77 | 78 | 79 | extern Serial_2_Socket Serial2Socket; 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /DrawBot_Badge/servo.h: -------------------------------------------------------------------------------- 1 | /* 2 | servo.h - rs274/ngc parser. 3 | Part of Grbl 4 | 5 | copyright (c) 2018 - Bart Dring This file was modified for use on the ESP32 6 | CPU. Do not use this with Grbl for atMega328P 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | 23 | 24 | /* 25 | Tower pro specs 26 | min pulse = 0.008 seconds 27 | max pulse = 0.220 seconds 28 | total sweep angle = 150° ... 2.62 radians 29 | */ 30 | 31 | 32 | 33 | // ---- begin servo definition ------ 34 | #define SERVO_MIN_RADIANS 0.0 35 | #define SERVO_MAX_RADIANS 2.62 // 150° 36 | #define SERVO_MIN_PULSE_MS 0.0008 // min pulse in seconds 37 | #define SERVO_MAX_PULSE_MS 0.0022 // max pulse in seconds 38 | // ---- begin servo definition ------ 39 | 40 | #define SERVO_TIMER_NUM 1 41 | #define SERVO_TIMER_INT_FREQ 20 // Hz This is the task freq 42 | 43 | #define SERVO_A_CHANNEL_NUM 5 44 | #define SERVO_B_CHANNEL_NUM 6 45 | #define SERVO_C_CHANNEL_NUM 7 46 | 47 | #ifdef CPU_MAP_WORKSHOP_PCB 48 | #define SERVO_A_PIN GPIO_NUM_12 49 | #define SERVO_B_PIN GPIO_NUM_27 50 | #define SERVO_C_PIN GPIO_NUM_14 51 | #endif 52 | 53 | #ifdef CPU_MAP_SIMPLE_PCB 54 | #define SERVO_A_PIN GPIO_NUM_12 55 | #define SERVO_B_PIN GPIO_NUM_14 56 | #define SERVO_C_PIN GPIO_NUM_27 57 | #endif 58 | 59 | #define SERVO_PULSE_FREQ 50 // 50Hz ... this is a standard analog servo value 60 | #define SERVO_PULSE_RES_BITS 16 // bits of resolution of PWM (16 is max) 61 | #define SERVO_PULSE_RES_COUNT 65535 // see above 62 | 63 | // these delays stagger the startup of the servos to prevent a large 64 | // current surge at turn on 65 | #define SERVO_A_DELAY 25 66 | #define SERVO_B_DELAY 60 67 | 68 | #define SERVO_TIME_PER_BIT ((1.0 / (float)SERVO_PULSE_FREQ) / ((float)SERVO_PULSE_RES_COUNT) ) // seconds 69 | 70 | #define SERVO_MIN_PULSE (uint16_t)(SERVO_MIN_PULSE_MS / SERVO_TIME_PER_BIT) // 71 | #define SERVO_MAX_PULSE (uint16_t)(SERVO_MAX_PULSE_MS / SERVO_TIME_PER_BIT) 72 | #define SERVO_PULSE_RANGE (SERVO_MAX_PULSE - SERVO_MIN_PULSE) 73 | 74 | // the servo are mounted in the same orientation, but the arms are not to optimize the travel. 75 | // The A servo arm is mounted so the center of servo travel is 45° down from machine zero 76 | // The B servo arm is mounted so the center of servo travel is 45° up from machine zero 77 | 78 | // calculate the pulse duration of the zero (pointing right) location 79 | // center of A is 45° above zero 80 | #define SERVO_A_ZERO_ANG (SERVO_MAX_RADIANS/2.0 + PI/4.0) // referenced to servo 81 | #define SERVO_A_ZERO_PT (uint16_t)(((float)SERVO_PULSE_RANGE * ((float)SERVO_A_ZERO_ANG/(float)SERVO_MAX_RADIANS)) + SERVO_MIN_PULSE) 82 | #define SERVO_A_RAD_CNT (SERVO_PULSE_RANGE / SERVO_MAX_RADIANS) 83 | 84 | // center of B is 45° below zero 85 | #define SERVO_B_ZERO_ANG (SERVO_MAX_RADIANS/2.0 - PI/4.0) // referenced to servo 86 | #define SERVO_B_ZERO_PT (uint16_t)(((float)SERVO_PULSE_RANGE * (SERVO_B_ZERO_ANG/SERVO_MAX_RADIANS)) + SERVO_MIN_PULSE) 87 | #define SERVO_B_RAD_CNT (SERVO_PULSE_RANGE / SERVO_MAX_RADIANS) // PWM counts per radian 88 | 89 | // servo C, the Z, is much simpler. We only need to define the range we want use 90 | #define SERVO_C_RADIANS_MIN SERVO_MAX_RADIANS - PI/2 // 90° of travel 91 | #define SERVO_C_RADIANS_MAX SERVO_MAX_RADIANS 92 | 93 | #define SERVO_C_RANGE_MM 3.0 // mm (full range of z) 94 | 95 | // Kinematic Constants 96 | // work area 97 | #define MIN_WORK_X -30.0 // outside work area, but useful for calibration 98 | #define MAX_WORK_X 75.0 99 | #define MIN_WORK_Y 0.0 100 | #define MAX_WORK_Y 75.0 101 | // arm lengths 102 | #define LEN_PEN_FOREARM 55.0 103 | #define L_PEN_UPPERARM 30.0 104 | #define LEN_LOWER_CRANK 50.0 105 | #define LEN_UPPER_CRANK 30.0 106 | #define LEN_MID_LINK 60.0 107 | // static positions 108 | #define SERVO_A_X 24.0 109 | #define SERVO_A_Y 91.1 110 | #define SERVO_B_X SERVO_A_X // both have same x position 111 | #define SERVO_B_Y 103.1 112 | 113 | #define SERVO_CAL_MIN 50.0 // the minimum allowable calibration value 114 | #define SERVO_CAL_MAX 150.0 // the maximum allowable calibration value 115 | 116 | #define BADGE_STARTUP_LINE "G0X58.3Y38.2Z0.0" // used to locate arms for assembly alignment 117 | 118 | #define BADGE_MODE (bit_istrue(settings.flags, BITFLAG_INVERT_PROBE_PIN)) 119 | 120 | #ifndef servo_h 121 | #define servo_h 122 | 123 | static TaskHandle_t servoSyncTaskHandle = 0; 124 | 125 | void servo_init(); 126 | 127 | void servoSyncTask(void *pvParameters); 128 | 129 | void calc_servo_cosines(float penX, float penY); 130 | void calc_servo_intersect(float penX, float penY, float penZ); 131 | uint8_t servo_constrain_cal_range(uint8_t cal_vsl); 132 | bool validate_bagde_settings(); 133 | void badge_servos_disable(); 134 | 135 | int circle_circle_intersection(float x0, float y0, float r0, // x,y and radius 136 | float x1, float y1, float r1, 137 | float *xi, float *yi, // intersection 138 | float *xi_prime, float *yi_prime); 139 | 140 | 141 | 142 | #endif -------------------------------------------------------------------------------- /DrawBot_Badge/settings.h: -------------------------------------------------------------------------------- 1 | /* 2 | settings.h - eeprom configuration handling 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | 2018 - Bart Dring This file was modifed for use on the ESP32 9 | CPU. Do not use this with Grbl for atMega328P 10 | 11 | Grbl is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | Grbl is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with Grbl. If not, see . 23 | */ 24 | 25 | #ifndef settings_h 26 | #define settings_h 27 | 28 | #include "grbl.h" 29 | 30 | 31 | // Version of the EEPROM data. Will be used to migrate existing data from older versions of Grbl 32 | // when firmware is upgraded. Always stored in byte 0 of eeprom 33 | #define SETTINGS_VERSION 10 // NOTE: Check settings_reset() when moving to next version. 34 | 35 | // Define bit flag masks for the boolean settings in settings.flag. 36 | #define BITFLAG_REPORT_INCHES bit(0) 37 | #define BITFLAG_LASER_MODE bit(1) 38 | #define BITFLAG_INVERT_ST_ENABLE bit(2) 39 | #define BITFLAG_HARD_LIMIT_ENABLE bit(3) 40 | #define BITFLAG_HOMING_ENABLE bit(4) 41 | #define BITFLAG_SOFT_LIMIT_ENABLE bit(5) 42 | #define BITFLAG_INVERT_LIMIT_PINS bit(6) 43 | #define BITFLAG_INVERT_PROBE_PIN bit(7) 44 | 45 | // Define status reporting boolean enable bit flags in settings.status_report_mask 46 | #define BITFLAG_RT_STATUS_POSITION_TYPE bit(0) 47 | #define BITFLAG_RT_STATUS_BUFFER_STATE bit(1) 48 | 49 | // Define settings restore bitflags. 50 | #define SETTINGS_RESTORE_DEFAULTS bit(0) 51 | #define SETTINGS_RESTORE_PARAMETERS bit(1) 52 | #define SETTINGS_RESTORE_STARTUP_LINES bit(2) 53 | #define SETTINGS_RESTORE_BUILD_INFO bit(3) 54 | #ifndef SETTINGS_RESTORE_ALL 55 | #define SETTINGS_RESTORE_ALL 0xFF // All bitflags 56 | #endif 57 | 58 | // Define EEPROM memory address location values for Grbl settings and parameters 59 | // NOTE: The Atmega328p has 1KB EEPROM. The upper half is reserved for parameters and 60 | // the startup script. The lower half contains the global settings and space for future 61 | // developments. 62 | #define EEPROM_SIZE 1024U 63 | #define EEPROM_ADDR_GLOBAL 1U 64 | #define EEPROM_ADDR_PARAMETERS 512U 65 | #define EEPROM_ADDR_STARTUP_BLOCK 768U 66 | #define EEPROM_ADDR_BUILD_INFO 942U 67 | 68 | // Define EEPROM address indexing for coordinate parameters 69 | #define N_COORDINATE_SYSTEM 6 // Number of supported work coordinate systems (from index 1) 70 | #define SETTING_INDEX_NCOORD N_COORDINATE_SYSTEM+1 // Total number of system stored (from index 0) 71 | // NOTE: Work coordinate indices are (0=G54, 1=G55, ... , 6=G59) 72 | #define SETTING_INDEX_G28 N_COORDINATE_SYSTEM // Home position 1 73 | #define SETTING_INDEX_G30 N_COORDINATE_SYSTEM+1 // Home position 2 74 | // #define SETTING_INDEX_G92 N_COORDINATE_SYSTEM+2 // Coordinate offset (G92.2,G92.3 not supported) 75 | 76 | // Define Grbl axis settings numbering scheme. Starts at START_VAL, every INCREMENT, over N_SETTINGS. 77 | #define AXIS_N_SETTINGS 4 78 | #define AXIS_SETTINGS_START_VAL 100 // NOTE: Reserving settings values >= 100 for axis settings. Up to 255. 79 | #define AXIS_SETTINGS_INCREMENT 10 // Must be greater than the number of axis settings 80 | 81 | // Global persistent settings (Stored from byte EEPROM_ADDR_GLOBAL onwards) 82 | typedef struct { 83 | // Axis settings 84 | float steps_per_mm[N_AXIS]; 85 | float max_rate[N_AXIS]; 86 | float acceleration[N_AXIS]; 87 | float max_travel[N_AXIS]; 88 | 89 | // Remaining Grbl settings 90 | uint8_t pulse_microseconds; 91 | uint8_t step_invert_mask; 92 | uint8_t dir_invert_mask; 93 | uint8_t stepper_idle_lock_time; // If max value 255, steppers do not disable. 94 | uint8_t status_report_mask; // Mask to indicate desired report data. 95 | float junction_deviation; 96 | float arc_tolerance; 97 | 98 | float rpm_max; 99 | float rpm_min; 100 | 101 | uint8_t flags; // Contains default boolean settings 102 | 103 | uint8_t homing_dir_mask; 104 | float homing_feed_rate; 105 | float homing_seek_rate; 106 | uint16_t homing_debounce_delay; 107 | float homing_pulloff; 108 | } settings_t; 109 | extern settings_t settings; 110 | 111 | // Initialize the configuration subsystem (load settings from EEPROM) 112 | void settings_init(); 113 | void settings_restore(uint8_t restore_flag); 114 | void write_global_settings(); 115 | uint8_t read_global_settings(); 116 | 117 | uint8_t settings_read_startup_line(uint8_t n, char *line); 118 | void settings_store_startup_line(uint8_t n, char *line); 119 | 120 | uint8_t settings_read_build_info(char *line); 121 | void settings_store_build_info(char *line); 122 | 123 | uint8_t settings_store_global_setting(uint8_t parameter, float value); 124 | 125 | // Writes selected coordinate data to EEPROM 126 | void settings_write_coord_data(uint8_t coord_select, float *coord_data); 127 | 128 | // Reads selected coordinate data from EEPROM 129 | uint8_t settings_read_coord_data(uint8_t coord_select, float *coord_data); 130 | 131 | // Returns the step pin mask according to Grbl's internal axis numbering 132 | uint8_t get_step_pin_mask(uint8_t i); 133 | 134 | // Returns the direction pin mask according to Grbl's internal axis numbering 135 | uint8_t get_direction_pin_mask(uint8_t i); 136 | 137 | 138 | #endif 139 | 140 | 141 | -------------------------------------------------------------------------------- /DrawBot_Badge/spindle_control.h: -------------------------------------------------------------------------------- 1 | /* 2 | spindle.h - Header for system level commands and real-time processes 3 | Part of Grbl 4 | Copyright (c) 2014-2016 Sungeun K. Jeon for Gnea Research LLC 5 | 6 | 2018 - Bart Dring This file was modified for use on the ESP32 7 | CPU. Do not use this with Grbl for atMega328P 8 | 9 | Grbl is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #ifndef spindle_control_h 22 | #define spindle_control_h 23 | 24 | #include "grbl.h" 25 | 26 | #define SPINDLE_NO_SYNC false 27 | #define SPINDLE_FORCE_SYNC true 28 | 29 | #define SPINDLE_STATE_DISABLE 0 // Must be zero. 30 | #define SPINDLE_STATE_CW bit(0) 31 | #define SPINDLE_STATE_CCW bit(1) 32 | 33 | void spindle_init(); 34 | void spindle_stop(); 35 | uint8_t spindle_get_state(); 36 | void spindle_set_speed(uint32_t pwm_value); 37 | uint32_t spindle_compute_pwm_value(float rpm); 38 | void spindle_set_state(uint8_t state, float rpm); 39 | void spindle_sync(uint8_t state, float rpm); 40 | void grbl_analogWrite(uint8_t chan, uint32_t duty); 41 | void spindle_set_enable(bool enable); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /DrawBot_Badge/stepper.h: -------------------------------------------------------------------------------- 1 | /* 2 | stepper.h - stepper motor driver: executes motion plans of planner.c using the stepper motors 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | 2018 - Bart Dring This file was modifed for use on the ESP32 9 | CPU. Do not use this with Grbl for atMega328P 10 | 11 | Grbl is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | Grbl is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with Grbl. If not, see . 23 | */ 24 | 25 | #ifndef stepper_h 26 | #define stepper_h 27 | 28 | #ifndef SEGMENT_BUFFER_SIZE 29 | #define SEGMENT_BUFFER_SIZE 6 30 | #endif 31 | 32 | 33 | 34 | #include "grbl.h" 35 | //#include "config.h" 36 | 37 | // Some useful constants. 38 | #define DT_SEGMENT (1.0/(ACCELERATION_TICKS_PER_SECOND*60.0)) // min/segment 39 | #define REQ_MM_INCREMENT_SCALAR 1.25 40 | #define RAMP_ACCEL 0 41 | #define RAMP_CRUISE 1 42 | #define RAMP_DECEL 2 43 | #define RAMP_DECEL_OVERRIDE 3 44 | 45 | #define PREP_FLAG_RECALCULATE bit(0) 46 | #define PREP_FLAG_HOLD_PARTIAL_BLOCK bit(1) 47 | #define PREP_FLAG_PARKING bit(2) 48 | #define PREP_FLAG_DECEL_OVERRIDE bit(3) 49 | 50 | // Define Adaptive Multi-Axis Step-Smoothing(AMASS) levels and cutoff frequencies. The highest level 51 | // frequency bin starts at 0Hz and ends at its cutoff frequency. The next lower level frequency bin 52 | // starts at the next higher cutoff frequency, and so on. The cutoff frequencies for each level must 53 | // be considered carefully against how much it over-drives the stepper ISR, the accuracy of the 16-bit 54 | // timer, and the CPU overhead. Level 0 (no AMASS, normal operation) frequency bin starts at the 55 | // Level 1 cutoff frequency and up to as fast as the CPU allows (over 30kHz in limited testing). 56 | // NOTE: AMASS cutoff frequency multiplied by ISR overdrive factor must not exceed maximum step frequency. 57 | // NOTE: Current settings are set to overdrive the ISR to no more than 16kHz, balancing CPU overhead 58 | // and timer accuracy. Do not alter these settings unless you know what you are doing. 59 | ///#ifdef ADAPTIVE_MULTI_AXIS_STEP_SMOOTHING 60 | #define MAX_AMASS_LEVEL 3 61 | // AMASS_LEVEL0: Normal operation. No AMASS. No upper cutoff frequency. Starts at LEVEL1 cutoff frequency. 62 | // Note ESP32 use F_STEPPER_TIMER rather than the AVR F_CPU 63 | #define AMASS_LEVEL1 (F_STEPPER_TIMER/8000) // Over-drives ISR (x2). Defined as F_CPU/(Cutoff frequency in Hz) 64 | #define AMASS_LEVEL2 (F_STEPPER_TIMER/4000) // Over-drives ISR (x4) 65 | #define AMASS_LEVEL3 (F_STEPPER_TIMER/2000) // Over-drives ISR (x8) 66 | 67 | #if MAX_AMASS_LEVEL <= 0 68 | error "AMASS must have 1 or more levels to operate correctly." 69 | #endif 70 | //#endif 71 | 72 | #define STEP_TIMER_GROUP TIMER_GROUP_0 73 | #define STEP_TIMER_INDEX TIMER_0 74 | 75 | // esp32 work around for diable in main loop 76 | extern uint64_t stepper_idle_counter; 77 | extern bool stepper_idle; 78 | 79 | // -- Task handles for use in the notifications 80 | 81 | 82 | void IRAM_ATTR onSteppertimer(); 83 | void IRAM_ATTR onStepperOffTimer(); 84 | void stepper_init(); 85 | 86 | // Enable steppers, but cycle does not start unless called by motion control or realtime command. 87 | void st_wake_up(); 88 | 89 | // Immediately disables steppers 90 | void st_go_idle(); 91 | 92 | // Generate the step and direction port invert masks. 93 | void st_generate_step_dir_invert_masks(); 94 | 95 | // Reset the stepper subsystem variables 96 | void st_reset(); 97 | 98 | // Changes the run state of the step segment buffer to execute the special parking motion. 99 | void st_parking_setup_buffer(); 100 | 101 | // Restores the step segment buffer to the normal run state after a parking motion. 102 | void st_parking_restore_buffer(); 103 | 104 | // Reloads step segment buffer. Called continuously by realtime execution system. 105 | void st_prep_buffer(); 106 | 107 | // Called by planner_recalculate() when the executing block is updated by the new plan. 108 | void st_update_plan_block_parameters(); 109 | 110 | // Called by realtime status reporting if realtime rate reporting is enabled in config.h. 111 | float st_get_realtime_rate(); 112 | 113 | // disable (or enable) steppers via STEPPERS_DISABLE_PIN 114 | void set_stepper_disable(uint8_t disable); 115 | 116 | void set_step_pin_on(uint8_t axis, uint8_t isOn); 117 | void set_direction_pin_on(uint8_t axis, uint8_t isOn); 118 | void set_stepper_pins_on(uint8_t onMask); 119 | void set_direction_pins_on(uint8_t onMask); 120 | 121 | void Stepper_Timer_WritePeriod(uint64_t alarm_val); 122 | void Stepper_Timer_Start(); 123 | void Stepper_Timer_Stop(); 124 | 125 | #endif 126 | -------------------------------------------------------------------------------- /DrawBot_Badge/tdef.h: -------------------------------------------------------------------------------- 1 | #ifndef tdef_h 2 | #define tdef_h 3 | 4 | #include "grbl.h" 5 | 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /DrawBot_Badge/telnet_server.h: -------------------------------------------------------------------------------- 1 | /* 2 | telnet_server.h - telnet service functions class 3 | 4 | Copyright (c) 2014 Luc Lebosse. All rights reserved. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | //how many clients should be able to telnet to this ESP32 22 | #define MAX_TLNT_CLIENTS 1 23 | 24 | #ifndef _TELNET_SERVER_H 25 | #define _TELNET_SERVER_H 26 | 27 | 28 | #include "config.h" 29 | class WiFiServer; 30 | class WiFiClient; 31 | 32 | #define TELNETRXBUFFERSIZE 1200 33 | #define FLUSHTIMEOUT 500 34 | 35 | class Telnet_Server { 36 | public: 37 | Telnet_Server(); 38 | ~Telnet_Server(); 39 | bool begin(); 40 | void end(); 41 | void handle(); 42 | size_t write(const uint8_t *buffer, size_t size); 43 | int read(void); 44 | int peek(void); 45 | int available(); 46 | bool push (uint8_t data); 47 | bool push (const char * data); 48 | static uint16_t port(){return _port;} 49 | private: 50 | static bool _setupdone; 51 | static WiFiServer * _telnetserver; 52 | static WiFiClient _telnetClients[MAX_TLNT_CLIENTS]; 53 | static uint16_t _port; 54 | void clearClients(); 55 | uint32_t _lastflush; 56 | uint8_t _RXbuffer[TELNETRXBUFFERSIZE]; 57 | uint16_t _RXbufferSize; 58 | uint16_t _RXbufferpos; 59 | }; 60 | 61 | extern Telnet_Server telnet_server; 62 | 63 | #endif 64 | 65 | -------------------------------------------------------------------------------- /DrawBot_Badge/web_server.h: -------------------------------------------------------------------------------- 1 | /* 2 | web_server.h - wifi services functions class 3 | 4 | Copyright (c) 2014 Luc Lebosse. All rights reserved. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | 22 | #ifndef _WEB_SERVER_H 23 | #define _WEB_SERVER_H 24 | 25 | 26 | #include "config.h" 27 | #include "commands.h" 28 | class WebSocketsServer; 29 | class WebServer; 30 | 31 | #ifdef ENABLE_AUTHENTICATION 32 | struct auth_ip { 33 | IPAddress ip; 34 | level_authenticate_type level; 35 | char userID[17]; 36 | char sessionID[17]; 37 | uint32_t last_time; 38 | auth_ip * _next; 39 | }; 40 | 41 | #endif 42 | 43 | class Web_Server { 44 | public: 45 | Web_Server(); 46 | ~Web_Server(); 47 | bool begin(); 48 | void end(); 49 | void handle(); 50 | static long get_client_ID(); 51 | static uint16_t port(){return _port;} 52 | private: 53 | static bool _setupdone; 54 | static WebServer * _webserver; 55 | static long _id_connection; 56 | static WebSocketsServer * _socket_server; 57 | static uint16_t _port; 58 | static uint8_t _upload_status; 59 | static String getContentType (String filename); 60 | static String get_Splited_Value(String data, char separator, int index); 61 | static level_authenticate_type is_authenticated(); 62 | #ifdef ENABLE_AUTHENTICATION 63 | static auth_ip * _head; 64 | static uint8_t _nb_ip; 65 | static bool AddAuthIP (auth_ip * item); 66 | static char * create_session_ID(); 67 | static bool ClearAuthIP (IPAddress ip, const char * sessionID); 68 | static auth_ip * GetAuth (IPAddress ip, const char * sessionID); 69 | static level_authenticate_type ResetAuthIP (IPAddress ip, const char * sessionID); 70 | #endif 71 | #ifdef ENABLE_SSDP 72 | static void handle_SSDP (); 73 | #endif 74 | static void handle_root(); 75 | static void handle_login(); 76 | static void handle_not_found (); 77 | static void handle_web_command (); 78 | static void handle_web_command_silent (); 79 | static void handle_Websocket_Event(uint8_t num, uint8_t type, uint8_t * payload, size_t length); 80 | static void SPIFFSFileupload (); 81 | static void handleFileList (); 82 | static void handleUpdate (); 83 | static void WebUpdateUpload (); 84 | static bool is_realtime_cmd(char c); 85 | #ifdef ENABLE_SD_CARD 86 | static void handle_direct_SDFileList(); 87 | static void SDFile_direct_upload(); 88 | static bool deleteRecursive(String path); 89 | #endif 90 | }; 91 | 92 | extern Web_Server web_server; 93 | 94 | #endif 95 | 96 | -------------------------------------------------------------------------------- /DrawBot_Badge/wificonfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | wificonfig.h - wifi functions class 3 | 4 | Copyright (c) 2014 Luc Lebosse. All rights reserved. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | //Preferences entries 22 | #define HOSTNAME_ENTRY "ESP_HOSTNAME" 23 | #define STA_SSID_ENTRY "STA_SSID" 24 | #define STA_PWD_ENTRY "STA_PWD" 25 | #define STA_IP_ENTRY "STA_IP" 26 | #define STA_GW_ENTRY "STA_GW" 27 | #define STA_MK_ENTRY "STA_MK" 28 | #define AP_SSID_ENTRY "AP_SSID" 29 | #define AP_PWD_ENTRY "AP_PWD" 30 | #define AP_IP_ENTRY "AP_IP" 31 | #define AP_CHANNEL_ENTRY "AP_CHANNEL" 32 | #define HTTP_ENABLE_ENTRY "HTTP_ON" 33 | #define HTTP_PORT_ENTRY "HTTP_PORT" 34 | #define TELNET_ENABLE_ENTRY "TELNET_ON" 35 | #define TELNET_PORT_ENTRY "TELNET_PORT" 36 | #define STA_IP_MODE_ENTRY "STA_IP_MODE" 37 | 38 | #define DHCP_MODE 0 39 | #define STATIC_MODE 1 40 | 41 | //Switch 42 | #define ESP_SAVE_ONLY 0 43 | #define ESP_APPLY_NOW 1 44 | 45 | //defaults values 46 | #define DEFAULT_HOSTNAME "grblesp" 47 | #define DEFAULT_STA_SSID "GRBL_ESP" 48 | #define DEFAULT_STA_PWD "12345678" 49 | #define DEFAULT_STA_IP "0.0.0.0" 50 | #define DEFAULT_STA_GW "0.0.0.0" 51 | #define DEFAULT_STA_MK "0.0.0.0" 52 | #define DEFAULT_AP_SSID "GRBL_ESP" 53 | #define DEFAULT_AP_PWD "12345678" 54 | #define DEFAULT_AP_IP "192.168.0.1" 55 | #define DEFAULT_AP_MK "255.255.255.0" 56 | #define DEFAULT_AP_CHANNEL 1 57 | #define DEFAULT_WEBSERVER_PORT 80 58 | #define DEFAULT_HTTP_STATE 1 59 | #define DEFAULT_TELNETSERVER_PORT 23 60 | #define DEFAULT_TELNET_STATE 1 61 | #define DEFAULT_STA_IP_MODE DHCP_MODE 62 | #define HIDDEN_PASSWORD "********" 63 | 64 | //boundaries 65 | #define MAX_SSID_LENGTH 32 66 | #define MIN_SSID_LENGTH 1 67 | #define MAX_PASSWORD_LENGTH 64 68 | //min size of password is 0 or upper than 8 char 69 | //so let set min is 8 70 | #define MIN_PASSWORD_LENGTH 8 71 | #define MAX_HOSTNAME_LENGTH 32 72 | #define MIN_HOSTNAME_LENGTH 1 73 | #define MAX_HTTP_PORT 65001 74 | #define MIN_HTTP_PORT 1 75 | #define MAX_TELNET_PORT 65001 76 | #define MIN_TELNET_PORT 1 77 | #define MIN_CHANNEL 1 78 | #define MAX_CHANNEL 14 79 | 80 | 81 | #ifndef _WIFI_CONFIG_H 82 | #define _WIFI_CONFIG_H 83 | #include "WiFi.h" 84 | 85 | class WiFiConfig { 86 | public: 87 | WiFiConfig(); 88 | ~WiFiConfig(); 89 | static const char *info(); 90 | static bool isValidIP(const char * string); 91 | static bool isPasswordValid (const char * password); 92 | static bool isSSIDValid (const char * ssid); 93 | static bool isHostnameValid (const char * hostname); 94 | static uint32_t IP_int_from_string(String & s); 95 | static String IP_string_from_int(uint32_t ip_int); 96 | static String Hostname(){return _hostname;} 97 | static char * mac2str (uint8_t mac [8]); 98 | static bool StartAP(); 99 | static bool StartSTA(); 100 | static void StopWiFi(); 101 | static int32_t getSignal (int32_t RSSI); 102 | static void begin(); 103 | static void end(); 104 | static void handle(); 105 | static void reset_settings(); 106 | static bool Is_WiFi_on(); 107 | private : 108 | static bool ConnectSTA2AP(); 109 | static void WiFiEvent(WiFiEvent_t event); 110 | static String _hostname; 111 | }; 112 | 113 | extern WiFiConfig wifi_config; 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /DrawBot_Badge/wifiservices.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | wifiservices.cpp - wifi services functions class 3 | 4 | Copyright (c) 2014 Luc Lebosse. All rights reserved. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifdef ARDUINO_ARCH_ESP32 22 | 23 | #include "config.h" 24 | 25 | #ifdef ENABLE_WIFI 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include "report.h" 32 | #include "wificonfig.h" 33 | #include "wifiservices.h" 34 | #ifdef ENABLE_MDNS 35 | #include 36 | #endif 37 | #ifdef ENABLE_OTA 38 | #include 39 | #endif 40 | #ifdef ENABLE_HTTP 41 | #include "web_server.h" 42 | #endif 43 | #ifdef ENABLE_TELNET 44 | #include "telnet_server.h" 45 | #endif 46 | 47 | WiFiServices wifi_services; 48 | 49 | WiFiServices::WiFiServices(){ 50 | } 51 | WiFiServices::~WiFiServices(){ 52 | end(); 53 | } 54 | 55 | bool WiFiServices::begin(){ 56 | bool no_error = true; 57 | //Sanity check 58 | if(WiFi.getMode() == WIFI_OFF) return false; 59 | String h; 60 | Preferences prefs; 61 | //Get hostname 62 | String defV = DEFAULT_HOSTNAME; 63 | prefs.begin(NAMESPACE, true); 64 | h = prefs.getString(HOSTNAME_ENTRY, defV); 65 | prefs.end(); 66 | WiFi.scanNetworks (true); 67 | //Start SPIFFS 68 | SPIFFS.begin(true); 69 | #ifdef ENABLE_MDNS 70 | //no need in AP mode 71 | if(WiFi.getMode() == WIFI_STA){ 72 | //start mDns 73 | if (!MDNS.begin(h.c_str())) { 74 | grbl_send(CLIENT_ALL,"[MSG:Cannot start mDNS]\r\n"); 75 | no_error = false; 76 | } else { 77 | grbl_sendf(CLIENT_ALL,"[MSG:Start mDNS with hostname:%s]\r\n",h.c_str()); 78 | } 79 | } 80 | #endif 81 | #ifdef ENABLE_OTA 82 | ArduinoOTA 83 | .onStart([]() { 84 | String type; 85 | if (ArduinoOTA.getCommand() == U_FLASH) 86 | type = "sketch"; 87 | else {// U_SPIFFS 88 | // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end() 89 | type = "filesystem"; 90 | SPIFFS.end(); 91 | } 92 | grbl_sendf(CLIENT_ALL,"[MSG:Start OTA updating %s]\r\n", type.c_str()); 93 | }) 94 | .onEnd([]() { 95 | grbl_sendf(CLIENT_ALL,"[MSG:End OTA]\r\n"); 96 | 97 | }) 98 | .onProgress([](unsigned int progress, unsigned int total) { 99 | grbl_sendf(CLIENT_ALL,"[MSG:OTA Progress: %u%%]\r\n", (progress / (total / 100))); 100 | }) 101 | .onError([](ota_error_t error) { 102 | grbl_sendf(CLIENT_ALL,"[MSG:OTA Error(%u):]\r\n", error); 103 | if (error == OTA_AUTH_ERROR) grbl_send(CLIENT_ALL,"[MSG:Auth Failed]\r\n"); 104 | else if (error == OTA_BEGIN_ERROR) grbl_send(CLIENT_ALL,"[MSG:Begin Failed]\r\n"); 105 | else if (error == OTA_CONNECT_ERROR) grbl_send(CLIENT_ALL,"[MSG:Connect Failed]\r\n"); 106 | else if (error == OTA_RECEIVE_ERROR) grbl_send(CLIENT_ALL,"[MSG:Receive Failed]\r\n"); 107 | else if (error == OTA_END_ERROR) grbl_send(CLIENT_ALL,"[MSG:End Failed]\r\n"); 108 | }); 109 | ArduinoOTA.begin(); 110 | #endif 111 | #ifdef ENABLE_HTTP 112 | web_server.begin(); 113 | #endif 114 | #ifdef ENABLE_TELNET 115 | telnet_server.begin(); 116 | #endif 117 | return no_error; 118 | } 119 | void WiFiServices::end(){ 120 | #ifdef ENABLE_TELNET 121 | telnet_server.end(); 122 | #endif 123 | 124 | #ifdef ENABLE_HTTP 125 | web_server.end(); 126 | #endif 127 | //stop OTA 128 | #ifdef ENABLE_OTA 129 | ArduinoOTA.end(); 130 | #endif 131 | //Stop SPIFFS 132 | SPIFFS.end(); 133 | 134 | #ifdef ENABLE_MDNS 135 | //Stop mDNS 136 | MDNS.end(); 137 | #endif 138 | } 139 | 140 | void WiFiServices::handle(){ 141 | #ifdef ENABLE_OTA 142 | ArduinoOTA.handle(); 143 | #endif 144 | #ifdef ENABLE_HTTP 145 | web_server.handle(); 146 | #endif 147 | #ifdef ENABLE_TELNET 148 | telnet_server.handle(); 149 | #endif 150 | } 151 | 152 | #endif // ENABLE_WIFI 153 | 154 | #endif // ARDUINO_ARCH_ESP32 155 | -------------------------------------------------------------------------------- /DrawBot_Badge/wifiservices.h: -------------------------------------------------------------------------------- 1 | /* 2 | wifiservices.h - wifi services functions class 3 | 4 | Copyright (c) 2014 Luc Lebosse. All rights reserved. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | 22 | 23 | #ifndef _WIFI_SERVICES_H 24 | #define _WIFI_SERVICES_H 25 | 26 | 27 | class WiFiServices { 28 | public: 29 | WiFiServices(); 30 | ~WiFiServices(); 31 | static bool begin(); 32 | static void end(); 33 | static void handle(); 34 | }; 35 | 36 | extern WiFiServices wifi_services; 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # The DrawBot Badge 2 | 3 | 4 | 5 | 6 | 7 | ### Overview 8 | 9 | The Drawbot Badge is a part of a “Getting Started in Small Scale CNC” workshop for the 2018 Hackaday Superconference. The PCB controller part packs just about every feature a small scale 3 axis CNC could ever need. The drawing machine part was provided as just the cheapest and easiest to build CNC machine I could think of. It draws wiggly line drawings on Post It Notes. 10 | 11 | The first part of the workshop cover basic concepts of small scale CNC machines and goes over how to control thing via gcode. 12 | 13 | During the second part of the workshop everyone builds the drawing badge. 14 | 15 | ### Badge Features 16 | 17 | - ESP32 Controller running a fork of Grbl_ESP32 18 | - (3) TI DRV8825 Stepper motor drivers 19 | - (3) Hobby servo connectors 20 | - (3) Home/Limit switch connectors 21 | - (4) Control switch inputs 22 | - (1) Touch probe interface 23 | - Spindle speed control output (3.3v PWM) 24 | - Laser Module interface (safety interlock and power control) 25 | - (1) General purpose output (3.3v TTL) 26 | - (1) High current output control (3A contiuous) 27 | - Bluetooth 28 | - Wifi (Access point or Client) 29 | - Web page interface 30 | - Micro SD Card Socket 31 | - Shitty add on interface 32 | - Power via battery, USB or DC barrel jack 33 | 34 | **Note:** Some of the above features cannot be used at the same time. For example: For each of the 3 axes (XYZ) you must choose to use either a stepper motor or hobby servo. You cannot use all 6 items at once. There are more details in the wiki. 35 | 36 | ### Assembly instructions 37 | 38 | [See the wiki](https://github.com/bdring/DrawBot_Badge/wiki/Assembly-Instructions) 39 | 40 | ### Status 41 | 42 | All source code and files will be added to the repo soon. -------------------------------------------------------------------------------- /SourceFiles/GCode/OSHW_Logo.nc: -------------------------------------------------------------------------------- 1 | G21 2 | G90 3 | G1 Z3.810 F228.6 4 | G0 X56.412 Y11.246 5 | G1 Z-1.000 F1000.0 6 | G1 X58.999 Y13.977 F1000.0 7 | G1 X59.193 Y14.278 F1000.0 8 | G1 X55.602 Y19.689 F1000.0 9 | G1 X54.997 Y20.785 F1000.0 10 | G1 X55.349 Y21.929 F1000.0 11 | G1 X57.010 Y26.002 F1000.0 12 | G1 X57.512 Y26.960 F1000.0 13 | G1 X65.212 Y28.548 F1000.0 14 | G1 X65.212 Y36.704 F1000.0 15 | G1 X64.867 Y36.861 F1000.0 16 | G1 X57.260 Y38.448 F1000.0 17 | G1 X55.862 Y41.403 F1000.0 18 | G1 X54.652 Y44.216 F1000.0 19 | G1 X59.272 Y51.193 F1000.0 20 | G1 X54.321 Y56.126 F1000.0 21 | G1 X53.379 Y56.976 F1000.0 22 | G1 X46.496 Y52.466 F1000.0 23 | G1 X45.497 Y52.745 F1000.0 24 | G1 X40.697 Y54.650 F1000.0 25 | G1 X39.204 Y62.555 F1000.0 26 | G1 X38.653 Y63.105 F1000.0 27 | G1 X32.321 Y63.048 F1000.0 28 | G1 X31.000 Y62.948 F1000.0 29 | G1 X30.742 Y62.722 F1000.0 30 | G1 X30.576 Y62.367 F1000.0 31 | G1 X29.067 Y54.650 F1000.0 32 | G1 X25.154 Y53.032 F1000.0 33 | G1 X23.441 Y52.419 F1000.0 34 | G1 X22.332 Y53.067 F1000.0 35 | G1 X16.527 Y56.929 F1000.0 36 | G1 X15.501 Y56.122 F1000.0 37 | G1 X13.504 Y54.212 F1000.0 38 | G1 X10.921 Y51.492 F1000.0 39 | G1 X10.681 Y51.130 F1000.0 40 | G1 X11.327 Y49.995 F1000.0 41 | G1 X14.435 Y45.355 F1000.0 42 | G1 X15.081 Y44.279 F1000.0 43 | G1 X13.940 Y41.395 F1000.0 44 | G1 X12.598 Y38.558 F1000.0 45 | G1 X12.331 Y38.307 F1000.0 46 | G1 X4.898 Y36.861 F1000.0 47 | G1 X4.552 Y36.704 F1000.0 48 | G1 X4.552 Y28.721 F1000.0 49 | G1 X4.756 Y28.563 F1000.0 50 | G1 X6.705 Y28.077 F1000.0 51 | G1 X12.268 Y26.945 F1000.0 52 | G1 X12.805 Y25.971 F1000.0 53 | G1 X14.924 Y20.816 F1000.0 54 | G1 X10.681 Y14.247 F1000.0 55 | G1 X11.543 Y13.210 F1000.0 56 | G1 X15.435 Y9.285 F1000.0 57 | G1 X16.464 Y8.417 F1000.0 58 | G1 X22.876 Y12.503 F1000.0 59 | G1 X25.455 Y11.299 F1000.0 60 | G1 X25.988 Y11.136 F1000.0 61 | G1 X26.267 Y11.533 F1000.0 62 | G1 X29.366 Y18.899 F1000.0 63 | G1 X31.582 Y24.430 F1000.0 64 | G1 X29.483 Y26.207 F1000.0 65 | G1 X28.666 Y26.995 F1000.0 66 | G1 X27.990 Y27.811 F1000.0 67 | G1 X27.451 Y28.666 F1000.0 68 | G1 X27.042 Y29.570 F1000.0 69 | G1 X26.758 Y30.537 F1000.0 70 | G1 X26.591 Y31.575 F1000.0 71 | G1 X26.537 Y34.111 F1000.0 72 | G1 X27.146 Y35.920 F1000.0 73 | G1 X28.011 Y37.412 F1000.0 74 | G1 X29.162 Y38.746 F1000.0 75 | G1 X30.498 Y39.803 F1000.0 76 | G1 X31.205 Y40.193 F1000.0 77 | G1 X32.252 Y40.587 F1000.0 78 | G1 X34.647 Y41.151 F1000.0 79 | G1 X37.271 Y40.805 F1000.0 80 | G1 X39.832 Y39.564 F1000.0 81 | G1 X41.812 Y37.616 F1000.0 82 | G1 X43.054 Y35.023 F1000.0 83 | G1 X43.431 Y32.508 F1000.0 84 | G1 X42.843 Y29.991 F1000.0 85 | G1 X42.378 Y28.836 F1000.0 86 | G1 X41.807 Y27.809 F1000.0 87 | G1 X41.168 Y26.992 F1000.0 88 | G1 X38.182 Y24.462 F1000.0 89 | G1 X42.520 Y13.854 F1000.0 90 | G1 X43.793 Y11.136 F1000.0 91 | G1 X44.327 Y11.292 F1000.0 92 | G1 X46.920 Y12.503 F1000.0 93 | G1 X47.953 Y11.919 F1000.0 94 | G1 X53.284 Y8.464 F1000.0 95 | G1 X53.552 Y8.386 F1000.0 96 | G1 X56.412 Y11.246 F1000.0 97 | G21 98 | G90 99 | G1 Z3.810 F1000.0 100 | G0 X0.000 Y0.000 101 | G4 P0.1 -------------------------------------------------------------------------------- /SourceFiles/PDF/Schematic_v1p1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdring/DrawBot_Badge/3a02d0541c2c60a1747d8ce8d9c7996ca49383f0/SourceFiles/PDF/Schematic_v1p1.pdf -------------------------------------------------------------------------------- /SourceFiles/STL/drawbadge_base.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdring/DrawBot_Badge/3a02d0541c2c60a1747d8ce8d9c7996ca49383f0/SourceFiles/STL/drawbadge_base.stl -------------------------------------------------------------------------------- /SourceFiles/STL/drawbadge_base_simple.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdring/DrawBot_Badge/3a02d0541c2c60a1747d8ce8d9c7996ca49383f0/SourceFiles/STL/drawbadge_base_simple.stl -------------------------------------------------------------------------------- /SourceFiles/STL/drawbadge_linkage.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdring/DrawBot_Badge/3a02d0541c2c60a1747d8ce8d9c7996ca49383f0/SourceFiles/STL/drawbadge_linkage.stl -------------------------------------------------------------------------------- /SourceFiles/STL/drawbadge_pen_arm.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdring/DrawBot_Badge/3a02d0541c2c60a1747d8ce8d9c7996ca49383f0/SourceFiles/STL/drawbadge_pen_arm.stl -------------------------------------------------------------------------------- /SourceFiles/STL/drawbadge_servo_a_arm.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdring/DrawBot_Badge/3a02d0541c2c60a1747d8ce8d9c7996ca49383f0/SourceFiles/STL/drawbadge_servo_a_arm.stl -------------------------------------------------------------------------------- /SourceFiles/STL/drawbadge_servo_b_arm.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdring/DrawBot_Badge/3a02d0541c2c60a1747d8ce8d9c7996ca49383f0/SourceFiles/STL/drawbadge_servo_b_arm.stl -------------------------------------------------------------------------------- /SourceFiles/STL/drawbadge_servo_box.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdring/DrawBot_Badge/3a02d0541c2c60a1747d8ce8d9c7996ca49383f0/SourceFiles/STL/drawbadge_servo_box.stl -------------------------------------------------------------------------------- /SourceFiles/STL/drawbadge_z_cam.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdring/DrawBot_Badge/3a02d0541c2c60a1747d8ce8d9c7996ca49383f0/SourceFiles/STL/drawbadge_z_cam.stl -------------------------------------------------------------------------------- /SourceFiles/STL/knob_5mm_screw.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdring/DrawBot_Badge/3a02d0541c2c60a1747d8ce8d9c7996ca49383f0/SourceFiles/STL/knob_5mm_screw.stl -------------------------------------------------------------------------------- /doc/csv/alarm_codes_en_US.csv: -------------------------------------------------------------------------------- 1 | "Alarm Code in v1.1+"," Alarm Message in v1.0-"," Alarm Description" 2 | "1","Hard limit","Hard limit has been triggered. Machine position is likely lost due to sudden halt. Re-homing is highly recommended." 3 | "2","Soft limit","Soft limit alarm. G-code motion target exceeds machine travel. Machine position retained. Alarm may be safely unlocked." 4 | "3","Abort during cycle","Reset while in motion. Machine position is likely lost due to sudden halt. Re-homing is highly recommended." 5 | "4","Probe fail","Probe fail. Probe is not in the expected initial state before starting probe cycle when G38.2 and G38.3 is not triggered and G38.4 and G38.5 is triggered." 6 | "5","Probe fail","Probe fail. Probe did not contact the workpiece within the programmed travel for G38.2 and G38.4." 7 | "6","Homing fail","Homing fail. The active homing cycle was reset." 8 | "7","Homing fail","Homing fail. Safety door was opened during homing cycle." 9 | "8","Homing fail","Homing fail. Pull off travel failed to clear limit switch. Try increasing pull-off setting or check wiring." 10 | "9","Homing fail","Homing fail. Could not find limit switch within search distances. Try increasing max travel, decreasing pull-off distance, or check wiring." 11 | -------------------------------------------------------------------------------- /doc/csv/build_option_codes_en_US.csv: -------------------------------------------------------------------------------- 1 | OPT: Code, Build-Option Description,State 2 | V,Variable spindle,Enabled 3 | N,Line numbers,Enabled 4 | M,Mist coolant M7,Enabled 5 | C,CoreXY,Enabled 6 | P,Parking motion,Enabled 7 | Z,Homing force origin,Enabled 8 | H,Homing single axis commands,Enabled 9 | T,Two limit switches on axis,Enabled 10 | A,Allow feed rate overrides in probe cycles,Enabled 11 | D,Use spindle direction as enable pin,Enabled 12 | 0,Spindle enable off when speed is zero,Enabled 13 | S,Software limit pin debouncing,Enabled 14 | R,Parking override control,Enabled 15 | +,Safety door input pin,Enabled 16 | *,Restore all EEPROM command,Disabled 17 | $,Restore EEPROM `$` settings command,Disabled 18 | #,Restore EEPROM parameter data command,Disabled 19 | I,Build info write user string command,Disabled 20 | E,Force sync upon EEPROM write,Disabled 21 | W,Force sync upon work coordinate offset change,Disabled 22 | L,Homing initialization auto-lock,Disabled -------------------------------------------------------------------------------- /doc/csv/error_codes_en_US.csv: -------------------------------------------------------------------------------- 1 | "Error Code in v1.1+","Error Message in v1.0-","Error Description" 2 | "1","Expected command letter","G-code words consist of a letter and a value. Letter was not found." 3 | "2","Bad number format","Missing the expected G-code word value or numeric value format is not valid." 4 | "3","Invalid statement","Grbl '$' system command was not recognized or supported." 5 | "4","Value < 0","Negative value received for an expected positive value." 6 | "5","Setting disabled","Homing cycle failure. Homing is not enabled via settings." 7 | "6","Value < 3 usec","Minimum step pulse time must be greater than 3usec." 8 | "7","EEPROM read fail. Using defaults","An EEPROM read failed. Auto-restoring affected EEPROM to default values." 9 | "8","Not idle","Grbl '$' command cannot be used unless Grbl is IDLE. Ensures smooth operation during a job." 10 | "9","G-code lock","G-code commands are locked out during alarm or jog state." 11 | "10","Homing not enabled","Soft limits cannot be enabled without homing also enabled." 12 | "11","Line overflow","Max characters per line exceeded. Received command line was not executed." 13 | "12","Step rate > 30kHz","Grbl '$' setting value cause the step rate to exceed the maximum supported." 14 | "13","Check Door","Safety door detected as opened and door state initiated." 15 | "14","Line length exceeded","Build info or startup line exceeded EEPROM line length limit. Line not stored." 16 | "15","Travel exceeded","Jog target exceeds machine travel. Jog command has been ignored." 17 | "16","Invalid jog command","Jog command has no '=' or contains prohibited g-code." 18 | "17","Setting disabled","Laser mode requires PWM output." 19 | "20","Unsupported command","Unsupported or invalid g-code command found in block." 20 | "21","Modal group violation","More than one g-code command from same modal group found in block." 21 | "22","Undefined feed rate","Feed rate has not yet been set or is undefined." 22 | "23","Invalid gcode ID:23","G-code command in block requires an integer value." 23 | "24","Invalid gcode ID:24","More than one g-code command that requires axis words found in block." 24 | "25","Invalid gcode ID:25","Repeated g-code word found in block." 25 | "26","Invalid gcode ID:26","No axis words found in block for g-code command or current modal state which requires them." 26 | "27","Invalid gcode ID:27","Line number value is invalid." 27 | "28","Invalid gcode ID:28","G-code command is missing a required value word." 28 | "29","Invalid gcode ID:29","G59.x work coordinate systems are not supported." 29 | "30","Invalid gcode ID:30","G53 only allowed with G0 and G1 motion modes." 30 | "31","Invalid gcode ID:31","Axis words found in block when no command or current modal state uses them." 31 | "32","Invalid gcode ID:32","G2 and G3 arcs require at least one in-plane axis word." 32 | "33","Invalid gcode ID:33","Motion command target is invalid." 33 | "34","Invalid gcode ID:34","Arc radius value is invalid." 34 | "35","Invalid gcode ID:35","G2 and G3 arcs require at least one in-plane offset word." 35 | "36","Invalid gcode ID:36","Unused value words found in block." 36 | "37","Invalid gcode ID:37","G43.1 dynamic tool length offset is not assigned to configured tool length axis." 37 | "38","Invalid gcode ID:38","Tool number greater than max supported value." 38 | "60","SD failed to mount" 39 | "61","SD card failed to open file for reading" 40 | "62","SD card failed to open directory" 41 | "63","SD Card directory not found" 42 | "64","SD Card file empty" 43 | "70","Bluetooth failed to start" 44 | -------------------------------------------------------------------------------- /doc/csv/setting_codes_en_US.csv: -------------------------------------------------------------------------------- 1 | "$-Code"," Setting"," Units"," Setting Description" 2 | "0","Step pulse time","microseconds","Sets time length per step. Minimum 3usec." 3 | "1","Step idle delay","milliseconds","Sets a short hold delay when stopping to let dynamics settle before disabling steppers. Value 255 keeps motors enabled with no delay." 4 | "2","Step pulse invert","mask","Inverts the step signal. Set axis bit to invert (00000ZYX)." 5 | "3","Step direction invert","mask","Inverts the direction signal. Set axis bit to invert (00000ZYX)." 6 | "4","Invert step enable pin","boolean","Inverts the stepper driver enable pin signal." 7 | "5","Invert limit pins","boolean","Inverts the all of the limit input pins." 8 | "6","Invert probe pin","boolean","Inverts the probe input pin signal." 9 | "10","Status report options","mask","Alters data included in status reports." 10 | "11","Junction deviation","millimeters","Sets how fast Grbl travels through consecutive motions. Lower value slows it down." 11 | "12","Arc tolerance","millimeters","Sets the G2 and G3 arc tracing accuracy based on radial error. Beware: A very small value may effect performance." 12 | "13","Report in inches","boolean","Enables inch units when returning any position and rate value that is not a settings value." 13 | "20","Soft limits enable","boolean","Enables soft limits checks within machine travel and sets alarm when exceeded. Requires homing." 14 | "21","Hard limits enable","boolean","Enables hard limits. Immediately halts motion and throws an alarm when switch is triggered." 15 | "22","Homing cycle enable","boolean","Enables homing cycle. Requires limit switches on all axes." 16 | "23","Homing direction invert","mask","Homing searches for a switch in the positive direction. Set axis bit (00000ZYX) to search in negative direction." 17 | "24","Homing locate feed rate","mm/min","Feed rate to slowly engage limit switch to determine its location accurately." 18 | "25","Homing search seek rate","mm/min","Seek rate to quickly find the limit switch before the slower locating phase." 19 | "26","Homing switch debounce delay","milliseconds","Sets a short delay between phases of homing cycle to let a switch debounce." 20 | "27","Homing switch pull-off distance","millimeters","Retract distance after triggering switch to disengage it. Homing will fail if switch isn't cleared." 21 | "30","Maximum spindle speed","RPM","Maximum spindle speed. Sets PWM to 100% duty cycle." 22 | "31","Minimum spindle speed","RPM","Minimum spindle speed. Sets PWM to 0.4% or lowest duty cycle." 23 | "32","Laser-mode enable","boolean","Enables laser mode. Consecutive G1/2/3 commands will not halt when spindle speed is changed." 24 | "100","X-axis travel resolution","step/mm","X-axis travel resolution in steps per millimeter." 25 | "101","Y-axis travel resolution","step/mm","Y-axis travel resolution in steps per millimeter." 26 | "102","Z-axis travel resolution","step/mm","Z-axis travel resolution in steps per millimeter." 27 | "110","X-axis maximum rate","mm/min","X-axis maximum rate. Used as G0 rapid rate." 28 | "111","Y-axis maximum rate","mm/min","Y-axis maximum rate. Used as G0 rapid rate." 29 | "112","Z-axis maximum rate","mm/min","Z-axis maximum rate. Used as G0 rapid rate." 30 | "120","X-axis acceleration","mm/sec^2","X-axis acceleration. Used for motion planning to not exceed motor torque and lose steps." 31 | "121","Y-axis acceleration","mm/sec^2","Y-axis acceleration. Used for motion planning to not exceed motor torque and lose steps." 32 | "122","Z-axis acceleration","mm/sec^2","Z-axis acceleration. Used for motion planning to not exceed motor torque and lose steps." 33 | "130","X-axis maximum travel","millimeters","Maximum X-axis travel distance from homing switch. Determines valid machine space for soft-limits and homing search distances." 34 | "131","Y-axis maximum travel","millimeters","Maximum Y-axis travel distance from homing switch. Determines valid machine space for soft-limits and homing search distances." 35 | "132","Z-axis maximum travel","millimeters","Maximum Z-axis travel distance from homing switch. Determines valid machine space for soft-limits and homing search distances." 36 | -------------------------------------------------------------------------------- /embedded/build.bat: -------------------------------------------------------------------------------- 1 | bin2c /infile tool.html.gz /outfile out.h /targetfolder . 2 | -------------------------------------------------------------------------------- /embedded/gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'), 2 | jshint = require('gulp-jshint'), 3 | gulpif = require('gulp-if'), 4 | concat = require('gulp-concat'), 5 | uglify = require('gulp-uglify'), 6 | cleanCSS = require('gulp-clean-css'), 7 | removeCode = require('gulp-remove-code'), 8 | merge = require('merge-stream'), 9 | del = require('del'), 10 | zip = require('gulp-zip'), 11 | gzip = require('gulp-gzip'), 12 | htmlmin = require('gulp-htmlmin'), 13 | replace = require('gulp-replace'), 14 | fs = require('fs'), 15 | smoosher = require('gulp-smoosher'); 16 | 17 | var demoMode = false; 18 | var testMode = false; 19 | 20 | function clean() { 21 | return del(['dist']); 22 | } 23 | 24 | function clean2() { 25 | return del(['dist/js', 'dist/css']); 26 | } 27 | function lint() { 28 | return gulp.src('www/js/**/script.js') 29 | .pipe(jshint()) 30 | .pipe(jshint.reporter('default')); 31 | } 32 | 33 | function Copytest() { 34 | return merge( 35 | gulp.src(['www/tool.html']) 36 | .pipe(removeCode({production: false})) 37 | .pipe(gulp.dest('dist')), 38 | gulp.src(['www/images/**/*.*']) 39 | .pipe(gulp.dest('dist/images')) 40 | ) 41 | } 42 | 43 | function Copy() { 44 | return merge( 45 | gulp.src(['www/tool.html']) 46 | .pipe(removeCode({production: true})) 47 | .pipe(gulp.dest('dist')), 48 | gulp.src(['www/images/**/*.*']) 49 | .pipe(gulp.dest('dist/images')) 50 | ) 51 | } 52 | 53 | function concatApptest() { 54 | return merge( 55 | gulp.src([ 'www/js/**/*.js']) 56 | .pipe(concat('script.js')) 57 | .pipe(removeCode({production: false})) 58 | .pipe(gulp.dest('./dist/js')), 59 | 60 | gulp.src([ 'www/css/**/*.css']) 61 | .pipe(concat('style.css')) 62 | .pipe(gulp.dest('./dist/css/')) 63 | ) 64 | } 65 | 66 | function concatApp() { 67 | return merge( 68 | gulp.src([ 'www/js/**/*.js']) 69 | .pipe(concat('script.js')) 70 | .pipe(removeCode({production: true})) 71 | .pipe(gulp.dest('./dist/js')), 72 | 73 | gulp.src([ 'www/css/**/*.css']) 74 | .pipe(concat('style.css')) 75 | .pipe(gulp.dest('./dist/css/')) 76 | ) 77 | } 78 | 79 | function minifyApp() { 80 | return merge( 81 | gulp.src(['dist/js/script.js']) 82 | .pipe(uglify({mangle: true})) 83 | .pipe(gulp.dest('./dist/js/')), 84 | 85 | gulp.src('dist/css/style.css') 86 | .pipe(cleanCSS({debug: true}, function(details) { 87 | console.log(details.name + ': ' + details.stats.originalSize); 88 | console.log(details.name + ': ' + details.stats.minifiedSize); 89 | })) 90 | .pipe(gulp.dest('./dist/css/')), 91 | 92 | gulp.src('dist/tool.html') 93 | .pipe(htmlmin({collapseWhitespace: true, minifyCSS: true})) 94 | .pipe(gulp.dest('dist')) 95 | ) 96 | } 97 | 98 | function smoosh() { 99 | return gulp.src('dist/tool.html') 100 | .pipe(smoosher()) 101 | .pipe(gulp.dest('dist')) 102 | } 103 | 104 | function compress() { 105 | return gulp.src('dist/tool.html') 106 | .pipe(gzip()) 107 | .pipe(gulp.dest('.')); 108 | } 109 | 110 | gulp.task(clean); 111 | gulp.task(lint); 112 | gulp.task(Copy); 113 | gulp.task(Copytest); 114 | gulp.task(concatApp); 115 | gulp.task(concatApptest); 116 | gulp.task(minifyApp); 117 | gulp.task(smoosh); 118 | gulp.task(clean2); 119 | 120 | var defaultSeries = gulp.series(clean, lint, Copy, concatApp, smoosh); 121 | var packageSeries = gulp.series(clean, lint, Copy, concatApp,minifyApp, smoosh, compress, clean2); 122 | 123 | gulp.task('default', defaultSeries); 124 | gulp.task('package', packageSeries); 125 | 126 | -------------------------------------------------------------------------------- /embedded/install.bat: -------------------------------------------------------------------------------- 1 | npm install --global gulp-cli 2 | npm install --save-dev gulp 3 | npm install --save-dev gulp-jshint 4 | npm install --save-dev jshint 5 | npm install --save-dev gulp-if 6 | npm install --save-dev gulp-concat 7 | npm install --save-dev gulp-uglify 8 | npm install --save-dev gulp-clean-css 9 | npm install --save-dev gulp-remove-code 10 | npm install --save-dev del 11 | npm install --save-dev gulp-zip 12 | npm install --save-dev gulp-gzip 13 | npm install --save-dev gulp-htmlmin 14 | npm install --save-dev gulp-replace 15 | npm install --save-dev gulp-smoosher 16 | -------------------------------------------------------------------------------- /embedded/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "embedded4ESP3D", 3 | "description": "Embedded files for ESP3D", 4 | "devDependencies": { 5 | "del": "^2.2.2", 6 | "deprecated": "0.0.1", 7 | "fs": "0.0.1-security", 8 | "gulp": "github:gulpjs/gulp#4.0", 9 | "gulp-bytediff": "^1.0.0", 10 | "gulp-cdnizer": "^1.1.7", 11 | "gulp-clean-css": "^2.4.0", 12 | "gulp-concat": "^2.6.1", 13 | "gulp-gzip": "^1.4.0", 14 | "gulp-htmlmin": "^3.0.0", 15 | "gulp-if": "^2.0.2", 16 | "gulp-jshint": "^2.0.4", 17 | "gulp-ng-annotate": "^2.0.0", 18 | "gulp-remove-code": "^1.0.2", 19 | "gulp-replace": "^0.5.4", 20 | "gulp-smoosher": "0.0.9", 21 | "gulp-uglify": "^2.1.2", 22 | "gulp-util": "^3.0.1", 23 | "gulp-zip": "^3.2.0", 24 | "jshint": "^2.9.5", 25 | "merge-stream": "^1.0.1" 26 | }, 27 | "repository": "https://github.com/luc-github/ESP3D", 28 | "author": "Luc LEBOSSE", 29 | "license": "(ISC OR GPL-3.0)" 30 | } 31 | -------------------------------------------------------------------------------- /embedded/tool.html.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdring/DrawBot_Badge/3a02d0541c2c60a1747d8ce8d9c7996ca49383f0/embedded/tool.html.gz -------------------------------------------------------------------------------- /embedded/www/tool.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | V1.2 10 |    11 |
12 |
13 |

It seems you do not have any index.html neither index.html.gz, please upload it or update your firmware if necessary.

14 | you can find one here : https://github.com/luc-github/ESP3D-WEBUI 15 |
16 | 17 |
18 |
Flash Filesystem
19 |
20 | 21 |    22 |

23 |
24 |
25 | 26 | 27 | 30 | 35 | 38 | 41 | 42 |
28 | 29 | 31 |
32 | + 33 |
34 |
36 |
37 |
39 |
 
40 |
43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 |
TypeNameSize
55 |
56 | 57 |
58 |
59 |
60 |
61 |
Firmware Update
62 |
63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 |
71 |
72 |
73 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /libraries/ESP32SSDP/ESP32SSDP.h: -------------------------------------------------------------------------------- 1 | /* 2 | ESP32 Simple Service Discovery 3 | Copyright (c) 2015 Hristo Gochkov 4 | 5 | Original (Arduino) version by Filippo Sallemi, July 23, 2014. 6 | Can be found at: https://github.com/nomadnt/uSSDP 7 | 8 | License (MIT license): 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | */ 28 | 29 | #ifndef ESP32SSDP_H 30 | #define ESP32SSDP_H 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #define SSDP_UUID_SIZE 37 37 | #define SSDP_SCHEMA_URL_SIZE 64 38 | #define SSDP_DEVICE_TYPE_SIZE 64 39 | #define SSDP_FRIENDLY_NAME_SIZE 64 40 | #define SSDP_SERIAL_NUMBER_SIZE 32 41 | #define SSDP_PRESENTATION_URL_SIZE 128 42 | #define SSDP_MODEL_NAME_SIZE 64 43 | #define SSDP_MODEL_URL_SIZE 128 44 | #define SSDP_MODEL_VERSION_SIZE 32 45 | #define SSDP_MANUFACTURER_SIZE 64 46 | #define SSDP_MANUFACTURER_URL_SIZE 128 47 | 48 | typedef enum { 49 | NONE, 50 | SEARCH, 51 | NOTIFY 52 | } ssdp_method_t; 53 | 54 | 55 | struct SSDPTimer; 56 | 57 | class SSDPClass{ 58 | public: 59 | SSDPClass(); 60 | ~SSDPClass(); 61 | 62 | bool begin(); 63 | 64 | void schema(WiFiClient client); 65 | 66 | void setDeviceType(const String& deviceType) { setDeviceType(deviceType.c_str()); } 67 | void setDeviceType(const char *deviceType); 68 | void setName(const String& name) { setName(name.c_str()); } 69 | void setName(const char *name); 70 | void setURL(const String& url) { setURL(url.c_str()); } 71 | void setURL(const char *url); 72 | void setSchemaURL(const String& url) { setSchemaURL(url.c_str()); } 73 | void setSchemaURL(const char *url); 74 | void setSerialNumber(const String& serialNumber) { setSerialNumber(serialNumber.c_str()); } 75 | void setSerialNumber(const char *serialNumber); 76 | void setSerialNumber(const uint32_t serialNumber); 77 | void setModelName(const String& name) { setModelName(name.c_str()); } 78 | void setModelName(const char *name); 79 | void setModelNumber(const String& num) { setModelNumber(num.c_str()); } 80 | void setModelNumber(const char *num); 81 | void setModelURL(const String& url) { setModelURL(url.c_str()); } 82 | void setModelURL(const char *url); 83 | void setManufacturer(const String& name) { setManufacturer(name.c_str()); } 84 | void setManufacturer(const char *name); 85 | void setManufacturerURL(const String& url) { setManufacturerURL(url.c_str()); } 86 | void setManufacturerURL(const char *url); 87 | void setHTTPPort(uint16_t port); 88 | void setTTL(uint8_t ttl); 89 | 90 | protected: 91 | void _send(ssdp_method_t method); 92 | void _update(); 93 | void _startTimer(); 94 | static void _onTimerStatic(SSDPClass* self); 95 | 96 | WiFiUDP *_server; 97 | SSDPTimer* _timer; 98 | uint16_t _port; 99 | uint8_t _ttl; 100 | 101 | IPAddress _respondToAddr; 102 | uint16_t _respondToPort; 103 | 104 | bool _pending; 105 | unsigned short _delay; 106 | unsigned long _process_time; 107 | unsigned long _notify_time; 108 | 109 | char _schemaURL[SSDP_SCHEMA_URL_SIZE]; 110 | char _uuid[SSDP_UUID_SIZE]; 111 | char _deviceType[SSDP_DEVICE_TYPE_SIZE]; 112 | char _friendlyName[SSDP_FRIENDLY_NAME_SIZE]; 113 | char _serialNumber[SSDP_SERIAL_NUMBER_SIZE]; 114 | char _presentationURL[SSDP_PRESENTATION_URL_SIZE]; 115 | char _manufacturer[SSDP_MANUFACTURER_SIZE]; 116 | char _manufacturerURL[SSDP_MANUFACTURER_URL_SIZE]; 117 | char _modelName[SSDP_MODEL_NAME_SIZE]; 118 | char _modelURL[SSDP_MODEL_URL_SIZE]; 119 | char _modelNumber[SSDP_MODEL_VERSION_SIZE]; 120 | }; 121 | 122 | #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SSDP) 123 | extern SSDPClass SSDP; 124 | #endif 125 | 126 | #endif 127 | -------------------------------------------------------------------------------- /libraries/ESP32SSDP/README.rst: -------------------------------------------------------------------------------- 1 | ESP32 Simple Service Discovery Copyright (c) 2015 Hristo Gochkov 2 | Original (Arduino) version by Filippo Sallemi, July 23, 2014. Can be 3 | found at: https://github.com/nomadnt/uSSDP 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a 6 | copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /libraries/ESP32SSDP/examples/SSDP/SSDP.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | const char* ssid = "********"; 6 | const char* password = "********"; 7 | 8 | WebServer HTTP(80); 9 | 10 | void setup() { 11 | Serial.begin(115200); 12 | Serial.println(); 13 | Serial.println("Starting WiFi..."); 14 | 15 | WiFi.mode(WIFI_STA); 16 | WiFi.begin(ssid, password); 17 | if(WiFi.waitForConnectResult() == WL_CONNECTED){ 18 | 19 | Serial.printf("Starting HTTP...\n"); 20 | HTTP.on("/index.html", HTTP_GET, [](){ 21 | HTTP.send(200, "text/plain", "Hello World!"); 22 | }); 23 | HTTP.on("/description.xml", HTTP_GET, [](){ 24 | SSDP.schema(HTTP.client()); 25 | }); 26 | HTTP.begin(); 27 | 28 | Serial.printf("Starting SSDP...\n"); 29 | SSDP.setSchemaURL("description.xml"); 30 | SSDP.setHTTPPort(80); 31 | SSDP.setName("Philips hue clone"); 32 | SSDP.setSerialNumber("001788102201"); 33 | SSDP.setURL("index.html"); 34 | SSDP.setModelName("Philips hue bridge 2012"); 35 | SSDP.setModelNumber("929000226503"); 36 | SSDP.setModelURL("http://www.meethue.com"); 37 | SSDP.setManufacturer("Royal Philips Electronics"); 38 | SSDP.setManufacturerURL("http://www.philips.com"); 39 | SSDP.begin(); 40 | 41 | Serial.printf("Ready!\n"); 42 | } else { 43 | Serial.printf("WiFi Failed\n"); 44 | while(1) delay(100); 45 | } 46 | } 47 | 48 | void loop() { 49 | HTTP.handleClient(); 50 | delay(1); 51 | } 52 | -------------------------------------------------------------------------------- /libraries/ESP32SSDP/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Ultrasound 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | ESP8266SSDP KEYWORD1 10 | SSDP KEYWORD1 11 | 12 | ####################################### 13 | # Methods and Functions (KEYWORD2) 14 | ####################################### 15 | 16 | begin KEYWORD2 17 | schema KEYWORD2 18 | setName KEYWORD2 19 | setURL KEYWORD2 20 | setHTTPPort KEYWORD2 21 | setSchemaURL KEYWORD2 22 | setSerialNumber KEYWORD2 23 | setModelName KEYWORD2 24 | setModelNumber KEYWORD2 25 | setModelURL KEYWORD2 26 | setManufacturer KEYWORD2 27 | setManufacturerURL KEYWORD2 28 | 29 | ####################################### 30 | # Constants (LITERAL1) 31 | ####################################### 32 | SSDP_INTERVAL LITERAL1 33 | SSDP_PORT LITERAL1 34 | SSDP_METHOD_SIZE LITERAL1 35 | SSDP_URI_SIZE LITERAL1 36 | SSDP_BUFFER_SIZE LITERAL1 37 | SSDP_BASE_SIZE LITERAL1 38 | SSDP_FRIENDLY_NAME_SIZE LITERAL1 39 | SSDP_SERIAL_NUMBER_SIZE LITERAL1 40 | SSDP_PRESENTATION_URL_SIZE LITERAL1 41 | SSDP_MODEL_NAME_SIZE LITERAL1 42 | SSDP_MODEL_URL_SIZE LITERAL1 43 | SSDP_MODEL_VERSION_SIZE LITERAL1 44 | SSDP_MANUFACTURER_SIZE LITERAL1 45 | SSDP_MANUFACTURER_URL_SIZE LITERAL1 46 | SEARCH LITERAL1 47 | NOTIFY LITERAL1 48 | BASIC LITERAL1 49 | MANAGEABLE LITERAL1 50 | SOLARPROTECTIONBLIND LITERAL1 51 | DIGITALSECURITYCAMERA LITERAL1 52 | HVAC LITERAL1 53 | LIGHTINGCONTROL LITERAL1 54 | -------------------------------------------------------------------------------- /libraries/ESP32SSDP/library.properties: -------------------------------------------------------------------------------- 1 | name=ESP32SSPD 2 | version=1.0 3 | author=Me-No-Dev 4 | maintainer=Me-No-Dev 5 | sentence=Simple SSDP library for ESP32 6 | paragraph=Only for ESP32 7 | category=Communication 8 | url= 9 | architectures=esp32 10 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | /tests/webSocketServer/node_modules 30 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: bash 3 | os: 4 | - linux 5 | env: 6 | matrix: 7 | - CPU="esp8266" BOARD="esp8266com:esp8266:generic:CpuFrequency=80" IDE_VERSION=1.6.5 8 | - CPU="esp8266" BOARD="esp8266com:esp8266:generic:CpuFrequency=80,FlashSize=1M0,FlashMode=qio,FlashFreq=80" IDE_VERSION=1.8.5 9 | - CPU="esp8266" BOARD="esp8266com:esp8266:generic:CpuFrequency=80,Debug=Serial1" IDE_VERSION=1.6.5 10 | - CPU="esp32" BOARD="espressif:esp32:esp32:FlashFreq=80" IDE_VERSION=1.6.5 11 | - CPU="esp32" BOARD="espressif:esp32:esp32:FlashFreq=80" IDE_VERSION=1.8.5 12 | 13 | script: 14 | - /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16 15 | - sleep 3 16 | - export DISPLAY=:1.0 17 | - wget http://downloads.arduino.cc/arduino-$IDE_VERSION-linux64.tar.xz 18 | - tar xf arduino-$IDE_VERSION-linux64.tar.xz 19 | - mv arduino-$IDE_VERSION $HOME/arduino_ide 20 | - export PATH="$HOME/arduino_ide:$PATH" 21 | - which arduino 22 | - mkdir -p $HOME/Arduino/libraries 23 | - cp -r $TRAVIS_BUILD_DIR $HOME/Arduino/libraries/arduinoWebSockets 24 | - source $TRAVIS_BUILD_DIR/travis/common.sh 25 | - get_core $CPU 26 | - cd $TRAVIS_BUILD_DIR 27 | - arduino --board $BOARD --save-prefs 28 | - arduino --get-pref sketchbook.path 29 | - build_sketches arduino $HOME/Arduino/libraries/arduinoWebSockets/examples/$CPU $CPU 30 | 31 | notifications: 32 | email: 33 | on_success: change 34 | on_failure: change 35 | webhooks: 36 | urls: 37 | - https://webhooks.gitter.im/e/1aa78fbe15080b0c2e37 38 | on_success: change # options: [always|never|change] default: always 39 | on_failure: always # options: [always|never|change] default: always 40 | on_start: false # default: false 41 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/README.md: -------------------------------------------------------------------------------- 1 | WebSocket Server and Client for Arduino [![Build Status](https://travis-ci.org/Links2004/arduinoWebSockets.svg?branch=master)](https://travis-ci.org/Links2004/arduinoWebSockets) 2 | =========================================== 3 | 4 | a WebSocket Server and Client for Arduino based on RFC6455. 5 | 6 | 7 | ##### Supported features of RFC6455 ##### 8 | - text frame 9 | - binary frame 10 | - connection close 11 | - ping 12 | - pong 13 | - continuation frame 14 | 15 | ##### Limitations ##### 16 | - max input length is limited to the ram size and the ```WEBSOCKETS_MAX_DATA_SIZE``` define 17 | - max output length has no limit (the hardware is the limit) 18 | - Client send big frames with mask 0x00000000 (on AVR all frames) 19 | - continuation frame reassembly need to be handled in the application code 20 | 21 | ##### Limitations for Async ##### 22 | - Functions called from within the context of the websocket event might not honor `yield()` and/or `delay()`. See [this issue](https://github.com/Links2004/arduinoWebSockets/issues/58#issuecomment-192376395) for more info and a potential workaround. 23 | - wss / SSL is not possible. 24 | 25 | ##### Supported Hardware ##### 26 | - ESP8266 [Arduino for ESP8266](https://github.com/esp8266/Arduino/) 27 | - ESP32 [Arduino for ESP32](https://github.com/espressif/arduino-esp32) 28 | - ESP31B 29 | - Particle with STM32 ARM Cortex M3 30 | - ATmega328 with Ethernet Shield (ATmega branch) 31 | - ATmega328 with enc28j60 (ATmega branch) 32 | - ATmega2560 with Ethernet Shield (ATmega branch) 33 | - ATmega2560 with enc28j60 (ATmega branch) 34 | 35 | ###### Note: ###### 36 | 37 | version 2.0 and up is not compatible with AVR/ATmega, check ATmega branch. 38 | 39 | Arduino for AVR not supports std namespace of c++. 40 | 41 | ### wss / SSL ### 42 | supported for: 43 | - wss client on the ESP8266 44 | - wss / SSL is not natively supported in WebSocketsServer however it is possible to achieve secure websockets 45 | by running the device behind an SSL proxy. See [Nginx](examples/Nginx/esp8266.ssl.reverse.proxy.conf) for a 46 | sample Nginx server configuration file to enable this. 47 | 48 | ### ESP Async TCP ### 49 | 50 | This libary can run in Async TCP mode on the ESP. 51 | 52 | The mode can be activated in the ```WebSockets.h``` (see WEBSOCKETS_NETWORK_TYPE define). 53 | 54 | [ESPAsyncTCP](https://github.com/me-no-dev/ESPAsyncTCP) libary is required. 55 | 56 | 57 | ### High Level Client API ### 58 | 59 | - `begin` : Initiate connection sequence to the websocket host. 60 | ``` 61 | void begin(const char *host, uint16_t port, const char * url = "/", const char * protocol = "arduino"); 62 | void begin(String host, uint16_t port, String url = "/", String protocol = "arduino"); 63 | ``` 64 | - `onEvent`: Callback to handle for websocket events 65 | 66 | ``` 67 | void onEvent(WebSocketClientEvent cbEvent); 68 | ``` 69 | 70 | - `WebSocketClientEvent`: Handler for websocket events 71 | ``` 72 | void (*WebSocketClientEvent)(WStype_t type, uint8_t * payload, size_t length) 73 | ``` 74 | Where `WStype_t type` is defined as: 75 | ``` 76 | typedef enum { 77 | WStype_ERROR, 78 | WStype_DISCONNECTED, 79 | WStype_CONNECTED, 80 | WStype_TEXT, 81 | WStype_BIN, 82 | WStype_FRAGMENT_TEXT_START, 83 | WStype_FRAGMENT_BIN_START, 84 | WStype_FRAGMENT, 85 | WStype_FRAGMENT_FIN, 86 | } WStype_t; 87 | ``` 88 | 89 | ### Issues ### 90 | Submit issues to: https://github.com/Links2004/arduinoWebSockets/issues 91 | 92 | [![Join the chat at https://gitter.im/Links2004/arduinoWebSockets](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Links2004/arduinoWebSockets?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 93 | 94 | ### License and credits ### 95 | 96 | The library is licensed under [LGPLv2.1](https://github.com/Links2004/arduinoWebSockets/blob/master/LICENSE) 97 | 98 | [libb64](http://libb64.sourceforge.net/) written by Chris Venter. It is distributed under Public Domain see [LICENSE](https://github.com/Links2004/arduinoWebSockets/blob/master/src/libb64/LICENSE). 99 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/examples/Nginx/esp8266.ssl.reverse.proxy.conf: -------------------------------------------------------------------------------- 1 | # ESP8266 nginx SSL reverse proxy configuration file (tested and working on nginx v1.10.0) 2 | 3 | # proxy cache location 4 | proxy_cache_path /opt/etc/nginx/cache levels=1:2 keys_zone=ESP8266_cache:10m max_size=10g inactive=5m use_temp_path=off; 5 | 6 | # webserver proxy 7 | server { 8 | 9 | # general server parameters 10 | listen 50080; 11 | server_name myDomain.net; 12 | access_log /opt/var/log/nginx/myDomain.net.access.log; 13 | 14 | # SSL configuration 15 | ssl on; 16 | ssl_certificate /usr/builtin/etc/certificate/lets-encrypt/myDomain.net/fullchain.pem; 17 | ssl_certificate_key /usr/builtin/etc/certificate/lets-encrypt/myDomain.net/privkey.pem; 18 | ssl_session_cache builtin:1000 shared:SSL:10m; 19 | ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 20 | ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4; 21 | ssl_prefer_server_ciphers on; 22 | 23 | location / { 24 | 25 | # proxy caching configuration 26 | proxy_cache ESP8266_cache; 27 | proxy_cache_revalidate on; 28 | proxy_cache_min_uses 1; 29 | proxy_cache_use_stale off; 30 | proxy_cache_lock on; 31 | # proxy_cache_bypass $http_cache_control; 32 | # include the sessionId cookie value as part of the cache key - keeps the cache per user 33 | # proxy_cache_key $proxy_host$request_uri$cookie_sessionId; 34 | 35 | # header pass through configuration 36 | proxy_set_header Host $host; 37 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 38 | proxy_set_header X-Forwarded-Proto $scheme; 39 | 40 | # ESP8266 custom headers which identify to the device that it's running through an SSL proxy 41 | proxy_set_header X-SSL On; 42 | proxy_set_header X-SSL-WebserverPort 50080; 43 | proxy_set_header X-SSL-WebsocketPort 50081; 44 | 45 | # extra debug headers 46 | add_header X-Proxy-Cache $upstream_cache_status; 47 | add_header X-Forwarded-For $proxy_add_x_forwarded_for; 48 | 49 | # actual proxying configuration 50 | proxy_ssl_session_reuse on; 51 | # target the IP address of the device with proxy_pass 52 | proxy_pass http://192.168.0.20; 53 | proxy_read_timeout 90; 54 | } 55 | } 56 | 57 | # websocket proxy 58 | server { 59 | 60 | # general server parameters 61 | listen 50081; 62 | server_name myDomain.net; 63 | access_log /opt/var/log/nginx/myDomain.net.wss.access.log; 64 | 65 | # SSL configuration 66 | ssl on; 67 | ssl_certificate /usr/builtin/etc/certificate/lets-encrypt/myDomain.net/fullchain.pem; 68 | ssl_certificate_key /usr/builtin/etc/certificate/lets-encrypt/myDomain.net/privkey.pem; 69 | ssl_session_cache builtin:1000 shared:SSL:10m; 70 | ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 71 | ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4; 72 | ssl_prefer_server_ciphers on; 73 | 74 | location / { 75 | 76 | # websocket upgrade tunnel configuration 77 | proxy_pass http://192.168.0.20:81; 78 | proxy_http_version 1.1; 79 | proxy_set_header Upgrade $http_upgrade; 80 | proxy_set_header Connection "Upgrade"; 81 | proxy_read_timeout 86400; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/examples/avr/WebSocketClientAVR/WebSocketClientAVR.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * WebSocketClientAVR.ino 3 | * 4 | * Created on: 10.12.2015 5 | * 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | 16 | 17 | // Enter a MAC address for your controller below. 18 | // Newer Ethernet shields have a MAC address printed on a sticker on the shield 19 | byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 20 | 21 | // Set the static IP address to use if the DHCP fails to assign 22 | IPAddress ip(192, 168, 0, 177); 23 | 24 | WebSocketsClient webSocket; 25 | 26 | 27 | 28 | void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) { 29 | 30 | 31 | switch(type) { 32 | case WStype_DISCONNECTED: 33 | Serial.println("[WSc] Disconnected!\n"); 34 | break; 35 | case WStype_CONNECTED: 36 | { 37 | Serial.print("[WSc] Connected to url: "); 38 | Serial.println((char *)payload); 39 | // send message to server when Connected 40 | webSocket.sendTXT("Connected"); 41 | } 42 | break; 43 | case WStype_TEXT: 44 | Serial.print("[WSc] get text: "); 45 | Serial.println((char *)payload); 46 | // send message to server 47 | // webSocket.sendTXT("message here"); 48 | break; 49 | case WStype_BIN: 50 | Serial.print("[WSc] get binary length: "); 51 | Serial.println(length); 52 | // hexdump(payload, length); 53 | 54 | // send data to server 55 | // webSocket.sendBIN(payload, length); 56 | break; 57 | } 58 | 59 | } 60 | 61 | void setup() 62 | { 63 | // Open serial communications and wait for port to open: 64 | Serial.begin(115200); 65 | while (!Serial) {} 66 | 67 | // start the Ethernet connection: 68 | if (Ethernet.begin(mac) == 0) { 69 | Serial.println("Failed to configure Ethernet using DHCP"); 70 | // no point in carrying on, so do nothing forevermore: 71 | // try to congifure using IP address instead of DHCP: 72 | Ethernet.begin(mac, ip); 73 | } 74 | 75 | webSocket.begin("192.168.0.123", 8011); 76 | webSocket.onEvent(webSocketEvent); 77 | 78 | } 79 | 80 | 81 | void loop() 82 | { 83 | webSocket.loop(); 84 | } 85 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/examples/esp32/WebSocketClient/WebSocketClient.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * WebSocketClient.ino 3 | * 4 | * Created on: 24.05.2015 5 | * 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | 17 | WiFiMulti WiFiMulti; 18 | WebSocketsClient webSocket; 19 | 20 | #define USE_SERIAL Serial1 21 | 22 | void hexdump(const void *mem, uint32_t len, uint8_t cols = 16) { 23 | const uint8_t* src = (const uint8_t*) mem; 24 | USE_SERIAL.printf("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)", (ptrdiff_t)src, len, len); 25 | for(uint32_t i = 0; i < len; i++) { 26 | if(i % cols == 0) { 27 | USE_SERIAL.printf("\n[0x%08X] 0x%08X: ", (ptrdiff_t)src, i); 28 | } 29 | USE_SERIAL.printf("%02X ", *src); 30 | src++; 31 | } 32 | USE_SERIAL.printf("\n"); 33 | } 34 | 35 | void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) { 36 | 37 | switch(type) { 38 | case WStype_DISCONNECTED: 39 | USE_SERIAL.printf("[WSc] Disconnected!\n"); 40 | break; 41 | case WStype_CONNECTED: 42 | USE_SERIAL.printf("[WSc] Connected to url: %s\n", payload); 43 | 44 | // send message to server when Connected 45 | webSocket.sendTXT("Connected"); 46 | break; 47 | case WStype_TEXT: 48 | USE_SERIAL.printf("[WSc] get text: %s\n", payload); 49 | 50 | // send message to server 51 | // webSocket.sendTXT("message here"); 52 | break; 53 | case WStype_BIN: 54 | USE_SERIAL.printf("[WSc] get binary length: %u\n", length); 55 | hexdump(payload, length); 56 | 57 | // send data to server 58 | // webSocket.sendBIN(payload, length); 59 | break; 60 | case WStype_ERROR: 61 | case WStype_FRAGMENT_TEXT_START: 62 | case WStype_FRAGMENT_BIN_START: 63 | case WStype_FRAGMENT: 64 | case WStype_FRAGMENT_FIN: 65 | break; 66 | } 67 | 68 | } 69 | 70 | void setup() { 71 | // USE_SERIAL.begin(921600); 72 | USE_SERIAL.begin(115200); 73 | 74 | //Serial.setDebugOutput(true); 75 | USE_SERIAL.setDebugOutput(true); 76 | 77 | USE_SERIAL.println(); 78 | USE_SERIAL.println(); 79 | USE_SERIAL.println(); 80 | 81 | for(uint8_t t = 4; t > 0; t--) { 82 | USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t); 83 | USE_SERIAL.flush(); 84 | delay(1000); 85 | } 86 | 87 | WiFiMulti.addAP("SSID", "passpasspass"); 88 | 89 | //WiFi.disconnect(); 90 | while(WiFiMulti.run() != WL_CONNECTED) { 91 | delay(100); 92 | } 93 | 94 | // server address, port and URL 95 | webSocket.begin("192.168.0.123", 81, "/"); 96 | 97 | // event handler 98 | webSocket.onEvent(webSocketEvent); 99 | 100 | // use HTTP Basic Authorization this is optional remove if not needed 101 | webSocket.setAuthorization("user", "Password"); 102 | 103 | // try ever 5000 again if connection has failed 104 | webSocket.setReconnectInterval(5000); 105 | 106 | } 107 | 108 | void loop() { 109 | webSocket.loop(); 110 | } 111 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/examples/esp32/WebSocketClientSSL/WebSocketClientSSL.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * WebSocketClientSSL.ino 3 | * 4 | * Created on: 10.12.2015 5 | * 6 | * note SSL is only possible with the ESP8266 7 | * 8 | */ 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | 19 | WiFiMulti WiFiMulti; 20 | WebSocketsClient webSocket; 21 | 22 | #define USE_SERIAL Serial1 23 | 24 | void hexdump(const void *mem, uint32_t len, uint8_t cols = 16) { 25 | const uint8_t* src = (const uint8_t*) mem; 26 | USE_SERIAL.printf("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)", (ptrdiff_t)src, len, len); 27 | for(uint32_t i = 0; i < len; i++) { 28 | if(i % cols == 0) { 29 | USE_SERIAL.printf("\n[0x%08X] 0x%08X: ", (ptrdiff_t)src, i); 30 | } 31 | USE_SERIAL.printf("%02X ", *src); 32 | src++; 33 | } 34 | USE_SERIAL.printf("\n"); 35 | } 36 | 37 | void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) { 38 | 39 | 40 | switch(type) { 41 | case WStype_DISCONNECTED: 42 | USE_SERIAL.printf("[WSc] Disconnected!\n"); 43 | break; 44 | case WStype_CONNECTED: 45 | { 46 | USE_SERIAL.printf("[WSc] Connected to url: %s\n", payload); 47 | 48 | // send message to server when Connected 49 | webSocket.sendTXT("Connected"); 50 | } 51 | break; 52 | case WStype_TEXT: 53 | USE_SERIAL.printf("[WSc] get text: %s\n", payload); 54 | 55 | // send message to server 56 | // webSocket.sendTXT("message here"); 57 | break; 58 | case WStype_BIN: 59 | USE_SERIAL.printf("[WSc] get binary length: %u\n", length); 60 | hexdump(payload, length); 61 | 62 | // send data to server 63 | // webSocket.sendBIN(payload, length); 64 | break; 65 | case WStype_ERROR: 66 | case WStype_FRAGMENT_TEXT_START: 67 | case WStype_FRAGMENT_BIN_START: 68 | case WStype_FRAGMENT: 69 | case WStype_FRAGMENT_FIN: 70 | break; 71 | } 72 | 73 | } 74 | 75 | void setup() { 76 | // USE_SERIAL.begin(921600); 77 | USE_SERIAL.begin(115200); 78 | 79 | //Serial.setDebugOutput(true); 80 | USE_SERIAL.setDebugOutput(true); 81 | 82 | USE_SERIAL.println(); 83 | USE_SERIAL.println(); 84 | USE_SERIAL.println(); 85 | 86 | for(uint8_t t = 4; t > 0; t--) { 87 | USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t); 88 | USE_SERIAL.flush(); 89 | delay(1000); 90 | } 91 | 92 | WiFiMulti.addAP("SSID", "passpasspass"); 93 | 94 | //WiFi.disconnect(); 95 | while(WiFiMulti.run() != WL_CONNECTED) { 96 | delay(100); 97 | } 98 | 99 | webSocket.beginSSL("192.168.0.123", 81); 100 | webSocket.onEvent(webSocketEvent); 101 | 102 | } 103 | 104 | void loop() { 105 | webSocket.loop(); 106 | } 107 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/examples/esp32/WebSocketServer/WebSocketServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * WebSocketServer.ino 3 | * 4 | * Created on: 22.05.2015 5 | * 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | WiFiMulti WiFiMulti; 17 | WebSocketsServer webSocket = WebSocketsServer(81); 18 | 19 | #define USE_SERIAL Serial1 20 | 21 | void hexdump(const void *mem, uint32_t len, uint8_t cols = 16) { 22 | const uint8_t* src = (const uint8_t*) mem; 23 | USE_SERIAL.printf("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)", (ptrdiff_t)src, len, len); 24 | for(uint32_t i = 0; i < len; i++) { 25 | if(i % cols == 0) { 26 | USE_SERIAL.printf("\n[0x%08X] 0x%08X: ", (ptrdiff_t)src, i); 27 | } 28 | USE_SERIAL.printf("%02X ", *src); 29 | src++; 30 | } 31 | USE_SERIAL.printf("\n"); 32 | } 33 | 34 | void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) { 35 | 36 | switch(type) { 37 | case WStype_DISCONNECTED: 38 | USE_SERIAL.printf("[%u] Disconnected!\n", num); 39 | break; 40 | case WStype_CONNECTED: 41 | { 42 | IPAddress ip = webSocket.remoteIP(num); 43 | USE_SERIAL.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload); 44 | 45 | // send message to client 46 | webSocket.sendTXT(num, "Connected"); 47 | } 48 | break; 49 | case WStype_TEXT: 50 | USE_SERIAL.printf("[%u] get Text: %s\n", num, payload); 51 | 52 | // send message to client 53 | // webSocket.sendTXT(num, "message here"); 54 | 55 | // send data to all connected clients 56 | // webSocket.broadcastTXT("message here"); 57 | break; 58 | case WStype_BIN: 59 | USE_SERIAL.printf("[%u] get binary length: %u\n", num, length); 60 | hexdump(payload, length); 61 | 62 | // send message to client 63 | // webSocket.sendBIN(num, payload, length); 64 | break; 65 | case WStype_ERROR: 66 | case WStype_FRAGMENT_TEXT_START: 67 | case WStype_FRAGMENT_BIN_START: 68 | case WStype_FRAGMENT: 69 | case WStype_FRAGMENT_FIN: 70 | break; 71 | } 72 | 73 | } 74 | 75 | void setup() { 76 | // USE_SERIAL.begin(921600); 77 | USE_SERIAL.begin(115200); 78 | 79 | //Serial.setDebugOutput(true); 80 | USE_SERIAL.setDebugOutput(true); 81 | 82 | USE_SERIAL.println(); 83 | USE_SERIAL.println(); 84 | USE_SERIAL.println(); 85 | 86 | for(uint8_t t = 4; t > 0; t--) { 87 | USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t); 88 | USE_SERIAL.flush(); 89 | delay(1000); 90 | } 91 | 92 | WiFiMulti.addAP("SSID", "passpasspass"); 93 | 94 | while(WiFiMulti.run() != WL_CONNECTED) { 95 | delay(100); 96 | } 97 | 98 | webSocket.begin(); 99 | webSocket.onEvent(webSocketEvent); 100 | } 101 | 102 | void loop() { 103 | webSocket.loop(); 104 | } 105 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/examples/esp8266/WebSocketClient/WebSocketClient.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * WebSocketClient.ino 3 | * 4 | * Created on: 24.05.2015 5 | * 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | 17 | ESP8266WiFiMulti WiFiMulti; 18 | WebSocketsClient webSocket; 19 | 20 | #define USE_SERIAL Serial1 21 | 22 | void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) { 23 | 24 | switch(type) { 25 | case WStype_DISCONNECTED: 26 | USE_SERIAL.printf("[WSc] Disconnected!\n"); 27 | break; 28 | case WStype_CONNECTED: { 29 | USE_SERIAL.printf("[WSc] Connected to url: %s\n", payload); 30 | 31 | // send message to server when Connected 32 | webSocket.sendTXT("Connected"); 33 | } 34 | break; 35 | case WStype_TEXT: 36 | USE_SERIAL.printf("[WSc] get text: %s\n", payload); 37 | 38 | // send message to server 39 | // webSocket.sendTXT("message here"); 40 | break; 41 | case WStype_BIN: 42 | USE_SERIAL.printf("[WSc] get binary length: %u\n", length); 43 | hexdump(payload, length); 44 | 45 | // send data to server 46 | // webSocket.sendBIN(payload, length); 47 | break; 48 | } 49 | 50 | } 51 | 52 | void setup() { 53 | // USE_SERIAL.begin(921600); 54 | USE_SERIAL.begin(115200); 55 | 56 | //Serial.setDebugOutput(true); 57 | USE_SERIAL.setDebugOutput(true); 58 | 59 | USE_SERIAL.println(); 60 | USE_SERIAL.println(); 61 | USE_SERIAL.println(); 62 | 63 | for(uint8_t t = 4; t > 0; t--) { 64 | USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t); 65 | USE_SERIAL.flush(); 66 | delay(1000); 67 | } 68 | 69 | WiFiMulti.addAP("SSID", "passpasspass"); 70 | 71 | //WiFi.disconnect(); 72 | while(WiFiMulti.run() != WL_CONNECTED) { 73 | delay(100); 74 | } 75 | 76 | // server address, port and URL 77 | webSocket.begin("192.168.0.123", 81, "/"); 78 | 79 | // event handler 80 | webSocket.onEvent(webSocketEvent); 81 | 82 | // use HTTP Basic Authorization this is optional remove if not needed 83 | webSocket.setAuthorization("user", "Password"); 84 | 85 | // try ever 5000 again if connection has failed 86 | webSocket.setReconnectInterval(5000); 87 | 88 | } 89 | 90 | void loop() { 91 | webSocket.loop(); 92 | } 93 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/examples/esp8266/WebSocketClientSSL/WebSocketClientSSL.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * WebSocketClientSSL.ino 3 | * 4 | * Created on: 10.12.2015 5 | * 6 | * note SSL is only possible with the ESP8266 7 | * 8 | */ 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include 18 | 19 | ESP8266WiFiMulti WiFiMulti; 20 | WebSocketsClient webSocket; 21 | 22 | 23 | #define USE_SERIAL Serial1 24 | 25 | void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) { 26 | 27 | 28 | switch(type) { 29 | case WStype_DISCONNECTED: 30 | USE_SERIAL.printf("[WSc] Disconnected!\n"); 31 | break; 32 | case WStype_CONNECTED: 33 | { 34 | USE_SERIAL.printf("[WSc] Connected to url: %s\n", payload); 35 | 36 | // send message to server when Connected 37 | webSocket.sendTXT("Connected"); 38 | } 39 | break; 40 | case WStype_TEXT: 41 | USE_SERIAL.printf("[WSc] get text: %s\n", payload); 42 | 43 | // send message to server 44 | // webSocket.sendTXT("message here"); 45 | break; 46 | case WStype_BIN: 47 | USE_SERIAL.printf("[WSc] get binary length: %u\n", length); 48 | hexdump(payload, length); 49 | 50 | // send data to server 51 | // webSocket.sendBIN(payload, length); 52 | break; 53 | } 54 | 55 | } 56 | 57 | void setup() { 58 | // USE_SERIAL.begin(921600); 59 | USE_SERIAL.begin(115200); 60 | 61 | //Serial.setDebugOutput(true); 62 | USE_SERIAL.setDebugOutput(true); 63 | 64 | USE_SERIAL.println(); 65 | USE_SERIAL.println(); 66 | USE_SERIAL.println(); 67 | 68 | for(uint8_t t = 4; t > 0; t--) { 69 | USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t); 70 | USE_SERIAL.flush(); 71 | delay(1000); 72 | } 73 | 74 | WiFiMulti.addAP("SSID", "passpasspass"); 75 | 76 | //WiFi.disconnect(); 77 | while(WiFiMulti.run() != WL_CONNECTED) { 78 | delay(100); 79 | } 80 | 81 | webSocket.beginSSL("192.168.0.123", 81); 82 | webSocket.onEvent(webSocketEvent); 83 | 84 | } 85 | 86 | void loop() { 87 | webSocket.loop(); 88 | } 89 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/examples/esp8266/WebSocketClientSocketIO/WebSocketClientSocketIO.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * WebSocketClientSocketIO.ino 3 | * 4 | * Created on: 06.06.2016 5 | * 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | 17 | ESP8266WiFiMulti WiFiMulti; 18 | WebSocketsClient webSocket; 19 | 20 | 21 | #define USE_SERIAL Serial1 22 | 23 | #define MESSAGE_INTERVAL 30000 24 | #define HEARTBEAT_INTERVAL 25000 25 | 26 | uint64_t messageTimestamp = 0; 27 | uint64_t heartbeatTimestamp = 0; 28 | bool isConnected = false; 29 | 30 | void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) { 31 | 32 | 33 | switch(type) { 34 | case WStype_DISCONNECTED: 35 | USE_SERIAL.printf("[WSc] Disconnected!\n"); 36 | isConnected = false; 37 | break; 38 | case WStype_CONNECTED: 39 | { 40 | USE_SERIAL.printf("[WSc] Connected to url: %s\n", payload); 41 | isConnected = true; 42 | 43 | // send message to server when Connected 44 | // socket.io upgrade confirmation message (required) 45 | webSocket.sendTXT("5"); 46 | } 47 | break; 48 | case WStype_TEXT: 49 | USE_SERIAL.printf("[WSc] get text: %s\n", payload); 50 | 51 | // send message to server 52 | // webSocket.sendTXT("message here"); 53 | break; 54 | case WStype_BIN: 55 | USE_SERIAL.printf("[WSc] get binary length: %u\n", length); 56 | hexdump(payload, length); 57 | 58 | // send data to server 59 | // webSocket.sendBIN(payload, length); 60 | break; 61 | } 62 | 63 | } 64 | 65 | void setup() { 66 | // USE_SERIAL.begin(921600); 67 | USE_SERIAL.begin(115200); 68 | 69 | //Serial.setDebugOutput(true); 70 | USE_SERIAL.setDebugOutput(true); 71 | 72 | USE_SERIAL.println(); 73 | USE_SERIAL.println(); 74 | USE_SERIAL.println(); 75 | 76 | for(uint8_t t = 4; t > 0; t--) { 77 | USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t); 78 | USE_SERIAL.flush(); 79 | delay(1000); 80 | } 81 | 82 | WiFiMulti.addAP("SSID", "passpasspass"); 83 | 84 | //WiFi.disconnect(); 85 | while(WiFiMulti.run() != WL_CONNECTED) { 86 | delay(100); 87 | } 88 | 89 | webSocket.beginSocketIO("192.168.0.123", 81); 90 | //webSocket.setAuthorization("user", "Password"); // HTTP Basic Authorization 91 | webSocket.onEvent(webSocketEvent); 92 | 93 | } 94 | 95 | void loop() { 96 | webSocket.loop(); 97 | 98 | if(isConnected) { 99 | 100 | uint64_t now = millis(); 101 | 102 | if(now - messageTimestamp > MESSAGE_INTERVAL) { 103 | messageTimestamp = now; 104 | // example socket.io message with type "messageType" and JSON payload 105 | webSocket.sendTXT("42[\"messageType\",{\"greeting\":\"hello\"}]"); 106 | } 107 | if((now - heartbeatTimestamp) > HEARTBEAT_INTERVAL) { 108 | heartbeatTimestamp = now; 109 | // socket.io heartbeat message 110 | webSocket.sendTXT("2"); 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/examples/esp8266/WebSocketClientStomp/WebSocketClientStomp.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WebSocketClientStomp.ino 3 | 4 | Example for connecting and maintining a connection with a STOMP websocket connection. 5 | In this example, we connect to a Spring application (see https://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html). 6 | 7 | Created on: 25.09.2017 8 | Author: Martin Becker , Contact: becker@informatik.uni-wuerzburg.de 9 | */ 10 | 11 | // PRE 12 | 13 | #define USE_SERIAL Serial 14 | 15 | 16 | // LIBRARIES 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | 25 | // SETTINGS 26 | 27 | const char* wlan_ssid = "yourssid"; 28 | const char* wlan_password = "somepassword"; 29 | 30 | const char* ws_host = "the.host.net"; 31 | const int ws_port = 80; 32 | 33 | // URL for STOMP endpoint. 34 | // For the default config of Spring's STOMP support, the default URL is "/socketentry/websocket". 35 | const char* stompUrl = "/socketentry/websocket"; // don't forget the leading "/" !!! 36 | 37 | 38 | // VARIABLES 39 | 40 | WebSocketsClient webSocket; 41 | 42 | 43 | // FUNCTIONS 44 | 45 | /** 46 | * STOMP messages need to be NULL-terminated (i.e., \0 or \u0000). 47 | * However, when we send a String or a char[] array without specifying 48 | * a length, the size of the message payload is derived by strlen() internally, 49 | * thus dropping any NULL values appended to the "msg"-String. 50 | * 51 | * To solve this, we first convert the String to a NULL terminated char[] array 52 | * via "c_str" and set the length of the payload to include the NULL value. 53 | */ 54 | void sendMessage(String & msg) { 55 | webSocket.sendTXT(msg.c_str(), msg.length() + 1); 56 | } 57 | 58 | void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) { 59 | 60 | switch (type) { 61 | case WStype_DISCONNECTED: 62 | USE_SERIAL.printf("[WSc] Disconnected!\n"); 63 | break; 64 | case WStype_CONNECTED: 65 | { 66 | USE_SERIAL.printf("[WSc] Connected to url: %s\n", payload); 67 | 68 | String msg = "CONNECT\r\naccept-version:1.1,1.0\r\nheart-beat:10000,10000\r\n\r\n"; 69 | sendMessage(msg); 70 | } 71 | break; 72 | case WStype_TEXT: 73 | { 74 | // ##################### 75 | // handle STOMP protocol 76 | // ##################### 77 | 78 | String text = (char*) payload; 79 | USE_SERIAL.printf("[WSc] get text: %s\n", payload); 80 | 81 | if (text.startsWith("CONNECTED")) { 82 | 83 | // subscribe to some channels 84 | 85 | String msg = "SUBSCRIBE\nid:sub-0\ndestination:/user/queue/messages\n\n"; 86 | sendMessage(msg); 87 | delay(1000); 88 | 89 | // and send a message 90 | 91 | msg = "SEND\ndestination:/app/message\n\n{\"user\":\"esp\",\"message\":\"Hello!\"}"; 92 | sendMessage(msg); 93 | delay(1000); 94 | 95 | } else { 96 | 97 | // do something with messages 98 | 99 | } 100 | 101 | break; 102 | } 103 | case WStype_BIN: 104 | USE_SERIAL.printf("[WSc] get binary length: %u\n", length); 105 | hexdump(payload, length); 106 | 107 | // send data to server 108 | // webSocket.sendBIN(payload, length); 109 | break; 110 | } 111 | 112 | } 113 | 114 | void setup() { 115 | 116 | // setup serial 117 | 118 | // USE_SERIAL.begin(921600); 119 | USE_SERIAL.begin(115200); 120 | 121 | // USE_SERIAL.setDebugOutput(true); 122 | 123 | USE_SERIAL.println(); 124 | 125 | 126 | // connect to WiFi 127 | 128 | USE_SERIAL.print("Logging into WLAN: "); Serial.print(wlan_ssid); Serial.print(" ..."); 129 | WiFi.mode(WIFI_STA); 130 | WiFi.begin(wlan_ssid, wlan_password); 131 | 132 | while (WiFi.status() != WL_CONNECTED) { 133 | delay(500); 134 | USE_SERIAL.print("."); 135 | } 136 | USE_SERIAL.println(" success."); 137 | USE_SERIAL.print("IP: "); USE_SERIAL.println(WiFi.localIP()); 138 | 139 | 140 | // connect to websocket 141 | webSocket.begin(ws_host, ws_port, stompUrl); 142 | webSocket.setExtraHeaders(); // remove "Origin: file://" header because it breaks the connection with Spring's default websocket config 143 | // webSocket.setExtraHeaders("foo: I am so funny\r\nbar: not"); // some headers, in case you feel funny 144 | webSocket.onEvent(webSocketEvent); 145 | } 146 | 147 | void loop() { 148 | webSocket.loop(); 149 | } 150 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/examples/esp8266/WebSocketClientStompOverSockJs/WebSocketClientStompOverSockJs.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WebSocketClientStompOverSockJs.ino 3 | 4 | Example for connecting and maintining a connection with a SockJS+STOMP websocket connection. 5 | In this example, we connect to a Spring application (see https://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html). 6 | 7 | Created on: 18.07.2017 8 | Author: Martin Becker , Contact: becker@informatik.uni-wuerzburg.de 9 | */ 10 | 11 | // PRE 12 | 13 | #define USE_SERIAL Serial 14 | 15 | 16 | // LIBRARIES 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | 25 | // SETTINGS 26 | 27 | const char* wlan_ssid = "yourssid"; 28 | const char* wlan_password = "somepassword"; 29 | 30 | const char* ws_host = "the.host.net"; 31 | const int ws_port = 80; 32 | 33 | // base URL for SockJS (websocket) connection 34 | // The complete URL will look something like this(cf. http://sockjs.github.io/sockjs-protocol/sockjs-protocol-0.3.3.html#section-36): 35 | // ws://://<3digits>//websocket 36 | // For the default config of Spring's SockJS/STOMP support, the default base URL is "/socketentry/". 37 | const char* ws_baseurl = "/socketentry/"; // don't forget leading and trailing "/" !!! 38 | 39 | 40 | // VARIABLES 41 | 42 | WebSocketsClient webSocket; 43 | 44 | 45 | // FUNCTIONS 46 | 47 | void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) { 48 | 49 | switch (type) { 50 | case WStype_DISCONNECTED: 51 | USE_SERIAL.printf("[WSc] Disconnected!\n"); 52 | break; 53 | case WStype_CONNECTED: 54 | { 55 | USE_SERIAL.printf("[WSc] Connected to url: %s\n", payload); 56 | } 57 | break; 58 | case WStype_TEXT: 59 | { 60 | // ##################### 61 | // handle SockJs+STOMP protocol 62 | // ##################### 63 | 64 | String text = (char*) payload; 65 | 66 | USE_SERIAL.printf("[WSc] get text: %s\n", payload); 67 | 68 | if (payload[0] == 'h') { 69 | 70 | USE_SERIAL.println("Heartbeat!"); 71 | 72 | } else if (payload[0] == 'o') { 73 | 74 | // on open connection 75 | char *msg = "[\"CONNECT\\naccept-version:1.1,1.0\\nheart-beat:10000,10000\\n\\n\\u0000\"]"; 76 | webSocket.sendTXT(msg); 77 | 78 | } else if (text.startsWith("a[\"CONNECTED")) { 79 | 80 | // subscribe to some channels 81 | 82 | char *msg = "[\"SUBSCRIBE\\nid:sub-0\\ndestination:/user/queue/messages\\n\\n\\u0000\"]"; 83 | webSocket.sendTXT(msg); 84 | delay(1000); 85 | 86 | // and send a message 87 | 88 | msg = "[\"SEND\\ndestination:/app/message\\n\\n{\\\"user\\\":\\\"esp\\\",\\\"message\\\":\\\"Hello!\\\"}\\u0000\"]"; 89 | webSocket.sendTXT(msg); 90 | delay(1000); 91 | } 92 | 93 | break; 94 | } 95 | case WStype_BIN: 96 | USE_SERIAL.printf("[WSc] get binary length: %u\n", length); 97 | hexdump(payload, length); 98 | 99 | // send data to server 100 | // webSocket.sendBIN(payload, length); 101 | break; 102 | } 103 | 104 | } 105 | 106 | void setup() { 107 | 108 | // setup serial 109 | 110 | // USE_SERIAL.begin(921600); 111 | USE_SERIAL.begin(115200); 112 | 113 | // USE_SERIAL.setDebugOutput(true); 114 | 115 | USE_SERIAL.println(); 116 | 117 | 118 | // connect to WiFi 119 | 120 | USE_SERIAL.print("Logging into WLAN: "); Serial.print(wlan_ssid); Serial.print(" ..."); 121 | WiFi.mode(WIFI_STA); 122 | WiFi.begin(wlan_ssid, wlan_password); 123 | 124 | while (WiFi.status() != WL_CONNECTED) { 125 | delay(500); 126 | USE_SERIAL.print("."); 127 | } 128 | USE_SERIAL.println(" success."); 129 | USE_SERIAL.print("IP: "); USE_SERIAL.println(WiFi.localIP()); 130 | 131 | 132 | // ##################### 133 | // create socket url according to SockJS protocol (cf. http://sockjs.github.io/sockjs-protocol/sockjs-protocol-0.3.3.html#section-36) 134 | // ##################### 135 | String socketUrl = ws_baseurl; 136 | socketUrl += random(0, 999); 137 | socketUrl += "/"; 138 | socketUrl += random(0, 999999); // should be a random string, but this works (see ) 139 | socketUrl += "/websocket"; 140 | 141 | // connect to websocket 142 | webSocket.begin(ws_host, ws_port, socketUrl); 143 | webSocket.setExtraHeaders(); // remove "Origin: file://" header because it breaks the connection with Spring's default websocket config 144 | // webSocket.setExtraHeaders("foo: I am so funny\r\nbar: not"); // some headers, in case you feel funny 145 | webSocket.onEvent(webSocketEvent); 146 | } 147 | 148 | void loop() { 149 | webSocket.loop(); 150 | } 151 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/examples/esp8266/WebSocketServer/WebSocketServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * WebSocketServer.ino 3 | * 4 | * Created on: 22.05.2015 5 | * 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | ESP8266WiFiMulti WiFiMulti; 16 | 17 | WebSocketsServer webSocket = WebSocketsServer(81); 18 | 19 | #define USE_SERIAL Serial1 20 | 21 | void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) { 22 | 23 | switch(type) { 24 | case WStype_DISCONNECTED: 25 | USE_SERIAL.printf("[%u] Disconnected!\n", num); 26 | break; 27 | case WStype_CONNECTED: 28 | { 29 | IPAddress ip = webSocket.remoteIP(num); 30 | USE_SERIAL.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload); 31 | 32 | // send message to client 33 | webSocket.sendTXT(num, "Connected"); 34 | } 35 | break; 36 | case WStype_TEXT: 37 | USE_SERIAL.printf("[%u] get Text: %s\n", num, payload); 38 | 39 | // send message to client 40 | // webSocket.sendTXT(num, "message here"); 41 | 42 | // send data to all connected clients 43 | // webSocket.broadcastTXT("message here"); 44 | break; 45 | case WStype_BIN: 46 | USE_SERIAL.printf("[%u] get binary length: %u\n", num, length); 47 | hexdump(payload, length); 48 | 49 | // send message to client 50 | // webSocket.sendBIN(num, payload, length); 51 | break; 52 | } 53 | 54 | } 55 | 56 | void setup() { 57 | // USE_SERIAL.begin(921600); 58 | USE_SERIAL.begin(115200); 59 | 60 | //Serial.setDebugOutput(true); 61 | USE_SERIAL.setDebugOutput(true); 62 | 63 | USE_SERIAL.println(); 64 | USE_SERIAL.println(); 65 | USE_SERIAL.println(); 66 | 67 | for(uint8_t t = 4; t > 0; t--) { 68 | USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t); 69 | USE_SERIAL.flush(); 70 | delay(1000); 71 | } 72 | 73 | WiFiMulti.addAP("SSID", "passpasspass"); 74 | 75 | while(WiFiMulti.run() != WL_CONNECTED) { 76 | delay(100); 77 | } 78 | 79 | webSocket.begin(); 80 | webSocket.onEvent(webSocketEvent); 81 | } 82 | 83 | void loop() { 84 | webSocket.loop(); 85 | } 86 | 87 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/examples/esp8266/WebSocketServerAllFunctionsDemo/WebSocketServerAllFunctionsDemo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * WebSocketServerAllFunctionsDemo.ino 3 | * 4 | * Created on: 10.05.2018 5 | * 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #define LED_RED 15 18 | #define LED_GREEN 12 19 | #define LED_BLUE 13 20 | 21 | #define USE_SERIAL Serial 22 | 23 | ESP8266WiFiMulti WiFiMulti; 24 | 25 | ESP8266WebServer server(80); 26 | WebSocketsServer webSocket = WebSocketsServer(81); 27 | 28 | void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) { 29 | 30 | switch(type) { 31 | case WStype_DISCONNECTED: 32 | USE_SERIAL.printf("[%u] Disconnected!\n", num); 33 | break; 34 | case WStype_CONNECTED: { 35 | IPAddress ip = webSocket.remoteIP(num); 36 | USE_SERIAL.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload); 37 | 38 | // send message to client 39 | webSocket.sendTXT(num, "Connected"); 40 | } 41 | break; 42 | case WStype_TEXT: 43 | USE_SERIAL.printf("[%u] get Text: %s\n", num, payload); 44 | 45 | if(payload[0] == '#') { 46 | // we get RGB data 47 | 48 | // decode rgb data 49 | uint32_t rgb = (uint32_t) strtol((const char *) &payload[1], NULL, 16); 50 | 51 | analogWrite(LED_RED, ((rgb >> 16) & 0xFF)); 52 | analogWrite(LED_GREEN, ((rgb >> 8) & 0xFF)); 53 | analogWrite(LED_BLUE, ((rgb >> 0) & 0xFF)); 54 | } 55 | 56 | break; 57 | } 58 | 59 | } 60 | 61 | void setup() { 62 | //USE_SERIAL.begin(921600); 63 | USE_SERIAL.begin(115200); 64 | 65 | //USE_SERIAL.setDebugOutput(true); 66 | 67 | USE_SERIAL.println(); 68 | USE_SERIAL.println(); 69 | USE_SERIAL.println(); 70 | 71 | for(uint8_t t = 4; t > 0; t--) { 72 | USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t); 73 | USE_SERIAL.flush(); 74 | delay(1000); 75 | } 76 | 77 | pinMode(LED_RED, OUTPUT); 78 | pinMode(LED_GREEN, OUTPUT); 79 | pinMode(LED_BLUE, OUTPUT); 80 | 81 | digitalWrite(LED_RED, 1); 82 | digitalWrite(LED_GREEN, 1); 83 | digitalWrite(LED_BLUE, 1); 84 | 85 | WiFiMulti.addAP("SSID", "passpasspass"); 86 | 87 | while(WiFiMulti.run() != WL_CONNECTED) { 88 | delay(100); 89 | } 90 | 91 | // start webSocket server 92 | webSocket.begin(); 93 | webSocket.onEvent(webSocketEvent); 94 | 95 | if(MDNS.begin("esp8266")) { 96 | USE_SERIAL.println("MDNS responder started"); 97 | } 98 | 99 | // handle index 100 | server.on("/", []() { 101 | // send index.html 102 | server.send(200, "text/html", "LED Control:

R:
G:
B:
"); 103 | }); 104 | 105 | server.begin(); 106 | 107 | // Add service to MDNS 108 | MDNS.addService("http", "tcp", 80); 109 | MDNS.addService("ws", "tcp", 81); 110 | 111 | digitalWrite(LED_RED, 0); 112 | digitalWrite(LED_GREEN, 0); 113 | digitalWrite(LED_BLUE, 0); 114 | 115 | } 116 | 117 | unsigned long last_10sec = 0; 118 | unsigned int counter = 0; 119 | 120 | void loop() { 121 | unsigned long t = millis(); 122 | webSocket.loop(); 123 | server.handleClient(); 124 | 125 | if((t - last_10sec) > 10 * 1000) { 126 | counter++; 127 | bool ping = (counter % 2); 128 | int i = webSocket.connectedClients(ping); 129 | USE_SERIAL.printf("%d Connected websocket clients ping: %d\n", i, ping); 130 | last_10sec = millis(); 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/examples/esp8266/WebSocketServerFragmentation/WebSocketServerFragmentation.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * WebSocketServer.ino 3 | * 4 | * Created on: 22.05.2015 5 | * 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | ESP8266WiFiMulti WiFiMulti; 16 | 17 | WebSocketsServer webSocket = WebSocketsServer(81); 18 | 19 | #define USE_SERIAL Serial 20 | 21 | String fragmentBuffer = ""; 22 | 23 | void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) { 24 | 25 | switch(type) { 26 | case WStype_DISCONNECTED: 27 | USE_SERIAL.printf("[%u] Disconnected!\n", num); 28 | break; 29 | case WStype_CONNECTED: { 30 | IPAddress ip = webSocket.remoteIP(num); 31 | USE_SERIAL.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload); 32 | 33 | // send message to client 34 | webSocket.sendTXT(num, "Connected"); 35 | } 36 | break; 37 | case WStype_TEXT: 38 | USE_SERIAL.printf("[%u] get Text: %s\n", num, payload); 39 | break; 40 | case WStype_BIN: 41 | USE_SERIAL.printf("[%u] get binary length: %u\n", num, length); 42 | hexdump(payload, length); 43 | break; 44 | 45 | // Fragmentation / continuation opcode handling 46 | // case WStype_FRAGMENT_BIN_START: 47 | case WStype_FRAGMENT_TEXT_START: 48 | fragmentBuffer = (char*)payload; 49 | USE_SERIAL.printf("[%u] get start start of Textfragment: %s\n", num, payload); 50 | break; 51 | case WStype_FRAGMENT: 52 | fragmentBuffer += (char*)payload; 53 | USE_SERIAL.printf("[%u] get Textfragment : %s\n", num, payload); 54 | break; 55 | case WStype_FRAGMENT_FIN: 56 | fragmentBuffer += (char*)payload; 57 | USE_SERIAL.printf("[%u] get end of Textfragment: %s\n", num, payload); 58 | USE_SERIAL.printf("[%u] full frame: %s\n", num, fragmentBuffer.c_str()); 59 | break; 60 | } 61 | 62 | } 63 | 64 | void setup() { 65 | // USE_SERIAL.begin(921600); 66 | USE_SERIAL.begin(115200); 67 | 68 | //Serial.setDebugOutput(true); 69 | USE_SERIAL.setDebugOutput(true); 70 | 71 | USE_SERIAL.println(); 72 | USE_SERIAL.println(); 73 | USE_SERIAL.println(); 74 | 75 | for(uint8_t t = 4; t > 0; t--) { 76 | USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t); 77 | USE_SERIAL.flush(); 78 | delay(1000); 79 | } 80 | 81 | WiFiMulti.addAP("SSID", "passpasspass"); 82 | 83 | while(WiFiMulti.run() != WL_CONNECTED) { 84 | delay(100); 85 | } 86 | 87 | webSocket.begin(); 88 | webSocket.onEvent(webSocketEvent); 89 | } 90 | 91 | void loop() { 92 | webSocket.loop(); 93 | } 94 | 95 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/examples/esp8266/WebSocketServerHttpHeaderValidation/WebSocketServerHttpHeaderValidation.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * WebSocketServerHttpHeaderValidation.ino 3 | * 4 | * Created on: 08.06.2016 5 | * 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | ESP8266WiFiMulti WiFiMulti; 16 | 17 | WebSocketsServer webSocket = WebSocketsServer(81); 18 | 19 | #define USE_SERIAL Serial1 20 | 21 | const unsigned long int validSessionId = 12345; //some arbitrary value to act as a valid sessionId 22 | 23 | /* 24 | * Returns a bool value as an indicator to describe whether a user is allowed to initiate a websocket upgrade 25 | * based on the value of a cookie. This function expects the rawCookieHeaderValue to look like this "sessionId=|" 26 | */ 27 | bool isCookieValid(String rawCookieHeaderValue) { 28 | 29 | if (rawCookieHeaderValue.indexOf("sessionId") != -1) { 30 | String sessionIdStr = rawCookieHeaderValue.substring(rawCookieHeaderValue.indexOf("sessionId=") + 10, rawCookieHeaderValue.indexOf("|")); 31 | unsigned long int sessionId = strtoul(sessionIdStr.c_str(), NULL, 10); 32 | return sessionId == validSessionId; 33 | } 34 | return false; 35 | } 36 | 37 | /* 38 | * The WebSocketServerHttpHeaderValFunc delegate passed to webSocket.onValidateHttpHeader 39 | */ 40 | bool validateHttpHeader(String headerName, String headerValue) { 41 | 42 | //assume a true response for any headers not handled by this validator 43 | bool valid = true; 44 | 45 | if(headerName.equalsIgnoreCase("Cookie")) { 46 | //if the header passed is the Cookie header, validate it according to the rules in 'isCookieValid' function 47 | valid = isCookieValid(headerValue); 48 | } 49 | 50 | return valid; 51 | } 52 | 53 | void setup() { 54 | // USE_SERIAL.begin(921600); 55 | USE_SERIAL.begin(115200); 56 | 57 | //Serial.setDebugOutput(true); 58 | USE_SERIAL.setDebugOutput(true); 59 | 60 | USE_SERIAL.println(); 61 | USE_SERIAL.println(); 62 | USE_SERIAL.println(); 63 | 64 | for(uint8_t t = 4; t > 0; t--) { 65 | USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t); 66 | USE_SERIAL.flush(); 67 | delay(1000); 68 | } 69 | 70 | WiFiMulti.addAP("SSID", "passpasspass"); 71 | 72 | while(WiFiMulti.run() != WL_CONNECTED) { 73 | delay(100); 74 | } 75 | 76 | //connecting clients must supply a valid session cookie at websocket upgrade handshake negotiation time 77 | const char * headerkeys[] = { "Cookie" }; 78 | size_t headerKeyCount = sizeof(headerkeys) / sizeof(char*); 79 | webSocket.onValidateHttpHeader(validateHttpHeader, headerkeys, headerKeyCount); 80 | webSocket.begin(); 81 | } 82 | 83 | void loop() { 84 | webSocket.loop(); 85 | } 86 | 87 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/examples/esp8266/WebSocketServer_LEDcontrol/WebSocketServer_LEDcontrol.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * WebSocketServer_LEDcontrol.ino 3 | * 4 | * Created on: 26.11.2015 5 | * 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #define LED_RED 15 18 | #define LED_GREEN 12 19 | #define LED_BLUE 13 20 | 21 | #define USE_SERIAL Serial 22 | 23 | 24 | ESP8266WiFiMulti WiFiMulti; 25 | 26 | ESP8266WebServer server(80); 27 | WebSocketsServer webSocket = WebSocketsServer(81); 28 | 29 | void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) { 30 | 31 | switch(type) { 32 | case WStype_DISCONNECTED: 33 | USE_SERIAL.printf("[%u] Disconnected!\n", num); 34 | break; 35 | case WStype_CONNECTED: { 36 | IPAddress ip = webSocket.remoteIP(num); 37 | USE_SERIAL.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload); 38 | 39 | // send message to client 40 | webSocket.sendTXT(num, "Connected"); 41 | } 42 | break; 43 | case WStype_TEXT: 44 | USE_SERIAL.printf("[%u] get Text: %s\n", num, payload); 45 | 46 | if(payload[0] == '#') { 47 | // we get RGB data 48 | 49 | // decode rgb data 50 | uint32_t rgb = (uint32_t) strtol((const char *) &payload[1], NULL, 16); 51 | 52 | analogWrite(LED_RED, ((rgb >> 16) & 0xFF)); 53 | analogWrite(LED_GREEN, ((rgb >> 8) & 0xFF)); 54 | analogWrite(LED_BLUE, ((rgb >> 0) & 0xFF)); 55 | } 56 | 57 | break; 58 | } 59 | 60 | } 61 | 62 | void setup() { 63 | //USE_SERIAL.begin(921600); 64 | USE_SERIAL.begin(115200); 65 | 66 | //USE_SERIAL.setDebugOutput(true); 67 | 68 | USE_SERIAL.println(); 69 | USE_SERIAL.println(); 70 | USE_SERIAL.println(); 71 | 72 | for(uint8_t t = 4; t > 0; t--) { 73 | USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t); 74 | USE_SERIAL.flush(); 75 | delay(1000); 76 | } 77 | 78 | pinMode(LED_RED, OUTPUT); 79 | pinMode(LED_GREEN, OUTPUT); 80 | pinMode(LED_BLUE, OUTPUT); 81 | 82 | digitalWrite(LED_RED, 1); 83 | digitalWrite(LED_GREEN, 1); 84 | digitalWrite(LED_BLUE, 1); 85 | 86 | WiFiMulti.addAP("SSID", "passpasspass"); 87 | 88 | while(WiFiMulti.run() != WL_CONNECTED) { 89 | delay(100); 90 | } 91 | 92 | // start webSocket server 93 | webSocket.begin(); 94 | webSocket.onEvent(webSocketEvent); 95 | 96 | if(MDNS.begin("esp8266")) { 97 | USE_SERIAL.println("MDNS responder started"); 98 | } 99 | 100 | // handle index 101 | server.on("/", []() { 102 | // send index.html 103 | server.send(200, "text/html", "LED Control:

R:
G:
B:
"); 104 | }); 105 | 106 | server.begin(); 107 | 108 | // Add service to MDNS 109 | MDNS.addService("http", "tcp", 80); 110 | MDNS.addService("ws", "tcp", 81); 111 | 112 | digitalWrite(LED_RED, 0); 113 | digitalWrite(LED_GREEN, 0); 114 | digitalWrite(LED_BLUE, 0); 115 | 116 | } 117 | 118 | void loop() { 119 | webSocket.loop(); 120 | server.handleClient(); 121 | } 122 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/examples/particle/ParticleWebSocketClient/application.cpp: -------------------------------------------------------------------------------- 1 | /* To compile using make CLI, create a folder under \firmware\user\applications and copy application.cpp there. 2 | * Then, copy src files under particleWebSocket folder. 3 | */ 4 | 5 | #include "application.h" 6 | #include "particleWebSocket/WebSocketsClient.h" 7 | 8 | WebSocketsClient webSocket; 9 | 10 | void webSocketEvent(WStype_t type, uint8_t* payload, size_t length) 11 | { 12 | switch (type) 13 | { 14 | case WStype_DISCONNECTED: 15 | Serial.printlnf("[WSc] Disconnected!"); 16 | break; 17 | case WStype_CONNECTED: 18 | Serial.printlnf("[WSc] Connected to URL: %s", payload); 19 | webSocket.sendTXT("Connected\r\n"); 20 | break; 21 | case WStype_TEXT: 22 | Serial.printlnf("[WSc] get text: %s", payload); 23 | break; 24 | case WStype_BIN: 25 | Serial.printlnf("[WSc] get binary length: %u", length); 26 | break; 27 | } 28 | } 29 | 30 | void setup() 31 | { 32 | Serial.begin(9600); 33 | 34 | WiFi.setCredentials("[SSID]", "[PASSWORD]", WPA2, WLAN_CIPHER_AES_TKIP); 35 | WiFi.connect(); 36 | 37 | webSocket.begin("192.168.1.153", 85, "/ClientService/?variable=Test1212"); 38 | webSocket.onEvent(webSocketEvent); 39 | } 40 | 41 | void loop() 42 | { 43 | webSocket.sendTXT("Hello world!"); 44 | delay(500); 45 | webSocket.loop(); 46 | } 47 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "WebSockets", 3 | "description": "WebSocket Server and Client for Arduino based on RFC6455", 4 | "keywords": "wifi, http, web, server, client, websocket", 5 | "authors": [ 6 | { 7 | "name": "Markus Sattler", 8 | "url": "https://github.com/Links2004", 9 | "maintainer": true 10 | } 11 | ], 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/Links2004/arduinoWebSockets.git" 15 | }, 16 | "version": "2.1.2", 17 | "license": "LGPL-2.1", 18 | "export": { 19 | "exclude": [ 20 | "tests" 21 | ] 22 | }, 23 | "frameworks": "arduino", 24 | "platforms": "atmelavr, espressif8266, espressif32" 25 | } 26 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/library.properties: -------------------------------------------------------------------------------- 1 | name=WebSockets 2 | version=2.1.2 3 | author=Markus Sattler 4 | maintainer=Markus Sattler 5 | sentence=WebSockets for Arduino (Server + Client) 6 | paragraph=use 2.x.x for ESP and 1.3 for AVR 7 | category=Communication 8 | url=https://github.com/Links2004/arduinoWebSockets 9 | architectures=* 10 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/src/WebSocketsClient.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file WebSocketsClient.h 3 | * @date 20.05.2015 4 | * @author Markus Sattler 5 | * 6 | * Copyright (c) 2015 Markus Sattler. All rights reserved. 7 | * This file is part of the WebSockets for Arduino. 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | * 23 | */ 24 | 25 | #ifndef WEBSOCKETSCLIENT_H_ 26 | #define WEBSOCKETSCLIENT_H_ 27 | 28 | #include "WebSockets.h" 29 | 30 | class WebSocketsClient: private WebSockets { 31 | public: 32 | #ifdef __AVR__ 33 | typedef void (*WebSocketClientEvent)(WStype_t type, uint8_t * payload, size_t length); 34 | #else 35 | typedef std::function WebSocketClientEvent; 36 | #endif 37 | 38 | 39 | WebSocketsClient(void); 40 | virtual ~WebSocketsClient(void); 41 | 42 | void begin(const char *host, uint16_t port, const char * url = "/", const char * protocol = "arduino"); 43 | void begin(String host, uint16_t port, String url = "/", String protocol = "arduino"); 44 | void begin(IPAddress host, uint16_t port, const char * url = "/", const char * protocol = "arduino"); 45 | 46 | #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) 47 | void beginSSL(const char *host, uint16_t port, const char * url = "/", const char * = "", const char * protocol = "arduino"); 48 | void beginSSL(String host, uint16_t port, String url = "/", String fingerprint = "", String protocol = "arduino"); 49 | #endif 50 | 51 | void beginSocketIO(const char *host, uint16_t port, const char * url = "/socket.io/?EIO=3", const char * protocol = "arduino"); 52 | void beginSocketIO(String host, uint16_t port, String url = "/socket.io/?EIO=3", String protocol = "arduino"); 53 | 54 | #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) 55 | void beginSocketIOSSL(const char *host, uint16_t port, const char * url = "/socket.io/?EIO=3", const char * protocol = "arduino"); 56 | void beginSocketIOSSL(String host, uint16_t port, String url = "/socket.io/?EIO=3", String protocol = "arduino"); 57 | #endif 58 | 59 | #if (WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC) 60 | void loop(void); 61 | #else 62 | // Async interface not need a loop call 63 | void loop(void) __attribute__ ((deprecated)) {} 64 | #endif 65 | 66 | void onEvent(WebSocketClientEvent cbEvent); 67 | 68 | bool sendTXT(uint8_t * payload, size_t length = 0, bool headerToPayload = false); 69 | bool sendTXT(const uint8_t * payload, size_t length = 0); 70 | bool sendTXT(char * payload, size_t length = 0, bool headerToPayload = false); 71 | bool sendTXT(const char * payload, size_t length = 0); 72 | bool sendTXT(String & payload); 73 | 74 | bool sendBIN(uint8_t * payload, size_t length, bool headerToPayload = false); 75 | bool sendBIN(const uint8_t * payload, size_t length); 76 | 77 | bool sendPing(uint8_t * payload = NULL, size_t length = 0); 78 | bool sendPing(String & payload); 79 | 80 | void disconnect(void); 81 | 82 | void setAuthorization(const char * user, const char * password); 83 | void setAuthorization(const char * auth); 84 | 85 | void setExtraHeaders(const char * extraHeaders = NULL); 86 | 87 | void setReconnectInterval(unsigned long time); 88 | 89 | protected: 90 | String _host; 91 | uint16_t _port; 92 | 93 | #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) 94 | String _fingerprint; 95 | #endif 96 | WSclient_t _client; 97 | 98 | WebSocketClientEvent _cbEvent; 99 | 100 | unsigned long _lastConnectionFail; 101 | unsigned long _reconnectInterval; 102 | 103 | void messageReceived(WSclient_t * client, WSopcode_t opcode, uint8_t * payload, size_t length, bool fin); 104 | 105 | void clientDisconnect(WSclient_t * client); 106 | bool clientIsConnected(WSclient_t * client); 107 | 108 | #if (WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC) 109 | void handleClientData(void); 110 | #endif 111 | 112 | void sendHeader(WSclient_t * client); 113 | void handleHeader(WSclient_t * client, String * headerLine); 114 | 115 | void connectedCb(); 116 | void connectFailedCb(); 117 | 118 | #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC) 119 | void asyncConnect(); 120 | #endif 121 | 122 | /** 123 | * called for sending a Event to the app 124 | * @param type WStype_t 125 | * @param payload uint8_t * 126 | * @param length size_t 127 | */ 128 | virtual void runCbEvent(WStype_t type, uint8_t * payload, size_t length) { 129 | if(_cbEvent) { 130 | _cbEvent(type, payload, length); 131 | } 132 | } 133 | 134 | }; 135 | 136 | #endif /* WEBSOCKETSCLIENT_H_ */ 137 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/src/libb64/AUTHORS: -------------------------------------------------------------------------------- 1 | libb64: Base64 Encoding/Decoding Routines 2 | ====================================== 3 | 4 | Authors: 5 | ------- 6 | 7 | Chris Venter chris.venter@gmail.com http://rocketpod.blogspot.com 8 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/src/libb64/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright-Only Dedication (based on United States law) 2 | or Public Domain Certification 3 | 4 | The person or persons who have associated work with this document (the 5 | "Dedicator" or "Certifier") hereby either (a) certifies that, to the best of 6 | his knowledge, the work of authorship identified is in the public domain of the 7 | country from which the work is published, or (b) hereby dedicates whatever 8 | copyright the dedicators holds in the work of authorship identified below (the 9 | "Work") to the public domain. A certifier, moreover, dedicates any copyright 10 | interest he may have in the associated work, and for these purposes, is 11 | described as a "dedicator" below. 12 | 13 | A certifier has taken reasonable steps to verify the copyright status of this 14 | work. Certifier recognizes that his good faith efforts may not shield him from 15 | liability if in fact the work certified is not in the public domain. 16 | 17 | Dedicator makes this dedication for the benefit of the public at large and to 18 | the detriment of the Dedicator's heirs and successors. Dedicator intends this 19 | dedication to be an overt act of relinquishment in perpetuity of all present 20 | and future rights under copyright law, whether vested or contingent, in the 21 | Work. Dedicator understands that such relinquishment of all rights includes 22 | the relinquishment of all rights to enforce (by lawsuit or otherwise) those 23 | copyrights in the Work. 24 | 25 | Dedicator recognizes that, once placed in the public domain, the Work may be 26 | freely reproduced, distributed, transmitted, used, modified, built upon, or 27 | otherwise exploited by anyone for any purpose, commercial or non-commercial, 28 | and in any way, including by methods that have not yet been invented or 29 | conceived. -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/src/libb64/cdecode.c: -------------------------------------------------------------------------------- 1 | /* 2 | cdecoder.c - c source to a base64 decoding algorithm implementation 3 | 4 | This is part of the libb64 project, and has been placed in the public domain. 5 | For details, see http://sourceforge.net/projects/libb64 6 | */ 7 | 8 | #ifdef ESP8266 9 | #include 10 | #endif 11 | 12 | #if defined(ESP32) 13 | #define CORE_HAS_LIBB64 14 | #endif 15 | 16 | #ifndef CORE_HAS_LIBB64 17 | #include "cdecode_inc.h" 18 | 19 | int base64_decode_value(char value_in) 20 | { 21 | static const char decoding[] = {62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-2,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51}; 22 | static const char decoding_size = sizeof(decoding); 23 | value_in -= 43; 24 | if (value_in < 0 || value_in > decoding_size) return -1; 25 | return decoding[(int)value_in]; 26 | } 27 | 28 | void base64_init_decodestate(base64_decodestate* state_in) 29 | { 30 | state_in->step = step_a; 31 | state_in->plainchar = 0; 32 | } 33 | 34 | int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in) 35 | { 36 | const char* codechar = code_in; 37 | char* plainchar = plaintext_out; 38 | char fragment; 39 | 40 | *plainchar = state_in->plainchar; 41 | 42 | switch (state_in->step) 43 | { 44 | while (1) 45 | { 46 | case step_a: 47 | do { 48 | if (codechar == code_in+length_in) 49 | { 50 | state_in->step = step_a; 51 | state_in->plainchar = *plainchar; 52 | return plainchar - plaintext_out; 53 | } 54 | fragment = (char)base64_decode_value(*codechar++); 55 | } while (fragment < 0); 56 | *plainchar = (fragment & 0x03f) << 2; 57 | case step_b: 58 | do { 59 | if (codechar == code_in+length_in) 60 | { 61 | state_in->step = step_b; 62 | state_in->plainchar = *plainchar; 63 | return plainchar - plaintext_out; 64 | } 65 | fragment = (char)base64_decode_value(*codechar++); 66 | } while (fragment < 0); 67 | *plainchar++ |= (fragment & 0x030) >> 4; 68 | *plainchar = (fragment & 0x00f) << 4; 69 | case step_c: 70 | do { 71 | if (codechar == code_in+length_in) 72 | { 73 | state_in->step = step_c; 74 | state_in->plainchar = *plainchar; 75 | return plainchar - plaintext_out; 76 | } 77 | fragment = (char)base64_decode_value(*codechar++); 78 | } while (fragment < 0); 79 | *plainchar++ |= (fragment & 0x03c) >> 2; 80 | *plainchar = (fragment & 0x003) << 6; 81 | case step_d: 82 | do { 83 | if (codechar == code_in+length_in) 84 | { 85 | state_in->step = step_d; 86 | state_in->plainchar = *plainchar; 87 | return plainchar - plaintext_out; 88 | } 89 | fragment = (char)base64_decode_value(*codechar++); 90 | } while (fragment < 0); 91 | *plainchar++ |= (fragment & 0x03f); 92 | } 93 | } 94 | /* control should not reach here */ 95 | return plainchar - plaintext_out; 96 | } 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/src/libb64/cdecode_inc.h: -------------------------------------------------------------------------------- 1 | /* 2 | cdecode.h - c header for a base64 decoding algorithm 3 | 4 | This is part of the libb64 project, and has been placed in the public domain. 5 | For details, see http://sourceforge.net/projects/libb64 6 | */ 7 | 8 | #ifndef BASE64_CDECODE_H 9 | #define BASE64_CDECODE_H 10 | 11 | typedef enum 12 | { 13 | step_a, step_b, step_c, step_d 14 | } base64_decodestep; 15 | 16 | typedef struct 17 | { 18 | base64_decodestep step; 19 | char plainchar; 20 | } base64_decodestate; 21 | 22 | void base64_init_decodestate(base64_decodestate* state_in); 23 | 24 | int base64_decode_value(char value_in); 25 | 26 | int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in); 27 | 28 | #endif /* BASE64_CDECODE_H */ 29 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/src/libb64/cencode.c: -------------------------------------------------------------------------------- 1 | /* 2 | cencoder.c - c source to a base64 encoding algorithm implementation 3 | 4 | This is part of the libb64 project, and has been placed in the public domain. 5 | For details, see http://sourceforge.net/projects/libb64 6 | */ 7 | 8 | #ifdef ESP8266 9 | #include 10 | #endif 11 | 12 | #if defined(ESP32) 13 | #define CORE_HAS_LIBB64 14 | #endif 15 | 16 | #ifndef CORE_HAS_LIBB64 17 | #include "cencode_inc.h" 18 | 19 | const int CHARS_PER_LINE = 72; 20 | 21 | void base64_init_encodestate(base64_encodestate* state_in) 22 | { 23 | state_in->step = step_A; 24 | state_in->result = 0; 25 | state_in->stepcount = 0; 26 | } 27 | 28 | char base64_encode_value(char value_in) 29 | { 30 | static const char* encoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 31 | if (value_in > 63) return '='; 32 | return encoding[(int)value_in]; 33 | } 34 | 35 | int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in) 36 | { 37 | const char* plainchar = plaintext_in; 38 | const char* const plaintextend = plaintext_in + length_in; 39 | char* codechar = code_out; 40 | char result; 41 | char fragment; 42 | 43 | result = state_in->result; 44 | 45 | switch (state_in->step) 46 | { 47 | while (1) 48 | { 49 | case step_A: 50 | if (plainchar == plaintextend) 51 | { 52 | state_in->result = result; 53 | state_in->step = step_A; 54 | return codechar - code_out; 55 | } 56 | fragment = *plainchar++; 57 | result = (fragment & 0x0fc) >> 2; 58 | *codechar++ = base64_encode_value(result); 59 | result = (fragment & 0x003) << 4; 60 | case step_B: 61 | if (plainchar == plaintextend) 62 | { 63 | state_in->result = result; 64 | state_in->step = step_B; 65 | return codechar - code_out; 66 | } 67 | fragment = *plainchar++; 68 | result |= (fragment & 0x0f0) >> 4; 69 | *codechar++ = base64_encode_value(result); 70 | result = (fragment & 0x00f) << 2; 71 | case step_C: 72 | if (plainchar == plaintextend) 73 | { 74 | state_in->result = result; 75 | state_in->step = step_C; 76 | return codechar - code_out; 77 | } 78 | fragment = *plainchar++; 79 | result |= (fragment & 0x0c0) >> 6; 80 | *codechar++ = base64_encode_value(result); 81 | result = (fragment & 0x03f) >> 0; 82 | *codechar++ = base64_encode_value(result); 83 | 84 | ++(state_in->stepcount); 85 | if (state_in->stepcount == CHARS_PER_LINE/4) 86 | { 87 | *codechar++ = '\n'; 88 | state_in->stepcount = 0; 89 | } 90 | } 91 | } 92 | /* control should not reach here */ 93 | return codechar - code_out; 94 | } 95 | 96 | int base64_encode_blockend(char* code_out, base64_encodestate* state_in) 97 | { 98 | char* codechar = code_out; 99 | 100 | switch (state_in->step) 101 | { 102 | case step_B: 103 | *codechar++ = base64_encode_value(state_in->result); 104 | *codechar++ = '='; 105 | *codechar++ = '='; 106 | break; 107 | case step_C: 108 | *codechar++ = base64_encode_value(state_in->result); 109 | *codechar++ = '='; 110 | break; 111 | case step_A: 112 | break; 113 | } 114 | *codechar++ = 0x00; 115 | 116 | return codechar - code_out; 117 | } 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/src/libb64/cencode_inc.h: -------------------------------------------------------------------------------- 1 | /* 2 | cencode.h - c header for a base64 encoding algorithm 3 | 4 | This is part of the libb64 project, and has been placed in the public domain. 5 | For details, see http://sourceforge.net/projects/libb64 6 | */ 7 | 8 | #ifndef BASE64_CENCODE_H 9 | #define BASE64_CENCODE_H 10 | 11 | typedef enum 12 | { 13 | step_A, step_B, step_C 14 | } base64_encodestep; 15 | 16 | typedef struct 17 | { 18 | base64_encodestep step; 19 | char result; 20 | int stepcount; 21 | } base64_encodestate; 22 | 23 | void base64_init_encodestate(base64_encodestate* state_in); 24 | 25 | char base64_encode_value(char value_in); 26 | 27 | int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in); 28 | 29 | int base64_encode_blockend(char* code_out, base64_encodestate* state_in); 30 | 31 | #endif /* BASE64_CENCODE_H */ 32 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/src/libsha1/libsha1.h: -------------------------------------------------------------------------------- 1 | /* ================ sha1.h ================ */ 2 | /* 3 | SHA-1 in C 4 | By Steve Reid 5 | 100% Public Domain 6 | */ 7 | 8 | #if !defined(ESP8266) && !defined(ESP32) 9 | 10 | typedef struct { 11 | uint32_t state[5]; 12 | uint32_t count[2]; 13 | unsigned char buffer[64]; 14 | } SHA1_CTX; 15 | 16 | void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]); 17 | void SHA1Init(SHA1_CTX* context); 18 | void SHA1Update(SHA1_CTX* context, const unsigned char* data, uint32_t len); 19 | void SHA1Final(unsigned char digest[20], SHA1_CTX* context); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/tests/webSocket.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 40 | 41 | 42 | 43 | LED Control:
44 |
45 | R:
46 | G:
47 | B:
48 | 49 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/tests/webSocketServer/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | var WebSocketServer = require('websocket').server; 3 | var http = require('http'); 4 | 5 | var server = http.createServer(function(request, response) { 6 | console.log((new Date()) + ' Received request for ' + request.url); 7 | response.writeHead(404); 8 | response.end(); 9 | }); 10 | server.listen(8011, function() { 11 | console.log((new Date()) + ' Server is listening on port 8011'); 12 | }); 13 | 14 | wsServer = new WebSocketServer({ 15 | httpServer: server, 16 | // You should not use autoAcceptConnections for production 17 | // applications, as it defeats all standard cross-origin protection 18 | // facilities built into the protocol and the browser. You should 19 | // *always* verify the connection's origin and decide whether or not 20 | // to accept it. 21 | autoAcceptConnections: false 22 | }); 23 | 24 | function originIsAllowed(origin) { 25 | // put logic here to detect whether the specified origin is allowed. 26 | return true; 27 | } 28 | 29 | wsServer.on('request', function(request) { 30 | 31 | if (!originIsAllowed(request.origin)) { 32 | // Make sure we only accept requests from an allowed origin 33 | request.reject(); 34 | console.log((new Date()) + ' Connection from origin ' + request.origin + ' rejected.'); 35 | return; 36 | } 37 | 38 | var connection = request.accept('arduino', request.origin); 39 | console.log((new Date()) + ' Connection accepted.'); 40 | 41 | connection.on('message', function(message) { 42 | if (message.type === 'utf8') { 43 | console.log('Received Message: ' + message.utf8Data); 44 | // connection.sendUTF(message.utf8Data); 45 | } 46 | else if (message.type === 'binary') { 47 | console.log('Received Binary Message of ' + message.binaryData.length + ' bytes'); 48 | //connection.sendBytes(message.binaryData); 49 | } 50 | }); 51 | 52 | connection.on('close', function(reasonCode, description) { 53 | console.log((new Date()) + ' Peer ' + connection.remoteAddress + ' disconnected.'); 54 | }); 55 | 56 | connection.sendUTF("Hallo Client!"); 57 | }); 58 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/tests/webSocketServer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webSocketServer", 3 | "version": "1.0.0", 4 | "description": "WebSocketServer for testing", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/Links2004/arduinoWebSockets" 12 | }, 13 | "keywords": [ 14 | "esp8266", 15 | "websocket", 16 | "arduino" 17 | ], 18 | "author": "Markus Sattler", 19 | "license": "LGPLv2", 20 | "bugs": { 21 | "url": "https://github.com/Links2004/arduinoWebSockets/issues" 22 | }, 23 | "homepage": "https://github.com/Links2004/arduinoWebSockets", 24 | "dependencies": { 25 | "websocket": "^1.0.18" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /libraries/arduinoWebSockets/travis/common.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function build_sketches() 4 | { 5 | local arduino=$1 6 | local srcpath=$2 7 | local platform=$3 8 | local sketches=$(find $srcpath -name *.ino) 9 | for sketch in $sketches; do 10 | local sketchdir=$(dirname $sketch) 11 | if [[ -f "$sketchdir/.$platform.skip" ]]; then 12 | echo -e "\n\n ------------ Skipping $sketch ------------ \n\n"; 13 | continue 14 | fi 15 | echo -e "\n\n ------------ Building $sketch ------------ \n\n"; 16 | $arduino --verify $sketch; 17 | local result=$? 18 | if [ $result -ne 0 ]; then 19 | echo "Build failed ($sketch) build verbose..." 20 | $arduino --verify --verbose --preserve-temp-files $sketch 21 | result=$? 22 | fi 23 | if [ $result -ne 0 ]; then 24 | echo "Build failed ($1) $sketch" 25 | return $result 26 | fi 27 | done 28 | } 29 | 30 | 31 | function get_core() 32 | { 33 | echo Setup core for $1 34 | 35 | cd $HOME/arduino_ide/hardware 36 | 37 | if [ "$1" = "esp8266" ] ; then 38 | mkdir esp8266com 39 | cd esp8266com 40 | git clone https://github.com/esp8266/Arduino.git esp8266 41 | cd esp8266/tools 42 | python get.py 43 | fi 44 | 45 | if [ "$1" = "esp32" ] ; then 46 | mkdir espressif 47 | cd espressif 48 | git clone https://github.com/espressif/arduino-esp32.git esp32 49 | cd esp32/tools 50 | python get.py 51 | fi 52 | 53 | } 54 | --------------------------------------------------------------------------------