Ho un modulo RFM69 (radio) che riceve dati che voglio visualizzare su una pagina web della LAN tramite una connessione RJ45 con W5100.
Entrambi i moduli usano la comunicazione SPI con diverso SlaveSelect
I moduli condividono le linee dati MISO, MOSI e SCK
Ogni modulo funziona regolarmente escludendo la compilazione dell'altro modulo.
Quando sono utilizzati entrambi, Arduino si blocca dopo qualche aggiornamento, sia della pagina web che del ciclo di print della uscita seriale.
cosa mi suggerite?
questa la bozza dello sketch
/* Bozza-01
prima versione
Circuit:
* Ethernet shield attached to pins 5, 11, 12, 13
* RFM69
*/
#define RF69_COMPAT 1 //prima di Jeelib.h
#include <JeeLib.h>
#include <SPI.h>
#include <Ethernet.h>
// RF12 settings
#define MyNodeID 11 //GLCD = 10
#define freq RF12_868MHZ //frequency
#define group 46 //network group
// struttura dati Rx PayloadTX formato da 5 variabili integer
typedef struct {int uno, due, tre, quattro, cinque, sei, sette, otto;}PayloadTX;
PayloadTX emontx; // crea una variabile chiamata emontx tipo PayloadTX
int emontx_nodeID;
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 54, 111);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
// ============= variabili globali
int INFO, info, Qw;
int Lastpower;
//Array dati
unsigned char D_St[4];
unsigned long tempo;
unsigned long ciclo = 10000;
boolean stato = HIGH;
//zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
void setup() {
pinMode(5,OUTPUT);
pinMode(10,OUTPUT);
digitalWrite(5,HIGH); //disabilita ethernet
rf12_initialize(MyNodeID, freq,group);
digitalWrite(10,HIGH); //disabilita RFM69
Ethernet.init(5); // Pin del CS RJ45
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Ethernet WebServer Bozza-01 ");
Serial.print("Node: ");
Serial.print(MyNodeID);
Serial.print(" Freq: ");
Serial.print("868Mhz");
Serial.print(" Network: ");
Serial.println(group);
Serial.println("zzzzzzzzzzzzzzzzzzzzzzzzz");
// start the Ethernet connection and the server:
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 ");
}
// start the server
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
tempo = millis();
delay(100);
}
//zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
void loop() {
//--------------------------------------------------------------------
// Ricezione dati da RFM69
//--------------------------------------------------------------------
if (rf12_recvDone() && rf12_crc == 0 && (rf12_hdr & RF12_HDR_CTL) == 0) {
emontx=*(PayloadTX*) rf12_data;
emontx_nodeID=rf12_hdr & 0x1F; //extract node ID from received packet
if (emontx_nodeID == 7) D_St[0] = emontx.uno/100; // T collettore
if (emontx_nodeID == 7) D_St[1] = emontx.due/100; // T AccBasso
if (emontx_nodeID == 7) D_St[2] = emontx.tre/100; // T AccAlto
if (emontx_nodeID == 7) D_St[3] = emontx.quattro; // Stato ST
}
if ((millis()-tempo) > ciclo) {
// SOLARE TERMICO
Serial.println("--- SOLARE TERMICO ---");
Serial.print(" collettore: ");
Serial.print(D_St[0]);
Serial.println(" °C");
Serial.print(" boiler basso: ");
Serial.print(D_St[1]);
Serial.println(" °C");
Serial.print(" boiler alto: ");
Serial.print(D_St[2]);
Serial.println(" °C");
tempo = millis();
}
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an HTTP request ends with a blank line
bool currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the HTTP request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard HTTP response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 15 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.print("<body>");
//dati Webpage
client.print("boiler alto: ");
client.print(D_St[2]);
client.print(" gradi");
client.println("<br />");
client.println("</html>");
client.print("</body>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
} else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}