2016年1月19日 星期二

物聯網排隊掛號機



這是一個物聯網排隊掛號機,當初在參加黑客松之前想出來的

起因是和財政部長在逛夜市的時候,想吃某一個排隊名店

But... 人多到漫出來啦!

所以當時就在想大家都有手機,等號碼快到的時候就推撥到手機叫你來領食物就好啦~

當時是用arduino yun做的,現在可以改為ESP8266
這樣加電源與Cloud的成本應該不用5USD,是不是比紙印掛號機的便宜呀?

要不要叫醫院也跟進一下??

好了!廢話不多說,而且這支code應該有半年了,我都快看不懂了
以下是arduino yuncode
#include <Parse.h>
#include <Bridge.h>
#include <Process.h>

// Constants
const char *PARSE_API = "api.parse.com";
const char *PARSE_APP = "你的parse app";
//const char *PARSE_CLASS = "TestObject";
const char *PARSE_KEY = "你的parse key";
const char *PARSE_VERSION = "1";
// Counter
int counter = 0;
//以下是寫七段顯示器,總是要讓現場等待的客人知道現在是幾號嘛!
byte seven_seg_digits[10][7] = { { 1,1,1,1,1,1,0 },  // = 0
                                 { 0,1,1,0,0,0,0 },  // = 1
                                 { 1,1,0,1,1,0,1 },  // = 2
                                 { 1,1,1,1,0,0,1 },  // = 3
                                 { 0,1,1,0,0,1,1 },  // = 4
                                 { 1,0,1,1,0,1,1 },  // = 5
                                 { 1,0,1,1,1,1,1 },  // = 6
                                 { 1,1,1,0,0,0,0 },  // = 7
                                 { 1,1,1,1,1,1,1 },  // = 8
                                 { 1,1,1,0,0,1,1 }   // = 9
                             };


ParseClient client;
// Leverage Yun Linux (curl)
Process process;

// Buffer for parameters
char buffer[80];

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 10;     // the number of the pushbutton pin
//const int ledPin =  13;      // the number of the LED pin


// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

int button_counter = 0;

void setup() {
  // put your setup code here, to run once:
// Initialize digital pin 13 as an output.
pinMode(13, OUTPUT);

// Initialize Bridge
Bridge.begin();

  // Console debugging
  // Wait for console
  #ifdef DEBUG
    Console.begin(); 
    while( !Console ) {;}
  #endif

  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);

// Initialize Serial
Serial.begin(9600);

  pinMode(2, OUTPUT); 
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  digitalWrite(9, 0);  // 關閉小數點


while (!Serial); // wait for a serial connection
Serial.println("Parse Starter Project");

// Initialize Parse
client.begin("Y5D6DVdimngH59TYabxYnsky1XKa0kfObQfZWL4T", "GazxeE62ICn4zGybUa6mXILqId8eGxZPkkbSJ2z6");


ParseObjectCreate create;
create.setClassName("TestObject");
create.add("foo", "bar");
ParseResponse response = create.send();

Serial.println("\nResponse for saving a TestObject:");
Serial.print(response.getJSONBody());
if (!response.getErrorCode()) {
   String objectId = response.getString("objectId");
   Serial.print("Test object id:");
   Serial.println(objectId);
} else {
   Serial.println("Failed to save the object");
}
response.close(); // Do not forget to free the resource

// Start push service
Parse.startPushService();
Serial.print("Push Installation ID:");
Serial.println(Parse.getInstallationId());

}

// 在七段顯示器上顯示指定的一個數字
void sevenSegWrite(byte digit) {
  byte pin = 2;
  for (byte seg = 0; seg < 7; ++seg) {
    digitalWrite(pin, seven_seg_digits[digit][seg]);
    ++pin;
  }
}

void loop() {
  buttonState = digitalRead(buttonPin);


  if (buttonState == HIGH) {
    digitalWrite(13, HIGH); // turn on LED
    button_counter++;
    Serial.println(button_counter);
      switch(button_counter) {
case 9:
    sevenSegWrite(button_counter);
    button_counter = 0 ;
    break;
default:
    sevenSegWrite(button_counter);
    break;
}

counter++;

ParseObjectUpdate update;
update.setClassName("line_up"); //parse上設定的類別名稱
update.setObjectId("SiaCCpzTCN");
update.add("number", counter);
update.send();
Serial.println(counter);
  if (counter == 9) {counter = 0;}

  }
  else {
    // turn LED off:
    digitalWrite(13, LOW);
  } 
}


// Send the data to Parse.com
void request( int value )
{
  // Curl request per Parse.com documentation
  /*
  curl -X POST \
  -H "X-Parse-Application-Id: APPLICATION_ID" \
  -H "X-Parse-REST-API-Key: REST_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"reading":123}' \
  https://api.parse.com/1/classes/Temperature 
  */ 

  // Build curl command line
  // Includes HTTPS support
  // POST
  // JSON
  process.begin( "curl" );
  process.addParameter( "-k" );
  process.addParameter( "-X" );
  process.addParameter( "POST" );
  process.addParameter( "-H" );
  process.addParameter( "Content-Type:application/json" );

  // Parse.com application
  process.addParameter( "-H" );
  sprintf( buffer, "X-Parse-Application-Id: %s", PARSE_APP );
  process.addParameter( buffer );
 
  // Parse.com key
  process.addParameter( "-H" );
  sprintf( buffer, "X-Parse-REST-API-Key: %s", PARSE_KEY );
  process.addParameter( buffer ); 

  // JSON body
  process.addParameter( "-d" );
  sprintf( buffer, "{\"channels\" : [\"arduino\"], \"data\" : {\"alert\" : \"test\"} }");
  process.addParameter( buffer );

  // URI
  sprintf( buffer, "https://%s/%s/push", PARSE_API, PARSE_VERSION );
  process.addParameter( buffer ); 

  // Run the command
  // Synchronous
  process.run();
 
        Serial.println("now creat");
}

Androidcode方面,下載parsetutorialcode來修改就行了

之前寫的很亂,最近有時間再整理一下,暫時不放上來丟人現眼了


沒有留言:

張貼留言

FB設定搶先看的方式

設定搶先看的兩種方式 A1. 先到我家的日常粉絲團按下 …( 紅框處 ) A2. 按下追蹤中 ( 紅框處 ) A3. 按下搶先看 ( 紅框處 ) A4. 完成!!! 另一種方式 ...