Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Reliable distribution system with Ruby x IoT

imashin
July 27, 2019

Reliable distribution system with Ruby x IoT

In our EC service called "Cookpad Mart", we develop Ruby x IoT system which not just works but works with reliability.
By the way, do you cook? Is it easy to get very fresh meats, fishes or vegetables around your home? Cookpad Mart makes it possible for customers to purchase fresh foods directly from farmers, meat shops and fish stores. We deliver ordered foods to pick-up points near your home, so you can pick them up anytime you like, without waiting for the delivery at your home or paying delivery fees.
To deliver fresh foods in the day of orders, we built a new distribution system consisting of several IoT devices: label printing devices, temperature sensors, location sensors and label readers.
In this talk, I explain our development of the label printing system. We set up label printing devices at all sellers’ shop and print labels for each food every day. We have to print the labels without any failures because they are for sellers, deliverers and customers to sort or to pick up foods, but it is difficult to monitor and to control many such edge devices like printers. Then, we solved it with a simple idea. I will talk about how to make the label printers reliable with Ruby and IoT technology.

imashin

July 27, 2019
Tweet

More Decks by imashin

Other Decks in Technology

Transcript

  1. Topic • Our food delivery service with Ruby x IoT

    • Building a reliable IoT system
  2. Agenda • What is "cookpad mart" • Building two IoT

    systems • The way to develop stable IoT system
  3. Hardwares iPad (Cellular model) Auto print app Always on Normal

    label printer Always on Ethernet connection Lightning to USB adapter USB to Ethernet adapter
  4. 1. get label data Workflow mart-server Rails iPad Label printer

    2. print command 3. printer status 4. printer status
  5. Failures • Too many steps to set up • Fail

    many times to print labels ‣ Unstable connection between iPad and label printer ‣ Label printer jam ‣ App crash ‣ App freeze • Unable to update easily
  6. Hardwares 1) Don't use iOS devices => Use controllable OS

    and device 2) Don't use normal label printer => Use businnes-use label printer
  7. Hardwares STAR MICRONICS TSP700II Thermal label printer Sensors for monitoring

    SNMP Huawei M2372h-607 LTE USB dongle Raspberry Pi 3 Model B+ Edge controller Arch Linux ARM Router / SSH Server Network monitoring / Kitting
  8. Network SORACOM print batch proxy gateway Canal Gate Air Shepherd

    mart server admin API API Order 6TFS Dongle Printer Raspi
  9. Sample code require 'star_ethernet' data = [ "Hello\nRuby Conf\nTaiwan!!\n", #

    command for feed label StarEthernet::Command.form_feed, # command for cut label StarEthernet::Command.partial_cut_current_line, ].flatten.join socket = TCPSocket.new('192.168.11.2', 9100) socket.print(data) socket.close
  10. def set_cancel_the_double_wide_high(n1, n2) [0x1b, 0x69, n1, n2].pack('C*') end def sextuple_font_size

    set_cancel_the_double_wide_high(0x05, 0x05) end https://www.starmicronics.com/support/Mannualfolder/starline_cm_en.pdf
  11. Next update • LTE USB dongle's signal is not good

    in some places • AC adapters set is not cool
  12. Important point in this distribution • Only user can open

    the fridge door • It works on unstable LTE network
  13. Hardwares Controller box same with label printer system HF500-W Honeywell

    QR reader D4SL-N OMRON Lock door switch Key holding force of 1,300N OPEN/CLOSE monitoring LOCK/UNLOCK monitoring DHT11 Temperature sensor
  14. Unlocking workflow User Fridge system mart-server mart-edge Fridges JWT token

    QR Reader Signature verification working on offline status Authorized User Unauthorized user SORACOM Gate SORACOM Canal
  15. Unlocking workflow User Fridge system mart-server mart-edge Fridges JWT token

    QR Reader Signature verification working on offline status Authorized User Unauthorized user SORACOM Gate SORACOM Canal
  16. Unlocking workflow User Fridge system mart-server mart-edge Fridges JWT token

    QR Reader Signature verification working on offline status Authorized User Unauthorized user SORACOM Gate SORACOM Canal
  17. Unlocking workflow User Fridge system mart-server mart-edge Fridges JWT token

    QR Reader Signature verification working on offline status Authorized User Unauthorized user SORACOM Gate SORACOM Canal
  18. Edge services • QR reader ‣ serial port input mode

    3BTQCFSSZ1J 4JOBUSB 23SFBEFS DPOUSPMMFS 23SFBEFS 0.30/MPDL -PDL DPOUSPMMFS User unlock Remote unlock
  19. QR reader require 'net/http' require 'uri' require 'serialport' HOST =

    'http://localhost:9292/qr_reader' SerialPort.open('/dev/ttyACM0', 38400, 8, 1, SerialPort::NONE) do |com| while true begin str = com.gets body = { input: str } Net::HTTP.post_form(URI.parse(HOST), body) rescue => e p e end end end
  20. Edge services • Sinatra ‣ user / remote unlocking ‣

    door status monitoring 3BTQCFSSZ1J 4JOBUSB 23SFBEFS DPOUSPMMFS 23SFBEFS 0.30/MPDL -PDL DPOUSPMMFS User unlock Remote unlock
  21. Sinatra server class App < Sinatra::Base post '/qr_reader' do body

    = request.body.read decoded_token = JWT.decode body.input, nil, false if verify(decoded_token) fridges_controller.open_all_fridges end end end
  22. Edge services • Lock controller ‣ door open/close ‣ door

    lock/unlock 3BTQCFSSZ1J 4JOBUSB 23SFBEFS DPOUSPMMFS 23SFBEFS 0.30/MPDL -PDL DPOUSPMMFS User unlock Remote unlock
  23. Lock def door_auto_lock_on_open Thread.new do loop do lock! if opened?

    sleep 1 end end end def opened? RPi::GPIO.high? (@door_open_closed_detection_contact_pin_num) end def lock! Mutex.new.synchronize do RPi::GPIO.set_low(@solenoid_pin_num) end end
  24. What I did • Find problems at first by prototyping

    • Understand what is acceptable and what is not • Make the system robust with designing
  25. Ruby can do anything • Label printer system ‣ TCP

    socket programming ‣ Print commands ‣ Kitting codes • Fridge lock system • Control QR reader • Verification / Signature • Control fridge lock via GPIO