Time to go

Made by yifeiy1

Found in Home Hack

Evan lives right next to a bus stop that has 4 buses that get him around to different places. The convenience of location makes him too comfortable and never plan ahead and often left out missing a bus and have to wait another 10 or more minutes. Thus, he really needs a real-time bus tracker that plans his trips and gives him visual/sound cue about the real-time status of the bus so if the bus is a bit delayed/ahead of schedule so when he needs to go NOW, Evan will be able to know.

0

Context

Evan Xiao is a student at Tepper school of business. He lives right next to a bus stop that has 4 buses that get him around to different places. This location is too convenient for transportation which often makes him too comfortable and never plan head and often left out missing a bus and have to wait another 10 or more minutes. This was not just his problem, it was also the problem that all five people living in that house was facing. But it was particular his problem since he often stays in the living room and gets involved in his things while not noticing that he needs to leave now.

0

Intention

A real-time bus gazer that roughly knows when he needs to get out and plans him according that he need to get on a bus that arrives in 5 minutes or he will need to wait a lot longer. It also gives him visual/sound cue about the real-time status of the bus so if the bus is a bit delayed/ahead of schedule, Evan will be able know.

0

Product

A real-time bus-gazer that helps bus riders in Pittsburgh to schedule their next trip.

- Bill of parts:

1 PIR Sensor

1 NeoPixel light strip

1 Push Button

Several Jumper Wires

Photon

0
TIGO: IoT Home Hack
Yifei Yin - https://vimeo.com/202230450
0

Process

1. Get the API

2. Get Python to talk to the API

-- Using the Requests package

-- Use list to store data

3. Get Python to talk to Particle

-- requests.post("", data={})

4. Get Particle to talk to people

-- Tried to use the Adafruit LED Matrix first to receive the best result

-- Failed

-- Compromised to use the Neopixel LED Stripe

-- Worked

The best display would be the LED Matrix, but since it really did not work, I have to compromise to use the Neopixel LED Stripe.

5. Get Particle to know whenever Evan leaves

Using a PIR sensor.

0
#include "application.h"
#include "neopixel/neopixel.h"
//#include "Adafruit_GFX/Adafruit_GFX.h"
//#include "adafruit-led-backpack.h"

/*#ifndef _BV
  #define _BV(bit) (1<<(bit))
#endif*/


 SYSTEM_MODE(AUTOMATIC);

 // IMPORTANT: Set pixel COUNT, PIN and TYPE
 #define PIXEL_PIN D6
 #define PIXEL_COUNT 16
 #define PIXEL_TYPE WS2812B



//Adafruit_8x8matrix matrix = Adafruit_8x8matrix();
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

int bus(String command);
int buildin= D7;
int command_int;
int pushButton = D2;
int pirSensor = D4;
bool flag = false;
int i = 0;

 // Prototypes for local build, ok to leave in for Build IDE
 void rainbow(uint8_t wait);
 uint32_t Wheel(byte WheelPos);
/*
 static const uint8_t  smile_bmp[] =
   { 0B00111100,
     0B01000010,
     0B10100101,
     0B10000001,
     0B10100101,
     0B10011001,
     0B01000010,
     0B00111100 };
 static const uint8_t  neutral_bmp[] =
   { 0B00111100,
     0B01000010,
     0B10100101,
     0B10000001,
     0B10111101,
     0B10000001,
     0B01000010,
     0B00111100 };
 static const uint8_t  frown_bmp[] =
   { 0B00111100,
     0B01000010,
     0B10100101,
     0B10000001,
     0B10011001,
     0B10100101,
     0B01000010,
     0B00111100 };
 static const uint8_t  cloud_bmp[] =
   { 0B00000000,
     0B00000000,
     0B00110100,
     0B01111110,
     0B11111111,
     0B11111111,
     0B00000000,
     0B00000000 };

 uint8_t counter = 0;

 int issPassingOver(String command);
 int passing = 0;

 // This function is executed when the IFTTT receipe calls it
 int issPassingOver(String command)
 {
     if(command == "iss")
     {
      passing = 1;
      return 1;
     }
     else return -1;
 }
*/

 void setup()
 {
   Serial.begin(9600);
   Particle.function("brew", bus);
   Particle.function("brew2", bus2);
   pinMode(buildin, OUTPUT);
   pinMode(pushButton, INPUT_PULLUP);
   pinMode(pirSensor, INPUT);
   strip.begin();
   strip.show(); // Initialize all pixels to 'off'
   //matrix.begin(0x70);  // pass in the address
   //Spark.function("iss",issPassingOver);
 }



 void loop()
 {
   //matrix.clear();
   //matrix.setRotation(0);

   // Play the scrolling cloud animation
   /*for (int8_t x=20; x>=-20; x--) {
           matrix.clear();
           matrix.drawBitmap(x, 0, cloud_bmp, 8, 8, LED_ON);
           matrix.writeDisplay();
           delay(100);
       }*/

 }

 // this function automagically gets called upon a matching POST request
 int bus(String command)
 {
   int pushButtonState;

   pushButtonState = digitalRead(pushButton);

   int pirSensorState;

   pirSensorState = digitalRead(pirSensor);

   if(pushButtonState == LOW){ // If we push down on the push button
     flag = true;
   }
   if (flag == true){
     if(pirSensorState == LOW){
       i++;
       if (i>1000){
         flag = false;
         return -1;
       }
     }
     else{
       Serial.println("motion detected!");
     }
   }
   Serial.println(flag);


   if (flag == true){
     command_int = atoi(command);

     Serial.println(command_int);

     if (command_int < 2)  {//RED -- DON'T GO
     colorTwoWipe1(strip.Color(1, 0, 0), 50);
     strip.show();
       if (command_int > 0 ){
         return 1;
       }
       else{
         return -10;
       }
     }
     else if (command_int < 3){//Orange
       colorTwoWipe1(strip.Color(4, 1, 0), 50);
       strip.show();
       return 2;
       Particle.publish("test", "Get ready.");

     }
     else if (command_int < 4) {//yellow
       colorTwoWipe1(strip.Color(2, 1, 0), 50);
       strip.show();
       return 3;
     }
     else if (command_int < 5) {//Green
       colorTwoWipe1(strip.Color(0, 1, 0), 50);
       strip.show();
       Particle.publish("alert", "2");
       return 4;

     }
     if (command_int >= 5){//Blue
       colorTwoWipe1(strip.Color(0, 1, 1),50);
       strip.show();
       return 5;
       
     }
     else return -10;
   }
   else
   {
     return -20;
   }
   delay(500);
 }

 // this function automagically gets called upon a matching POST request
 int bus2(String command)
 {
   int pushButtonState;

   pushButtonState = digitalRead(pushButton);

   int pirSensorState;

   pirSensorState = digitalRead(pirSensor);

   if(pushButtonState == LOW){ // If we push down on the push button
     flag = true;
   }
   if (flag == true){
     if(pirSensorState == LOW){
       i++;
       if (i>1000){
         flag = false;
         return -1;
       }
     }
     else{
       Serial.println("motion detected!");
     }
   }
   Serial.println(flag);


   if (flag == true){
     command_int = atoi(command);

     Serial.println(command_int);

     if (command_int < 2)  {//RED -- DON'T GO
     colorTwoWipe2(strip.Color(1, 0, 0), 50);
     strip.show();
       if (command_int > 0 ){
         return 1;
       }
       else{
         return -10;
       }
     }
     else if (command_int < 3){//Orange
       colorTwoWipe2(strip.Color(4, 1, 0), 50);
       strip.show();
       return 2;
     }
     else if (command_int < 4) {//yellow
       colorTwoWipe2(strip.Color(2, 1, 0), 50);
       strip.show();
       return 3;
     }
     else if (command_int < 5) {//Green
       colorTwoWipe2(strip.Color(0, 1, 0), 50);
       strip.show();
       return 4;
     }
     if (command_int < 10){//Blue
       colorTwoWipe2(strip.Color(0, 1, 1),50);
       strip.show();
       return 5;
       Particle.publish("test", "this is a test message from particle");
     }
     if (command_int >= 10){//Blue
       colorTwoWipe2(strip.Color(0, 0, 1),50);
       strip.show();
       return 6;
       Particle.publish("test", "this is a test message from particle");
     }
     else return -10;
   }
   else
   {
     return -20;
   }
   delay(500);
 }



 // Fill the dots one after the other with a color, wait (ms) after each one
 void colorWipe(uint32_t c, uint8_t wait) {
   for(uint16_t i=0; i<strip.numPixels(); i++) {
     strip.setPixelColor(i, c);
     strip.show();
     delay(wait);
   }
 }

 void colorTwoWipe (uint32_t c, uint32_t d, uint8_t wait){
   for(uint16_t i=0; i<8; i++) {
     strip.setPixelColor(i, c);
     strip.show();
     delay(wait);
   }
   for(uint16_t i=8; i<strip.numPixels(); i++) {
     strip.setPixelColor(i, d);
     strip.show();
     delay(wait);
   }
 }


 void colorTwoWipe1 (uint32_t c, uint8_t wait){
   for(uint16_t i=0; i<11; i++) {
     strip.setPixelColor(i, c);
     strip.show();
     delay(wait);
   }
 }

 void colorTwoWipe2 (uint32_t d, uint8_t wait){
   for(uint16_t i=11; i<strip.numPixels(); i++) {
     strip.setPixelColor(i, d);
     strip.show();
     delay(wait);
   }

 }

 void rainbow(uint8_t wait) {
   uint16_t i, j;

   for(j=0; j<256; j++) {
     for(i=0; i<strip.numPixels(); i++) {
       strip.setPixelColor(i, Wheel((i+j) & 255));
     }
     strip.show();
     delay(wait);
   }
 }

 // Input a value 0 to 255 to get a color value.
 // The colours are a transition r - g - b - back to r.
 uint32_t Wheel(byte WheelPos) {
   if(WheelPos < 85) {
    return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
   } else if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
   } else {
    WheelPos -= 170;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
   }
 }
Click to Expand
0
#import dependencies

import requests
import datetime
from xml.dom import minidom

b = 0
i = 0

while (b!= -1):
    realtime= str(datetime.datetime.now()).split()[1][0:5]
    realtime_split = realtime.split(':')
    realtime_hour = int(realtime_split[0])
    realtime_min = int(realtime_split[1])

    time = realtime_hour*60+realtime_min

    g = requests.get("http://truetime.portauthority.org/bustime/api/v1/getpredictions?key=VFkqS4yiFyqxAfdgvsrnQ783F&stpid=7097")


    with open("Output.txt", "w") as text_file:
        print(g.text, file=text_file)

    xmldoc = minidom.parse("Output.txt")
    itemlist = xmldoc.getElementsByTagName('prdtm')

    timeDif =[]

    for s in itemlist:
        bustime_split = s.firstChild.nodeValue.split()[1].split(':')
        bustime = int(bustime_split[0])*60 +int(bustime_split[1])
        timeDif.append(int(bustime-time))


    r = requests.post("https://api.particle.io/v1/devices/22002b001351353432393433/brew", data={'access_token': 'ada24d2045a440d9f975c0861224febe6b414065', 'args': timeDif[0]})
    r = requests.post("https://api.particle.io/v1/devices/22002b001351353432393433/brew2", data={'access_token': 'ada24d2045a440d9f975c0861224febe6b414065', 'args': timeDif[1]})

    print(r.status_code, r.reason)
    print(r.text)
    a=r.text.split(',')
    b=a[3].split(':')[1]
    b=b[:-1]
    b= int(b)
    i=i+1
    print(i)

print('request stopped')
Click to Expand
0

Reflection

Particle is pretty different from Arduino.

x
Share this Project

Found In
Courses

49-713 Designing for the Internet of Things

· 26 members

A hands-on introductory course exploring the Internet of Things and connected product experiences.


About

Evan lives right next to a bus stop that has 4 buses that get him around to different places. The convenience of location makes him too comfortable and never plan ahead and often left out missing a bus and have to wait another 10 or more minutes. Thus, he really needs a real-time bus tracker that plans his trips and gives him visual/sound cue about the real-time status of the bus so if the bus is a bit delayed/ahead of schedule so when he needs to go NOW, Evan will be able to know.

Created

January 26th, 2017