Jen Looper
Published © GPL3+

Create a kid-summoner with Spark Core

Make your spark core send a tweet to your kids when it's time for lunch!

IntermediateFull instructions provided1,669
Create a kid-summoner with Spark Core

Things used in this project

Hardware components

Spark Core
Particle Spark Core
$39
×1
Arduino Sidekick Basic Kit
For male-to-male cables, a button, and a resistor. You can buy this kit for $34.99 at Radio Shack, and is a useful kit to have on hand.
×1

Software apps and online services

Twitter
Twitter

Story

Read more

Schematics

Diagram

Wiring diagram
Unnamed

Code

file_8967.txt

C/C++
kid-summoner.ino
/*
  kid-summoner.ino
 
    On pressing a button, a tweet is sent via Pushingbox
    Written for the Spark Core
*/

int inputPin = D1; //push-button pin
int val = 0; //variable for push-button status
int state = 1; //variable for on/off state

const char * DEVID = the-devid-created-in-pushingbox";         // Scenario: "Tweet"
const char * serverName = "[api.pushingbox.com](http://api.pushingbox.com)";   // Pushingbox API URL

TCPClient client;

void setup() {
   
    pinMode(inputPin, INPUT);
    Serial.begin(9600);
}


void loop() {
    val = digitalRead(inputPin); //read the state of the push-button
   
    if (val == LOW) { //if push-button pressed
        state = !state; //reverse on/off state
        delay(250); //primitive button debounce
        Serial.println("button pushed!");
        sendToPushingBox(DEVID);
       
    }
}

void sendToPushingBox(const char * devid)
{
    client.stop();
    if (client.connect(serverName, 80)) {
        client.print("GET /pushingbox?devid=");
        client.print(devid);
        client.println(" HTTP/1.1");
        client.print("Host: ");
        client.println(serverName);
        client.println("User-Agent: Spark");
        client.println();
        client.flush();
       
    }
    else{
        Serial.println("connection failed");
    }
} 

Credits

Jen Looper

Jen Looper

10 projects • 36 followers
Founder: http://t.co/DOXReolRYV, indie web and mobile developer, Developer Relations team member at Telerik. Queen of the Apps!

Comments