Getting -310 error on simple MathWorks ThingSpeak get temperature example

1 vue (au cours des 30 derniers jours)
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
...

Réponse acceptée

Christopher Stapels
Christopher Stapels le 15 Nov 2019
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 commentaires
tebraxin tebraxin
tebraxin tebraxin le 7 Sep 2021
Modifié(e) : tebraxin tebraxin le 7 Sep 2021
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 le 7 Sep 2021
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.

Connectez-vous pour commenter.

Plus de réponses (2)

Christopher Stapels
Christopher Stapels le 15 Nov 2019
Modifié(e) : Christopher Stapels le 15 Nov 2019
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 commentaire
Wade Campbell
Wade Campbell le 15 Nov 2019
Modifié(e) : Wade Campbell le 15 Nov 2019
custom board: ATmega 328 with Wiznet 812MJ ethernet module
Looking forward to hearing your results!

Connectez-vous pour commenter.


Wade Campbell
Wade Campbell le 15 Nov 2019
custom board: ATmega 328 with Wiznet 812MJ ethernet module

Communautés

Plus de réponses dans  ThingSpeak Community

Catégories

En savoir plus sur REST API dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by