Getting -310 error on simple MathWorks ThingSpeak get temperature example

3 visualizzazioni (ultimi 30 giorni)
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
...

Risposta accettata

Christopher Stapels
Christopher Stapels il 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 Commenti
tebraxin tebraxin
tebraxin tebraxin il 7 Set 2021
Modificato: tebraxin tebraxin il 7 Set 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 il 7 Set 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.

Accedi per commentare.

Più risposte (2)

Christopher Stapels
Christopher Stapels il 15 Nov 2019
Modificato: Christopher Stapels il 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 Commento
Wade Campbell
Wade Campbell il 15 Nov 2019
Modificato: Wade Campbell il 15 Nov 2019
custom board: ATmega 328 with Wiznet 812MJ ethernet module
Looking forward to hearing your results!

Accedi per commentare.


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

Community

Più risposte nel  ThingSpeak Community

Categorie

Scopri di più su ThingSpeak in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by