📜 ⬆️ ⬇️

iToilet. Office toilet is free



Hi, Habr!
My name is Serg Krivoblotsky and I’m an alcoholic iOS developer. I work in a small Kiev company that specializes in iOS development and design for our platform. “Love what you do and do what you love,” they say. We do. Love

The idea of ​​monthly hackathons caught on in our team perfectly well. Once a month, on weekends, the team gathers for entertainment in the form of writing code, learning new technologies, simply generating ideas, or eating pizza. Tasks were different: from the virtual planning poker'a, to the recognition of the price on the check and convert to nat. currency. The main goal of all this is not to release the finished product, but rather to write a working prototype, aka MVP, as you wish.
On one of the ideas and its implementation, I would like to tell you more.

Everyone who is in a co-working or a small office has come across this algorithm of his actions:
  1. Coming to the toilet
  2. Oops, busy
  3. You go to the workplace.
  4. Wait until it is free.

There is a problem - there must be a solution. It would be convenient if, while in the workplace, I already knew whether the toilet was currently occupied and whether I should go there.
')



What we need for this:


It was purchased:

  1. Pcduino
  2. The most common analog light sensor
  3. Many wires and several resistors


Working process:
I will not write a lot of code, because it is understood as hello world. At the end of the article there will be links to Github.

  1. Connect the sensor to pcduino:

    The sensor will return values ​​in the range 0..4096.
    Empirically, it was determined that our light bulb in the toilet when turned on gives:
    > 3400 - darkness
    <3400 - light
  2. Raise apache. (previously there was installed ubuntu).
  3. We write php code to read the readings (at the end of the article there are links to GitHub):

    $this->port = (isset($_GET["port"]) && is_numeric($_GET["port"])) ? $_GET["port"]:2; $this->data = exec("cat /proc/adc".$this->port); 


  4. We write API for mobile, and not only, clients:
      $this->answer(array( 'light_value' => (int)$this->data, 'light_status' => (bool)$l_status, 'light_change' => (int)$l_change, 'sensor_status' => true )); 
  5. We interrogate the timer on the device in any way convenient for you:
    OSX:
      NSURL *toiletURL = [NSURL URLWithString:kToiletURLString]; NSError *requestError = nil; NSData *responseData = [NSData dataWithContentsOfURL:toiletURL options:NSDataReadingUncached error:&requestError]; 

    iOS:
      NSURL *url = [NSURL URLWithString:urlString]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; //Send NSURLSession dataTask [self sendRequest:request withCompletion:completion]; 

  6. Post notification:
     [self.notificationController deliverNotificationWithTitle:kBusyNotificationText andText:notificationText]; 



... In general, this is all that is needed. Later we added a few buns in the form of a timer and the ability to disable pop-up notifications.
Result of work:
OSX:


iOS


Hackathon sources:
OSX:
github.com/Krivoblotsky/iToilet-Mac-OS

iOS
github.com/Krivoblotsky/iToilet

PHP:
github.com/Krivoblotsky/iToilet-PHP

@Krivoblotsky

Source: https://habr.com/ru/post/216059/


All Articles