Witajcie.
Napisałem programik pod moduł ENC28J60 który działa poprawnie.
Program działa na skrypcie thingspeak
i bazujący na bibliotece EtherCard.h
Natomiast żeby nie było za dużo kabli zakupiłem ethernet shield i niestety nie działa na tej bibliotece.
Mimo ze też działa na SPI to cały czas mam komunikat że brak połączenia z serwerem.
Natomiast ten Ethernet Shield działa na wbudowanej bibliotece
<Ethernet.h
Dlaczego moduł https://botland.com.pl/pl/produkty-wycof...crosd.html
nie działa z biblioteką EtherCard.h
Co trzeba zmienić żeby to odpaliło.
Piny SPI sa dokładnie takie same. CS też jest na 10 - nawet ręcznie próbowałem ustawić CS na 10 też nie odpala.
Problem w tym, że już sporo napisałem kodu i nie tak prosto podmienić tą bibliotekę.
Przykładowy kod działający a Thingspeak na shieldzie.
Napisałem programik pod moduł ENC28J60 który działa poprawnie.
Program działa na skrypcie thingspeak
i bazujący na bibliotece EtherCard.h
Kod:
// Simple demo for feeding some random data to Pachube.
// 2011-07-08 <jc@wippler.nl>
//
// License: GPLv2
// Handle returning code and reset ethernet module if needed
// 2013-10-22 hneiraf@gmail.com
// Modifing so that it works on my setup for www.thingspeak.com.
// Arduino pro-mini 5V/16MHz, ETH modul on SPI with CS on pin 10.
// Also added a few changes found on various forums. Do not know what the
// res variable is for, tweaked it so it works faster for my application
// 2015-11-09 dani.lomajhenic@gmail.com
#include <EtherCard.h>
...
Mimo ze też działa na SPI to cały czas mam komunikat że brak połączenia z serwerem.
Natomiast ten Ethernet Shield działa na wbudowanej bibliotece
<Ethernet.h
Dlaczego moduł https://botland.com.pl/pl/produkty-wycof...crosd.html
nie działa z biblioteką EtherCard.h
Co trzeba zmienić żeby to odpaliło.
Piny SPI sa dokładnie takie same. CS też jest na 10 - nawet ręcznie próbowałem ustawić CS na 10 też nie odpala.
Problem w tym, że już sporo napisałem kodu i nie tak prosto podmienić tą bibliotekę.
Przykładowy kod działający a Thingspeak na shieldzie.
Kod:
#include <Timers_akcja.h>
#include <SPI.h>
#include <Ethernet.h>
int pin = 0; // analog pin
float tempc = 0; // temperature variables
int samples[8]; // variables to make a better precision
int maxi = -100,mini = 100; // to start max/min temperature
int i;
Timers_akcja <3> Akcja;
// Local Network Settings
byte mac[] = { 0xD4, 0xA8, 0xE2, 0xFE, 0xA0, 0xA1 }; // Must be unique on local network
byte ip[] = { 172,16,100,198 }; // Must be unique on local network
byte gateway[] = { 172,16,100,1};
byte subnet[] = { 255, 255, 255, 0 };
// ThingSpeak Settings
char thingSpeakAddress[] = "api.thingspeak.com";
String writeAPIKey = "A6D0VZ91IT6URB0L"; // Write API Key for a ThingSpeak Channel
const int updateInterval = 10000; // Time interval in milliseconds to update ThingSpeak
String analogPin0;
// Variable Setup
long lastConnectionTime = 0;
boolean lastConnected = false;
int failedCounter = 0;
int led1 = 13;
// Initialize Arduino Ethernet Client
EthernetClient client;
void setup()
{
Serial.begin(57600);
Ethernet.begin(mac, ip, gateway, subnet);
delay(1000);
Serial.print("ETHERNET SHIELD ip is : ");
Serial.println(Ethernet.localIP());
// Start Ethernet on Arduino
startEthernet();
Akcja.attach (0, 10000, update_thingspeak);
}
void loop()
{
Akcja.process(); //włączenie timerów
// tempc = ( 5.0 * analogRead(pin) * 100.0) / 1024.0;
tempc = ( 5.0 * analogRead(pin)) / 1024.0;
analogPin0 = String(tempc);
//Serial.println(analogPin0);
// Print Update Response to Serial Monitor
if (client.available())
{
char c = client.read();
Serial.print(c);
}
// Disconnect from ThingSpeak
if (!client.connected() && lastConnected)
{
Serial.println();
Serial.println("...disconnected.");
Serial.println();
client.stop();
}
// Update ThingSpeak
if(!client.connected() && (millis() - lastConnectionTime > updateInterval))
{
updateThingSpeak("field1="+analogPin0);
}
lastConnected = client.connected();
}
//============================================= MOJE FUNKCJE =================================================================
void updateThingSpeak(String tsData)
{
if (client.connect(thingSpeakAddress, 80))
{
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+writeAPIKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(tsData.length());
client.print("\n\n");
client.print(tsData);
lastConnectionTime = millis();
if (client.connected())
{
Serial.println("Connecting to ThingSpeak...");
Serial.println();
failedCounter = 0;
}
else
{
failedCounter++;
Serial.println("Connection to ThingSpeak failed ("+String(failedCounter, DEC)+")");
Serial.println();
}
}
else
{
failedCounter++;
Serial.println("Connection to ThingSpeak Failed ("+String(failedCounter, DEC)+")");
Serial.println();
lastConnectionTime = millis();
}
}
void startEthernet()
{
client.stop();
Serial.println("Connecting Arduino to network...");
Serial.println();
delay(1000);
// Connect to network amd obtain an IP address using DHCP
if (Ethernet.begin(mac) == 0)
{
Serial.println("DHCP Failed, reset Arduino to try again");
Serial.println();
}
else {
Serial.println("Arduino connected to network using DHCP");
Serial.println();
Serial.println("Data being uploaded to THINGSPEAK Server.......");
Serial.println();
}
delay(1000);
}
void update_thingspeak()
{
updateThingSpeak("field4="+analogPin0);
}