質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
SORACOM

SORACOMは、通信とクラウドを融合したIoTプラットフォームです。SIMカードの提供とその管理機能を提供する「SORACOM Air」と、よりセキュアな通信と管理をスムーズにする「SORACOM Beam」で構成。APIによりさまざまな機能を呼び出すことも可能です。

Arduino

Arduinoは、AVRマイコン、単純なI/O(入出力)ポートを備えた基板、C言語を元としたArduinoのプログラム言語と、それを実装した統合開発環境から構成されたシステムです。

Q&A

1回答

1521閲覧

AtlasScientific社製のECセンサーをarduinoに接続し、SORACOMのSigfoxシールドを使って、SORACOM LAGOONで測定値を可視化させたいです。

ToshiakiHIRAI

総合スコア0

SORACOM

SORACOMは、通信とクラウドを融合したIoTプラットフォームです。SIMカードの提供とその管理機能を提供する「SORACOM Air」と、よりセキュアな通信と管理をスムーズにする「SORACOM Beam」で構成。APIによりさまざまな機能を呼び出すことも可能です。

Arduino

Arduinoは、AVRマイコン、単純なI/O(入出力)ポートを備えた基板、C言語を元としたArduinoのプログラム言語と、それを実装した統合開発環境から構成されたシステムです。

0グッド

0クリップ

投稿2021/11/18 08:31

編集2021/11/22 03:55

前提・実現したいこと

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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

y_waiwai

2021/11/18 08:33

このままではコードが読みづらいので、質問を編集し、<code>ボタンを押し、出てくる’’’の枠の中にコードを貼り付けてください
thkana

2021/11/18 23:42

AtlasScientific社製のECセンサー SORACOMのSigfoxシールド SORACOM LAGOON それぞれの使い方/API仕様はどこで参照できますか? それがないと確実な回答はできません。
ToshiakiHIRAI

2021/11/22 03:03

Sigfoxのsend-temperatureのスケッチを文字数オーバーとなって追加できませんでした。 AtlasScientificのセンサーについては、下記に説明がありますが、私が使用したスケッチは旧バージョンなのか、もうネット上にはないようです。その旧スケッチの動作確認はできていて、正常に読取できています。 https://create.arduino.cc/projecthub/atlas-scientific/make-your-own-ph-and-salinity-monitoring-system-fb14c1?ref=similar&ref_id=166985&offset=1
thkana

2021/11/22 03:45

ところでタグの「文字コード」ってどういう関係があるのでしょう? 手違いなら外しておいてください。
guest

回答1

0

msg.addField("ecc", receive_reading);  の"receive_reading" が間違っている気がするが、他の方法が思いつかない。

なぜreceive_readingを引っ張ってきたのでしょう。そこはちゃんと考えてみる必要があると思います。

で、msg.addField()のパラメータに何を与えるべきかをちゃんと調べてみてください。

投稿2021/11/22 03:54

thkana

総合スコア7639

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ToshiakiHIRAI

2021/11/22 05:19

コメント、ありがとうございます。 恥ずかしながら、それがわからない素人なので、ここで質問させていただいています。
thkana

2021/11/22 09:36

ご存知かとは思いますが、teratailは「ITエンジニア特化型Q&Aサイト」とのことで、ヘルプにも「質問と回答を通してお互いに知識や情報を交換・共有する場所です。」となっているので、「こうすればOK」を見せて終わる場ではないと私は思うんですよね。 なので、msg.addField()にはどういうパラメータを与えるべきなのか、ぐらいは調べて欲しいわけですよ。エンジニアなら、呪文を唱えているわけじゃなくて「プログラムを作っている」のでしょうから、それが最初に行われていなきゃいけないはずなので。調べ方もわからないというならそこから話が始まりますけれど...
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問