Why arduino send data to thingspeak only once?

6 ビュー (過去 30 日間)
GARAM LEE
GARAM LEE 2022 年 8 月 24 日
編集済み: Christopher Stapels 2022 年 11 月 10 日
Good afternoon.
I want to send mpu6050 data to thingspeak every second. However, data is only sent once now. How can I keep sending data?
(When I searched for it, there is a saying that the data transfer limit of thingspeak is 15 seconds, so is it possible to transfer data one by one in up to 15 seconds?)
And currently, the board and laptop are connected by a usb cable for uploading the code, so can I still send data even if I remove the usb cable and connect the external battery after uploading?
Hardware : mkr1000, mpu6050
#include <SPI.h>
#include <WiFi101.h>
#include <Wire.h>
#include <I2Cdev.h>
#include <WiFiClient.h>
#include "MPU6050.h"
#include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros
char ssid[] = "abc-2.4G"; // your network SSID (name)
char pass[] = "abcdefgh"; // your network password
// Initialize the Wifi client library
WiFiClient client;
unsigned long myChannelNumber = num;
const char * myWriteAPIKey = "key tiped";
MPU6050 accel1;
int16_t ax1, ay1, az1;
int16_t gx1, gy1, gz1;
unsigned long lastTime = 0;
unsigned long timerDelay = 1000; // sending every second
void setup() {
Serial.begin(115200); // Initialize serial
Wire.begin ( );
accel1.initialize();
delay(10);
WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network.
ThingSpeak.begin(client); // Initialize ThingSpeak
}
void loop() {
if (millis() - lastTime >= timerDelay) {
accel1.getMotion6(&ax1, &ay1, &az1, &gx1, &gy1, &gz1);
//acceleration full-scale range between +-2 g (16,384LSB/g)
float accX = ((float)ax1) / 16384.0;
float accY = ((float)ay1) / 16384.0;
float accZ = ((float)az1) / 16384.0;
// set the fields with the values
ThingSpeak.setField(1, accX);
ThingSpeak.setField(2, accY);
ThingSpeak.setField(3, accZ);
ThingSpeak.setField(4, gx1);
ThingSpeak.setField(5, gy1);
ThingSpeak.setField(6, gz1);
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
}
lastTime = millis(); // Update the last update time
}
  2 件のコメント
Vasudeo
Vasudeo 2022 年 11 月 10 日
was it fixed ? and how . I am facing same issue
Christopher Stapels
Christopher Stapels 2022 年 11 月 10 日
編集済み: Christopher Stapels 2022 年 11 月 10 日
@Vasudeo Feel free to start a new thread and describe your issue, what you have tried, what you see, and what you expect to see.

サインインしてコメントする。

回答 (1 件)

Christopher Stapels
Christopher Stapels 2022 年 8 月 24 日
Your device will continue to send data once disconnected from the USB port, as long as it is powered and within the WiFi range.
If you have a free ThingSpeak account, you definitely need to increase the value of timerDelay to at least 15000. If you purchase a paid account, you can get update times up to once per second.
We strongly reccomend using the ThingSpeak library for Arduino.

コミュニティ

その他の回答  ThingSpeak コミュニティ

カテゴリ

Help Center および File ExchangeWiFi についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by