Hardware components | ||||||
| × | 1 | ||||
Software apps and online services | ||||||
|
Natuurlijk heb je het al eens meegemaakt: je staat 10 à 20 minuten te wachten voor een paskamer en als je jouw favoriete blauwe broek hebt gepast, blijkt dat je een andere maat nodig hebt. Je moet je weer aankleden, het andere kledingstuk halen en daar gaan we weer… opnieuw een lange tijd wachten voor een paskamer om die ene broek te passen.
De shoppingliefhebbers willen zeker op een efficiëntere manier shoppen en liefst zonder lange wachttijden natuurlijk! The Smart Store biedt de beste oplossing!
Via sensoren wordt gemeten hoeveel de wachttijd aan de paskamers bedraagt. Deze wachttijd kan je dan raadplegen op je smartphone en wordt ook in de winkel op een scherm getoond. Zo kan je op je gemak verder shoppen zonder aan de lange rij aan de paskamers te denken, je houdt enkel je smartphone in het oog. Het is ook mogelijk een paskamer te reserveren. Wanneer de paskamer vrij is, krijg je netjes een berichtje op je smartphone.
In die lange, saaie wachtrijen staan is vanaf nu verleden tijd! De Smart Store is efficiënt voor de klant én voor het personeel.Vooral de tevredenheid van de klanten zal er dankzij dit systeem op vooruitgaan. Zij kunnen nu nóg meer winkels bezoeken dankzij de kortere wachttijden!
smartstore.ino
Arduino/*
Author: students JOMA secundair Merksem and K. Kuypers
Contact: kathleen.kuypers@gmail.com or kkuypers@jomasecundair.be
This Sketch is made for an Genuino 101 IoT board with a Grove
UART WiFi module based on the popular ESP8266 IoT SoC to communicate to the AllThingsTalk
IoT developer cloud.
The Grove UART WiFi module has firmware installed which includes the ATT_IOT library. It
communicates through Serial1 of the Genuino 101 board.
Version 1.0 dd 16_03_2016
### Instructions
1. Setup the Arduino hardware
- Use an Arduino Genuino 101 IoT board
- Connect the Arduino Grove shield
- Connect USB cable to your computer
- Connect a Grove LED to pin D2 of the Arduino shield RODE LED
- Connect a Grove LED to pin D3 of the Arduino shield GROENE LED
- Connect a Grove Ultrasonic ranger to pin D7 of the Arduino shield
- There will be a virtual asset of type string on virtual port 9
- Grove UART wifi to pin UART (D0,D1)
2. Add 'ATT_IOT_UART' library to your Arduino Environment
More info can be found at http://arduino.cc/en/Guide/Libraries
3. Fill in the missing strings (deviceId, clientId and clientKey) in the keys.h file
4. Optionally, change sensor names, labels as appropiate
5. Upload the sketch
*/
#include "ATT_IOT_UART.h" // AllThingsTalk Arduino UART IoT library
#include <SPI.h> // Required to have support for signed/unsigned long type
#include "keys.h" // Keep all your personal account information in a seperate file
#include "Ultrasonic.h"
ATTDevice Device(&Serial1);
char httpServer[] = "api.smartliving.io"; // HTTP API Server host
char mqttServer[] = "broker.smartliving.io"; // MQTT Server Address
//****************************************************************
//** PIN numbers and other constants
//****************************************************************
#define redledId 2 // Digital actuator is connected to pin D2 on grove shield
#define greenledId 3 // Digital actuator is connected to pin D6 on grove shield
#define distanceId 7 // Digital sensor is connected to pin D7 on grove shield
#define subscribeId 9 // Textbox in smartliving IOT cloud to get name to put into waitinglist
#define nameId 5 // Virtual actuator to show tge first person of the waitinglist in label in smartliving IOT cloud
#define dim 3 // Dimension of waitinglist array
Ultrasonic ultrasonic(distanceId);
void callback(int pin, String& value);
//****************************************************************
//** setup
//****************************************************************
void setup()
{
Serial.begin(57600); // Init serial link for debugging
while(!Serial && millis() < 1000); // Make sure you see all output on the monitor. After 1 sec, it will skip this step, so that the board can also work without being connected to a pc
Serial.println("Starting sketch");
Serial1.begin(115200); // Init serial link for WiFi module
while(!Serial1);
while(!Device.StartWifi())
Serial.println("Retrying...");
while(!Device.Init(DEVICEID, CLIENTID, CLIENTKEY)) // If we can't succeed to initialize and set the device credentials, there is no point to continue
Serial.println("Retrying...");
while(!Device.Connect(httpServer)) // Connect the device with the AllThingsTalk IOT developer cloud. No point to continue if we can't succeed at this
Serial.println("Retrying");
//*** assets in the smartliving IOT cloud
Device.AddAsset(greenledId, "FITTING ROOM FREE?", "GREEN LED", false, "boolean");
Device.AddAsset(subscribeId, "SUBSCRIBE TO WAITINGLIST:", "name waitinglist", true, "string");
Device.AddAsset(nameId, "NEXT:", "next", false, "string");
//***
delay(1000); // Give the WiFi some time to finish everything
while(!Device.Subscribe(mqttServer, callback)) // Make sure that we can receive message from the AllThingsTalk IOT developer cloud (MQTT). This stops the http connection
Serial.println("Retrying");
pinMode(redledId, OUTPUT);
Serial.println(" RED LED is ready for use!");
pinMode(greenledId, OUTPUT);
Device.Send("true", greenledId);
Serial.println(" GREEN LED is ready for use!");
pinMode(distanceId, INPUT);
Serial.println("Ultrasonic ranger is ready for use!");
pinMode(subscribeId, INPUT);
Device.Send("", subscribeId);
Serial.println("Subscribe is ready for use!");
pinMode(nameId, OUTPUT);
Device.Send("", nameId);
Serial.println("Next is ready for use!");
}
//****************************************************************
//** variables
//****************************************************************
int roomHeight = 250; //height of fittingroom in cm
int threshold = 50; //we do not want to meassure up the ground in case something is lying there
int zone = roomHeight - threshold; //the zone we meassure whether it's free
long RangeInCentimeters;
String waitinglist[dim]; //waitinglist containing names
int namesOnWaitingList=0; //number of names on the waitinglist
boolean occupied = false; //fresh status fitting room
boolean prev_occupied = false; //previous status fitting room
//****************************************************************
//** loop
//****************************************************************
void loop()
{
//*** meassure
RangeInCentimeters = ultrasonic.MeasureInCentimeters(); // read Ultrasonic Ranger Sensor
Serial.println("RangeInCentimeters = " + RangeInCentimeters);
Device.Send(String(RangeInCentimeters), distanceId);
if (RangeInCentimeters >= zone)
occupied = false; //fiiting room is free
else
occupied = true; //fitting room is occupied
//*** action if status has changed
if (!occupied && prev_occupied) //became free
{
Device.Send("", subscribeId);
Serial.println("Checking waitinglist");
tryWaitinglist();
digitalWrite(redledId, LOW);
digitalWrite(greenledId, HIGH);
Device.Send("true", greenledId);
prev_occupied = false;
}
else if (occupied && !prev_occupied) //is taken
{
Device.Send("" , nameId);
Serial.println("occupied");
digitalWrite(greenledId, LOW);
digitalWrite(redledId, HIGH);
Device.Send("false", greenledId);
prev_occupied = true;
}
//*** show waitinglist
Serial.println("Names on waitinglist:");
for (int i=0;i<namesOnWaitingList;i++)
{
Serial.println(waitinglist[i]);
}
Device.Process();
delay(2000); //meassure every 2 sec
}
//****************************************************************
//** Callback function: handles messages that were sent from the iot platform to this device.
//****************************************************************
void callback(int pin, String& value)
{
Serial.print("incoming data for: "); // Display the value that arrived from the AllThingsTalk IOT developer cloud.
Serial.print(pin);
Serial.print(", value: ");
Serial.print(value);
Device.Send(value, pin); // Send the value back for confirmation
if(pin == subscribeId && occupied) // One can only subscribe to the waitinglist is the fitting room is occupied
{
if(value != "" && value!= "FULL")
{
if (namesOnWaitingList < dim)
{
waitinglist[namesOnWaitingList]=value;
namesOnWaitingList++;
Device.Send("", subscribeId);
}
else
{
Device.Send("FULL", subscribeId);
}
}
}
}
//****************************************************************
//** Get first name of waitinglist if there is one
//****************************************************************
void tryWaitinglist()
{
String first;
if (namesOnWaitingList > 0) //there are names on the waitinglist
{
first = waitinglist[0];
for (int i=1;i<namesOnWaitingList;i++) //remove first one and move others to the front
{
waitinglist[i-1] = waitinglist[i];
}
waitinglist[namesOnWaitingList-1]="";
namesOnWaitingList--;
Serial.println("De first van de waitinglist is " + first);
Device.Send(first , nameId);
}
}
keys.h
ArduinoFill in the missing strings (deviceId, clientId and clientKey) in the keys.h file you get for the device
#ifndef SETTINGS
#define SETTINGS
#define DEVICEID "xxx" // Your device id comes here
#define CLIENTID "xxx" // Your client id comes here;
#define CLIENTKEY "xxx" // Your client key comes here;
#endif
Comments