Dominik Feiler
Published © GPL3+

Chromebook Enrollment

For work every now and then I have to enroll up to 200 Chromebooks/Chromebits/Chromeboxes, so I wrote a script that does just that.

BeginnerWork in progress6 minutes2,989
Chromebook Enrollment

Things used in this project

Story

Read more

Schematics

Mandatory Fritzing sketch

Take your Particle and plug it into the Chromebook via USB.
Sorry, Fritzing didn't have 'USB-Cable' or 'Chromebook' in the parts list

Code

ChromebookEnrollment

Arduino
Main file with the 3 steps of Enrollment
I created some convenience-functions like up, down, tab, enter in the KeyboardDuckie Library
// This #include statement was automatically added by the Particle IDE.
#include "KeyboardDuckie.h"


STARTUP(Keyboard.begin());
SYSTEM_MODE(SEMI_AUTOMATIC);


bool runChromebookStep0 = false;
bool runChromebookStep1 = true;
bool runChromebookStep2 = true;
bool runChromebookStep3 = true;

void Chrome_0_Chromebit_Setup(){
    delay_medium();
    tab();
    enter();
    tab();
}

void Chrome_1_WifiSetup(){
    
    delay_medium();
    
    tab(2);
    enter();
    delay_tiny();
    
    // Up 2 for Chromebooks & Chromebits
    up(2);
    
    // Up 3 for Chromeboxes because of Ethernet
    //up(3);
    delay_tiny();
    enter();
    delay_tiny();
    fastWrite("YOURSSID");
    tab();
    // Down 2 for WPA2
    down(2);
    tab();
    fastWrite("YOURWIFIPASSWORD");

    enter();
    
    // Delay(5000) for Chromebooks and Chromeboxes
    delay(5000);
    // Delay(10000) for Chromebits
    //delay(10000);
    
    tab();
    enter();
    
    runChromebookStep1 = false;
}

void Chrome_2_FirstSetup(){
    delay_short();
    enter();
    // Delay(5000) for Chromebooks and Chromeboxes
    delay(5000);
    // Delay(15 000) for Chromebits
    //delay(15000);
    runChromebookStep2 = false;
}

void Chrome_3_Enrollment(){
    delay_long();
    
    Keyboard.press(KEY_LEFTALT);
    Keyboard.press(KEY_LEFTCTRL);
    delay_tiny();
    Keyboard.press(KEY_E);
    
    Keyboard.releaseAll();
    
    //Keyboard.click(KEY_E, MOD_LEFTALT | MOD_LEFTCTRL);
    delay_long();
    //
    // Enrollment User EMail
    //
    fastWrite("USERNAME");
    
    //somehow I had problems just writing the @ so I used this workaround
    Keyboard.press(KEY_LEFTSHIFT);
    delay_tiny();
    Keyboard.press(KEY_2);
    Keyboard.releaseAll();
    fastWrite("DOMAIN");
    enter();
    delay_long();
    //
    // Enrollment User Password
    //
    fastWrite("YOURPASSWORD");
    //tab(2);
    enter();
    runChromebookStep3 = false;
}

// Stop the process when you press the System-button and
// try to connect to the cloud
void button_handler(system_event_t event, int duration, void* )
{
    if (!duration) { // just pressed
        RGB.control(true);
        RGB.color(255, 0, 0);
        runChromebookStep1 = false;
        runChromebookStep2 = false;
        runChromebookStep3 = false;
        Particle.connect();
        delay(1000);
        RGB.control(false);// MAGENTA
    }
        
}

///
//
//
// Finally - Run all the Stuff!
//
//
///

void setup() {
    
    System.on(button_status, button_handler);
    
    LedSetup();
    LedToggle();
}

void loop(){
    
    if(runChromebookStep0){
        Chrome_0_Chromebit_Setup();
    }
    if(runChromebookStep1){
        Chrome_1_WifiSetup();
    }
    if(runChromebookStep2){
        Chrome_2_FirstSetup();
    }
    if(runChromebookStep3){
        Chrome_3_Enrollment();      
    }
    
    //done with enrollment
    delay(100);
    LedToggle();
}

KeyboardDuckie.cpp

Arduino
KeyboardDuckie 'Library' with some convenience-functions
#include "application.h"
#include "KeyboardDuckie.h"

int microdelay = 20;
int tinydelay = 100;
int shortdelay = 500;
int mediumdelay = 1000;
int longdelay = 2000;

void delay_micro(){
    delay(microdelay);
}

void delay_tiny(){
    delay(tinydelay);
}

void delay_short(){
    delay(shortdelay);
}

void delay_medium(){
    delay(mediumdelay);
}

void delay_long(){
    delay(longdelay);
}


void LedSetup(){
    pinMode(D7, OUTPUT);
}

bool led = true;

void LedToggle(){
    if(led == true){
        digitalWrite(D7, HIGH);
    }else{
        digitalWrite(D7, LOW);
    }
    led = !led;
}


void fastWrite(String text){
    Keyboard.releaseAll();
    for (unsigned int i = 0; i < strlen(text); i++) {
        Keyboard.write(text.charAt(i));
        //delay_tiny();
        LedToggle();
    }
}

void tab(){
    tab(1);
}

void tab(int count){
    while( count > 0){
        delay_tiny();
        Keyboard.click(KEY_TAB);
        count --;
        LedToggle();
    }
    delay(shortdelay);
}

void down(){
    down(1);
}

void down(int count){
    while( count > 0){
        delay_tiny();
        Keyboard.click(KEY_DOWN);
        count --;
        LedToggle();
    }
}

void up(){
    up(1);
}

void up(int count){
    while( count > 0){
        delay_tiny();
        Keyboard.click(KEY_UP);
        count --;
        LedToggle();
    }
}



void enter(){
    enter(1);
}

void enter(int count){
    while( count > 0){
        delay_short();
        Keyboard.click(KEY_ENTER);
        count --;
        LedToggle();
    }
    delay_short();
}

void shifttab(){
    shifttab(1);
}

void shifttab(int count){
    while( count > 0){
        delay_short();
        Keyboard.click(KEY_TAB, MOD_LEFTSHIFT);
        count --;
        LedToggle();
    }
    delay_short();
}

KeyboardDuckie.h

Arduino
Header-File for the KeyboardDuckie Lib
void LedSetup(void);
void LedToggle(void);

void fastWrite(String);

void delay_tiny(void);

void delay_short(void);

void delay_medium(void);

void delay_long(void);

void tab(int);
void tab(void);

void shifttab(int);
void shifttab(void);

void up(void);
void up(int);

void down(void);
void down(int);

void enter(int);
void enter(void);

Credits

Dominik Feiler

Dominik Feiler

1 project • 2 followers

Comments