LoginSignup
4
2

More than 3 years have passed since last update.

ここでは、Sigfox Shield for Arduino(本名UnaShield: 台湾・シンガポールを拠点とするUnaBiz社が開発したSigfox評価ボード)に内蔵されている各種センサーやGROVEセンサーからデータ取得する方法を説明します。
UnaBiz社は、ソラコムとともに、ニチガス「スペース蛍」を開発された会社です。ニュースはこちら

入手方法

下記いずれかからご購入ください。

ソラコムさんの場合は、SORACOM Air for Sigfoxとしてお使いいただくことになりますので、ここで説明する使い方とは少し異なります。

その他準備

UnaShieldは、Arduino UNOに互換を持つシールドですので、Arduino UNOを入手しておいてください。

1年間無料回線

1年間の無料回線が付いてきます。デバイスを入手したら、こちらを見て、回線をアクティベートしてください。
1年経過後は、有料回線への切り替えが必要です。Sigfox Buyで新たにデバイスを登録しなおすことになりますが、PACコードは一度登録されると変更されますので、こちらを参考に、現状のPACコードを確認し、登録しなおしてください。

UnaShield搭載センサ

UnaShieldは加速度センサ(MMA8451Q)と温/湿度・気圧センサ(BME280)を搭載しており、すぐにでもIoTアプリケーションを作ってみることができます。
また、2つのGROVEコネクタ(I2Cインターフェースとアナログ入出力)を搭載していますので、外部GPSセンサなどと接続することも可能です。

サンプルスケッチ

UnaBiz社が提供しているサンプルはこちらにあります。サンプルスケッチのうちDemoTestUnaShieldV2SRCZ3は、日本国内向けに対応しているものですので、変更することなくお使いいただけます。

また、こちらにもサンプルがあります。
すべてのサンプルスケッチは日本RC3向けになっており、搭載センサのサンプルの他、GROVEセンサを使ったサンプルもあります。

basic-demo

Sigfoxモジュールの温度と入力電圧を一定間隔で送信します。

basic-demo.c
#include "SIGFOX.h"

//必要に応じ書き換えてください
//************************************
static const unsigned int MESSAGE_INTERVAL = 30000;   //Sigfoxメッセージ送信間隔(30秒)
static const unsigned int MAX_MESSAGE_CNT = 10;         //Sigfoxメッセージ最大送信数(10回)
//************************************

unsigned int message_cnt = 0;

// IMPORTANT: Check these settings with UnaBiz to use the SIGFOX library correctly.
static const String device = "NOTUSED";  //  Set this to your device name if you're using UnaBiz Emulator.
static const bool useEmulator = false;  //  Set to true if using UnaBiz Emulator.
static const bool echo = true;  //  Set to true if the SIGFOX library should display the executed commands.
static const Country country = COUNTRY_JP;  //  Set this to your country to configure the SIGFOX transmission frequencies.
static UnaShieldV2S transceiver(country, useEmulator, device, echo);  //  Uncomment this for UnaBiz UnaShield V2S Dev Kit
static String response;  //  Will store the downlink response from SIGFOX.
// IMPORTANT: Check these settings with UnaBiz to use the SIGFOX library correctly.

void setup()
{
  Serial.begin(9600);         // Arduinoハードウェアシリアルを起動(Arduino <-> PC)
  Serial.println("===========================");
  Serial.println("Sigfox UnaShield Basic Sample");
  Serial.print("Send a message in "); Serial.print(MAX_MESSAGE_CNT); Serial.print(" times for each "); Serial.print(MESSAGE_INTERVAL); Serial.println(" msec.");
  Serial.println("===========================");

  //Sigfoxモジュールを起動
  if (!transceiver.begin()) stop(F("Unable to init SIGFOX module, may be missing"));  //  Will never return.

  Serial.println("Waiting 3 seconds...");
  delay(3000);
}

void loop()
{ 
  //温度、バッテリー電圧を取得する
  float temperature = 0;
  float voltage = 0;
  transceiver.getTemperature(temperature);
  transceiver.getVoltage(voltage);

  if (sendSigfoxMessage(message_cnt, temperature, voltage)) 
  {
    message_cnt++;
  }

  if (message_cnt >= MAX_MESSAGE_CNT) 
  {
    stop(String("finish...(Message sent successfully)"));
  }

  Serial.print("Waiting "); Serial.print(MESSAGE_INTERVAL/1000); Serial.println(" seconds...");
  delay(MESSAGE_INTERVAL);  
}

//送信回数と温度、バッテリー電圧をSigfoxメッセージで送信する
bool sendSigfoxMessage(unsigned int cnt, float temperature, float voltage) 
{
  Serial.println("\n*****SEND SIGFOX MESSAGE*****");
  String sCnt = transceiver.toHex(cnt);
  String sTemp = convertFloatToHex(temperature);
  String sVoltage = convertFloatToHex(voltage);
  Serial.print("Count: "); Serial.print(cnt);
  Serial.print(" / Temperature: "); Serial.print(temperature); 
  Serial.print(" / Voltage: "); Serial.println(voltage);
  Serial.print("Payload: "); Serial.println(sCnt + sTemp + sVoltage);
  bool success = transceiver.sendMessage(sCnt + sTemp + sVoltage);
  Serial.println("*****************************");
  return success;
}

//Float型変数をIEEE754に準拠した16進文字列へ変換する
String convertFloatToHex(float val) 
{
  union {
    uint32_t B32;
    float Float;
  } floatb32;

  floatb32.Float = val;
  return String(floatb32.B32, HEX);
}

basic-button

シールド上のボタンを押したときに、Sigfoxメッセージを送信します。

basic-temp-humid-pressure

シールド上のBME280から温度、湿度、気圧を送信します。
ライブラリマネージャ(スケッチライブラリのインクルードライブラリを管理)で"Adafruit BME280 Library"をインストールしておく必要があります。

grove-gps

Grove GPSセンサの緯度経度を送信します。
GPSセンサは下記URLのもので、GROVEセンサのアナログポートに接続することにより、お試しいただけます。
http://wiki.seeedstudio.com/Grove-GPS/

grove-light

Digital Light Sensor (TSL2561)から、明暗変化時に、取得した照度を送信します。
Grove(I2C)ポートにセンサを接続してください。
http://wiki.seeedstudio.com/Grove-Digital_Light_Sensor/

grove-ultrasonic

Grove Ultrasonic Rangerから物体検出時に想定距離と共にSigfoxメッセージを送信します。
Grove(Analog)ポートにセンサを接続してください。
http://wiki.seeedstudio.com/Grove-Ultrasonic_Ranger/

Sigfox Japan KCCS

4
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2