Save 37% off PRO during our Black Friday Sale! »

Reliable distribution system with Ruby x IoT

Fe72a6744f7422c341d6301df629a36f?s=47 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.

Fe72a6744f7422c341d6301df629a36f?s=128

imashin

July 27, 2019
Tweet

Transcript

  1. Reliable distribution system with Ruby x IoT Ruby Conf Taiwan

    2019
  2. whoami ࠓҪᏴհ Shinsuke IMAI Twitter: @imashin_ ! Japan Cookpad inc.

    / Shopping Platform Department Ruby x IoT
  3. Topic • Our food delivery service with Ruby x IoT

    • Building a reliable IoT system
  4. We do not use mruby

  5. We use CRuby

  6. Agenda • What is "cookpad mart" • Building two IoT

    systems • The way to develop stable IoT system
  7. Fresh food EC platform released at last summer https://cookpad-mart.com/

  8. How to use

  9. Order Choose 
 a pick-up point

  10. Order

  11. Order Order items

  12. Order

  13. Pick up Next day, go to the pick-up point

  14. Pick up Unlock fridge by QR code

  15. Pick up Pick ordered items up

  16. Distribution flow

  17. Ordering to shops Rails batch sends orders to shops by

    FAX, Mail or Chat tool
  18. None
  19. Preparing Shops attach labels to ordered items

  20. Collecting A carrier collects items
 from shops

  21. Delivering The carriers deliver items 
 to pick-up points

  22. We don't have distribution centers

  23. Deliver in one day Low cost

  24. Fresh foods

  25. IoT devices contribute to this distribution system

  26. IoT devices Security lock on pick-up fridge Label printing system

  27. Label printing system

  28. Important point in this distribution Put labels on items Pickup

    labeled items Print labels
  29. Prototype of label printer system

  30. Hardwares iPad (Cellular model) Auto print app Always on Normal

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

    2. print command 3. printer status 4. printer status
  32. 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
  33. Label printing system as a product

  34. Hardwares 1) Don't use iOS devices => Use controllable OS

    and device 2) Don't use normal label printer => Use businnes-use label printer
  35. 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
  36. Network Can't access from server to edge => Use cellular

    network designed for IoT
  37. https://www.soracom.io/products/

  38. Network SORACOM print batch proxy gateway Canal Gate Air Shepherd

    mart server admin API API Order 6TFS Dongle Printer Raspi
  39. Software Don't use uncontrollable printer controller => Develop controllable printer

    controller
  40. https://rubygems.org/gems/star_ethernet

  41. https://www.starmicronics.com/support/Mannualfolder/starline_cm_en.pdf

  42. 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
  43. Commands

  44. 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
  45. require 'star_ethernet' data = [ StarEthernet::Command.quadruple_font_size, "Hello\nRuby Conf\nTaiwan!!\n", StarEthernet::Command.form_feed, StarEthernet::Command.partial_cut_current_line,

    ].flatten.join socket = TCPSocket.new('192.168.2.3', 9100) socket.print(data) socket.close
  46. Next update of label printer system

  47. Next update • LTE USB dongle's signal is not good

    in some places • AC adapters set is not cool
  48. Next update Antenna 2ch (5V, 24V) power supply mini PCIe

    LTE module to USB
  49. Pick-up point security

  50. Important point in this distribution • Only user can open

    the fridge door • It works on unstable LTE network
  51. Prototype of fridge lock system

  52. Before

  53. None
  54. After At

  55. None
  56. None
  57. None
  58. It works.

  59. 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
  60. Attached to fridge

  61. Requirement User can unlock in any troubles

  62. 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
  63. 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
  64. 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
  65. 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
  66. Edge services • QR reader ‣ serial port input mode

    3BTQCFSSZ1J 4JOBUSB 23SFBEFS DPOUSPMMFS 23SFBEFS 0.30/MPDL -PDL DPOUSPMMFS User unlock Remote unlock
  67. 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
  68. Edge services • Sinatra ‣ user / remote unlocking ‣

    door status monitoring 3BTQCFSSZ1J 4JOBUSB 23SFBEFS DPOUSPMMFS 23SFBEFS 0.30/MPDL -PDL DPOUSPMMFS User unlock Remote unlock
  69. 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
  70. Edge services • Lock controller ‣ door open/close ‣ door

    lock/unlock 3BTQCFSSZ1J 4JOBUSB 23SFBEFS DPOUSPMMFS 23SFBEFS 0.30/MPDL -PDL DPOUSPMMFS User unlock Remote unlock
  71. 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
  72. How to develop reliable IoT products

  73. What I did • Find problems at first by prototyping

    • Understand what is acceptable and what is not • Make the system robust with designing
  74. 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
  75. None