Getting -310 error on simple MathWorks ThingSpeak get temperature example

조회 수: 6 (최근 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일
편집: 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
Christopher Stapels 2021년 9월 7일
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.
  댓글 수: 1
Wade Campbell
Wade Campbell 2019년 11월 15일
편집: Wade Campbell 2019년 11월 15일
custom board: ATmega 328 with Wiznet 812MJ ethernet module
Looking forward to hearing your results!

댓글을 달려면 로그인하십시오.


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

커뮤니티

더 많은 답변 보기:  ThingSpeak 커뮤니티

카테고리

Help CenterFile Exchange에서 ThingSpeak에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by