前提・実現したいこと
AtlasScientific社製のECセンサーをarduinoに接続し、SORACOMのSigfoxシールドを使って、SORACOM LAGOONで測定値を可視化させたいです。
シリアルポートには測定値が正しく表示されますが(EC: 13.96)、SORACOMでは3999になります。
msg.addField("ecc", receive_reading);
をreceive_readingではなくしたいが、どうしたらいいのかわからない。
発生している問題・エラーメッセージ
シリアルポートには測定値(EC: 13.96)が正しく表示されますが、SORACOMでは3999になってしまいます。
下2つのサンプルスケッチ(ECセンサ、Sigfox)をもとに、スケッチを作製しました。
SigfoxのスケッチはUnaBiz Arduino ライブラリーをインストールして、その中のsend-temperatureのスケッチを基にした。
https://users.soracom.io/ja-jp/guides/devices/sigfox/unashield/
AtlasScientific社のECセンサは、下記の通りです。
#include <Ezo_i2c.h> //include the EZO I2C library from https://github.com/Atlas-Scientific/Ezo_I2c_lib #include <Wire.h> //include arduinos i2c library Ezo_board EC = Ezo_board(100, "EC"); //create an EC circuit object who's address is 100 and name is "EC" bool reading_request_phase = true; //selects our phase uint32_t next_poll_time = 0; //holds the next time we receive a response, in milliseconds const unsigned int response_delay = 10000; //how long we wait to receive a response, in milliseconds void setup() { Wire.begin(); //start the I2C Serial.begin(9600); //start the serial communication to the computer } void receive_reading(Ezo_board &Sensor) { // function to decode the reading after the read command was issued Serial.print(Sensor.get_name()); Serial.print(": "); // print the name of the circuit getting the reading Sensor.receive_read(); //get the response data and put it into the [Sensor].reading variable if successful Serial.print(Sensor.get_reading()); //the command was successful, print the reading } void loop() { if (reading_request_phase) { //if were in the phase where we ask for a reading //send a read command. we use this command instead of PH.send_cmd("R"); //to let the library know to parse the reading EC.send_read(); next_poll_time = millis() + response_delay; //set when the response will arrive reading_request_phase = false; //switch to the receiving phase } else { //if were in the receiving phase if (millis() >= next_poll_time) { //and its time to get the response receive_reading(EC); //get the reading from the EC circuit Serial.println(); reading_request_phase = true; //switch back to asking for readings } } }
エラーメッセージ
該当のソースコード
Arduino
// Send the sensor data from the temperature sensor to the SIGFOX cloud. // This code assumes that you are using the Grove DHT Sensor Pro: // http://wiki.seeedstudio.com/wiki/Grove_-_Temperature_and_Humidity_Sensor_Pro // // You can easily adapt the code for other Grove temperature sensors: // http://wiki.seeedstudio.com/wiki/Grove_-_Temperature_Sensor // http://wiki.seeedstudio.com/wiki/Grove_-_Tempture&Humidity_Sensor_(High-Accuracy_&Mini)_v1.0 // // Instructions and code based on: http://wiki.seeedstudio.com/wiki/Grove_-_Temperature_and_Humidity_Sensor_Pro // 1. Connect the Temperature and Humidity Sensor Pro to Port D2 of Grove - Base Shield // 2. Download and install Seeed DHT Library: https://github.com/Seeed-Studio/Grove_Temperature_And_Humidity_Sensor // 3. Make sure the voltage on the Grove Shield matches the voltage on the Arduino board. //////////////////////////////////////////////////////////// // Begin Sensor Declaration #include <Ezo_i2c.h> //include the EZO I2C library from https://github.com/Atlas-Scientific/Ezo_I2c_lib #include <Wire.h> //include arduinos i2c library Ezo_board EC = Ezo_board(100, "EC"); //create an EC circuit object who's address is 100 and name is "EC" bool reading_request_phase = true; //selects our phase uint32_t next_poll_time = 0; //holds the next time we receive a response, in milliseconds const unsigned int response_delay = 10000; //how long we wait to receive a response, in milliseconds // End Sensor Declaration //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// // Begin SIGFOX Module Declaration #include "SIGFOX.h" // IMPORTANT: Check these settings with UnaBiz to use the SIGFOX library correctly. static const String device = "g88pi"; // 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 UnaShieldV1 transceiver(country, useEmulator, device, echo); // Uncomment this for UnaBiz UnaShield V1 Dev Kit // End SIGFOX Module Declaration //////////////////////////////////////////////////////////// void setup(){ { Serial.begin(9600); Serial.println(F("Water Monitoring")); Wire.begin(); } // End Sensor Setup //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// // Begin SIGFOX Module Setup String result = ""; // Enter command mode. Serial.println(F("\nEntering command mode...")); transceiver.enterCommandMode(); if (useEmulator) { // Emulation mode. transceiver.enableEmulator(result); } else { // Disable emulation mode. Serial.println(F("\nDisabling emulation mode...")); transceiver.disableEmulator(result); // Check whether emulator is used for transmission. Serial.println(F("\nChecking emulation mode (expecting 0)...")); int emulator = 0; transceiver.getEmulator(emulator); } // Set the frequency of SIGFOX module to SG/TW. Serial.println(F("\nSetting frequency...")); result = ""; transceiver.setFrequencySG(result); Serial.print(F("Set frequency result = ")); Serial.println(result); // Get and display the frequency used by the SIGFOX module. Should return 3 for RCZ4 (SG/TW). Serial.println(F("\nGetting frequency (expecting 3)...")); String frequency = ""; transceiver.getFrequency(frequency); Serial.print(F("Frequency (expecting 3) = ")); Serial.println(frequency); // Read SIGFOX ID and PAC from module. Serial.println(F("\nGetting SIGFOX ID...")); String id = "", pac = ""; if (transceiver.getID(id, pac)) { Serial.print(F("SIGFOX ID = ")); Serial.println(id); Serial.print(F("PAC = ")); Serial.println(pac); } else { Serial.println(F("ID KO")); } // Exit command mode and prepare to send message. transceiver.exitCommandMode(); // End SIGFOX Module Setup //////////////////////////////////////////////////////////// } void receive_reading(Ezo_board &Sensor) { // function to decode the reading after the read command was issued Serial.print(Sensor.get_name()); Serial.print(": "); // print the name of the circuit getting the reading Sensor.receive_read(); //get the response data and put it into the [Sensor].reading variable if successful Serial.print(Sensor.get_reading()); //the command was successful, print the reading } void loop() { //////////////////////////////////////////////////////////// // Begin Sensor Loop if (reading_request_phase) { //if were in the phase where we ask for a reading //send a read command. we use this command instead of PH.send_cmd("R"); //to let the library know to parse the reading EC.send_read(); next_poll_time = millis() + response_delay; //set when the response will arrive reading_request_phase = false; //switch to the receiving phase } else { //if were in the receiving phase if (millis() >= next_poll_time) { //and its time to get the response receive_reading(EC); //get the reading from the EC circuit Serial.println(); reading_request_phase = true; //switch back to asking for readings } } Message msg(transceiver); // Will contain the structured sensor data. { // Convert the numeric temperature and humidity to binary fields. // Field names must have 3 letters, no digits. Field names occupy 2 bytes. // Numeric fields occupy 2 bytes, with 1 decimal place. msg.addField("ecc", receive_reading); // 4 bytes // Total 8 bytes out of 12 bytes used. } // End Sensor Loop //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// // Begin SIGFOX Module Loop // Send the message. Serial.print(F("\n>> Device sending message ")); Serial.print(msg.getEncodedMessage() + "..."); transceiver.echoOn(); if (msg.send()) { Serial.println(F("Message sent")); } else { Serial.println(F("Message not sent")); } // End SIGFOX Module Loop //////////////////////////////////////////////////////////// // Wait a while before looping. 10000 milliseconds = 10 seconds. delay(20000); }
//
試したこと
他のセンサーでは問題なかったので、何を試したらいいのかわからない。
msg.addField("ecc", receive_reading); の"receive_reading" が間違っている気がするが、他の方法が思いつかない。
補足情報(FW/ツールのバージョンなど)
Arduino