Goを使ったセンサーデータ収集基盤の事例のお話 / golang.tokyo 26 LT

Goを使ったセンサーデータ収集基盤の事例のお話 / golang.tokyo 26 LT

06febd004d7cc9c9f6a4e0272b686bc7?s=128

Takeshi Shinoda

September 25, 2019
Tweet

Transcript

  1. GoΛ࢖ͬͨ ηϯαʔσʔλऩूج൫ ͷ ࣄྫͷ͓࿩ @takeshinoda

  2. ࣗݾ঺հ • ࣰా ݈ (͠ͷͩ ͚ͨ͠) • @takeshinoda • MODE,

    Inc ۈ຿ • ීஈ͸Rubyist • ன͸GoͱTypeScriptॻ͍ͯ·͢ • Go΋݁ߏ޷͖
  3. MODE, Inc. • γϦίϯόϨʔʹͯ2014೥૑ۀ • B2BͳIoTج൫Λఏڙ • ϦΞϧͷσʔλऩू • ϦΞϧσʔλ࢖ͬͨϏδωεͷ͓ख఻͍

  4. None
  5. ϓϩμΫγϣϯ΁ͷ͓ख఻͍ MODE Ϋϥ΢υ ࣌ܥྻ DB WebHook Πϕϯτج൫ OTA (Over-the-Air) ϩάऩू

    σόΠε؅ཧ ೝূ Users / Devices / API access MODE ήʔτ΢ΣΠ MODE αʔϏε Ϗδωεɾۀ຿αʔϏε ݱ࣮σʔλ ηϯαʔ/֤छػثσʔλ ͜͜ͷϨΠϠʔʹରͯ͠ PoCϨϕϧ͔Β ϓϩμΫγϣϯϨϕϧ·Ͱͷ ٕज़Λఏڙ͢Δ
  6. MODE Ϋϥ΢υ MODE ήʔτ΢ΣΠ MODE αʔϏε Ϣʔβʔɾఏܞاۀ ݱ࣮ੈք Sensor Cloud

    Mobility Cloud Factory Cloud ࣌ܥྻ DB ࣌ܥྻ DB/SDS ࣌ܥྻ DB
  7. MODE Gateway PLC Bluetooth MODbus GPS OBD-II ControllerPC RS-485 Bluetooth

    LE MODbus/RTU NMEA 0183 CANbus / ISO9141-2 Smb protocol MODE Platform Application TSDB Event Dispatcher Manage Devices OTA Update Authentica tion Application MQTT REST API REST API
  8. MODE Gateway PLC Bluetooth MODbus GPS OBD-II ControllerPC RS-485 Bluetooth

    LE MODbus/RTU NMEA 0183 CANbus / ISO9141-2 Smb protocol MODE Platform Application TSDB Event Dispatcher Manage Devices OTA Update Authentica tion Application MQTT REST API REST API Go: Gateway, Server side TypeScript: Frontend, Gateway
  9. Gateway OS: Ubuntu 16.04, 18.04, Yocto… Gateway main process Node

    process WiFi / 3G OTA Updater Log collector
  10. Go͸IoTͰศར Intel, ARM Ubuntu, Yocto Intel NUC, VIA, OpenBlocks, etc…

  11. Go͸IoTͰศར • ࠷ॳظ͸ES6 • ΫϩείϯύΠϧͷखؒͷ໰୊ • ඇಉظσʔλ௨৴ͷ੍ޚͷ؆ศ͞ • select, channel,

    goroutine • σϓϩΠͷ؆ศ͞ • ͜ͷྖҬͷ؆ศ͞ͱͦͦ͜͜ศརͳܕ
  12. Server side ඇಉظॲཧͱ ಉظॲཧ͕ࠞͬͯ͟Δ Gateway Eventॲཧ ࠶ૹॲཧ ࠶઀ଓॲཧ Event όοϑΝϦϯά

    Command Synced data
  13. Go͸IoTͰศར • ඇಉظ෦෼͸channelͱgoroutine • ಉظ෦෼͸௨ৗͷίʔυ • channelͱselect͕ͳ͍৔߹ɺͨ͘͞ΜͷΠϕ ϯτۦಈͰσʔλ͕ൃੜ͢ΔσʔλΛඇಉظ ॲཧͰॻ͘ͷ͕େม •

    node΋EventEmitterͳͲͰదͯ͠͸͍ͨ • ֤छGWσϓϩΠͷ؆ศ͞ͱσόοάͷ؆ศ ͞ͰGo͕࠾༻͞Εͨ
  14. Πϕϯτൃੜॲཧ TS for await (const sensorData of sensorModule.dataIterator()) { try

    { await timeout(dataSender.sendData(sensorData), timeout); } catch (error) { logger.error(`Failed: ${error}`); } } async* dataIterator(): AsyncIterable<SensorData[]> { while (true) { let sensorData: SensorData[]; try { sensorData = await this.next(); } catch (error) { throw error; // break loop } yield sensorData; } }
  15. Πϕϯτൃੜॲཧ Go select { case l := <- serial.Rx: return

    string(l), nil case <-time.After(timeout): return "", errors.New(“readtimeout”) } for { buf := make([]bytes, 1024) if _, err := s.Read(buf); err != nil { … } serial.Rx <- buf }
  16. Go͸IoTͰศར • Ͳ͕ͬͪྑ͍͔͸͘͢͝೉͍͠ • Ͳͬͪ΋ͳΜͱ͔ͳΔ • node΋Go΋ඇಉظॲཧ͸༏ल • ݸਓతʹ͸Goͷํ͕҆৺ •

    TSతͳॻ͖ํʹ׳Εͯͳ͍ͷ΋΋ͪΖΜ͋Δ • ͔͠͠nodeͰ΍Δͱ͖ʹ͸TS͸҆͘͢͝৺
  17. ͭ͠΋Μ

  18. ͋Γ͕ͱ͏ ͍͟͝·ͨ͠