Getting -310 error on simple MathWorks ThingSpeak get temperature example

3 次查看(过去 30 天)
Getting -310 error on simple MathWorks ThingSpeak get temperature example. (I simplified the example to include only the read from the public site)
Code is below.
Monitor output is at bottom of post.
Any ideas on why I'm getting the -310 would be greatly appreciated!
#include "ThingSpeak.h"
#include <Ethernet.h>
#include "secrets.h"
byte mac[] = SECRET_MAC;
// Set the static IP address to use if the DHCP fails to assign
byte ip[] = {
192, 168, 0, 199 };
EthernetClient client;
// Weather station channel details
unsigned long weatherStationChannelNumber = SECRET_CH_ID_WEATHER_STATION;
unsigned int temperatureFieldNumber = 4;
void setup() {
Serial.begin(9600L); //Initialize serial
delay (4000); //WVC
// start the Ethernet connection:
Serial.println("Initialize Ethernet");
Ethernet.begin(mac, ip);
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
// try to congifure using IP address instead of DHCP:
// Ethernet.begin(mac, ip, myDns); //WVC
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("initialize TS");
ThingSpeak.begin(client); // Initialize ThingSpeak
}
void loop() {
int statusCode = 0;
// Read in field 4 of the public channel recording the temperature
float temperatureInF = ThingSpeak.readFloatField(weatherStationChannelNumber, temperatureFieldNumber);
// Check the status of the read operation to see if it was successful
statusCode = ThingSpeak.getLastReadStatus();
if(statusCode == 200){
Serial.println("Temperature at MathWorks HQ: " + String(temperatureInF) + " deg F");
}
else{
Serial.println("Problem reading channel. HTTP error code " + String(statusCode));
}
delay(15000); // No need to read the temperature too often.
}
------------------ monitor output is below ----------------------
Initialize Ethernet
Initialize TS
Problem reading channel: HTTP error code -301
Problem reading channel: HTTP error code -301
Problem reading channel: HTTP error code -301
...

采纳的回答

Christopher Stapels
Christopher Stapels 2019-11-15
I got a -301 error when I didnt have the Ethernet cable plugged in, but now it is working fine on an arduino Uno with ethernet Shield (Sainsmart)
Perhaps check the connection, and the ethernet address (in the secrets file) to see if you are overlapping with an existing device?
  4 个评论
tebraxin tebraxin
编辑:tebraxin tebraxin 2021-9-7
Do you mean the cable has to connect before start arduino ??
I try both, calbe is also anytime connected before and afetr restart, but I always get error 301....
thanks
Christopher Stapels
It would be best to have the cable connected at all times, just in case. I would check the wifi connection using software if possible. USe the Serial Monitor to output the result of the cennection.
One user found a timeout setting that helped in this discussion.

请先登录,再进行评论。

更多回答(2 个)

Christopher Stapels
Christopher Stapels 2019-11-15
编辑:Christopher Stapels 2019-11-15
What hardware you are using? We will try to reproduce the error.
EDIT I am sttempting to verify the error with an arduino Uno with an Ethernet shield.

Wade Campbell
Wade Campbell 2019-11-15
custom board: ATmega 328 with Wiznet 812MJ ethernet module

社区

更多回答在  ThingSpeak Community

类别

Help CenterFile Exchange 中查找有关 REST API 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by