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

鯖 On RasPi ~Mackerelで簡単家モニタリング~

鯖 On RasPi ~Mackerelで簡単家モニタリング~

Mackerel meetup #4にてLT発表

y_matsuwitter

June 02, 2015
Tweet

More Decks by y_matsuwitter

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ • Gunosy Inc. • ։ൃຊ෦ࣥߦ໾һࡶ༻໾ • iOS, Android, Infrastructure,

    Web • Golang෍ڭ໾ • ਖ਼࠲ • ࠷ۙؾʹͳΔ΋ͷ: MQTT
  2. Spec • খܕɾ҆Ձͳڭҭ޲͚LinuxϚγϯ • RaspberryPi Foundation͕։ൃ • CPU: ARM •

    Memory: 256 ~ 1GB • USB microBͰڅి • GPIOϐϯ͕༻ҙ͞Ε͍ͯΔ
  3. embdͰSHT21͔ΒԹ౓Λऔಘ • ࠓճ͸EmbdͷI2CBusΛ௚઀ར༻ // Busʢܦ࿏ʣͷ࡞੒ bus := embd.NewI2CBus(1) // ॳظԽ

    bus.WriteByte(addr, byte(softreset)) // ॳظԽ׬ྃ଴ͪ time.Sleep(500 * time.Millisecond)
  4. ଓ͖ // Թ౓Λૹͬͯ΋Β͏Α͏৴߸ૹ৴ bus.WriteByte(addr, triggerTemperatureNoHold) // ϋʔυ΢ΣΞଆͷ৴߸଴ͪ time.Sleep(temperatureWait * time.Millisecond)

    // 1όΠτ໨ಡΈग़͠ first, _ := bus.ReadByte(addr) // 2όΠτ໨ಡΈग़͠ second, _ := bus.ReadByte(addr) // ̎ͭͷ஋Λݩʹηϧγ΢ε౓ʹม׵ temp := (175.72*float64((int64(first)<<8+int64(second))&statusBitMusk))/float64(1<<16) - 46.85