CITAZIONE (jackie2_it, 13/03/2014 12:50:58 )
Quote:Cmq posta poi lo sketch che utilizzi così ci possiamo lavorare su
Ecco lo sketch che uso!
[code]
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
byte server[] = {
144,76,107,68};
//char server[] = "solare.altervista.org";
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192,168,1,177);
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
// Setta le varibili contenenti le letture dal regolatore di carica
String strURL = "";
int tensione_pannello;
int corrente_pannello;
int tensione_batteria;
int corrente_batteria;
int tensione_carico;
int corrente_carico;
int data_long = 0;
int data[50];
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
//Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
}
// give the Ethernet shield a second to initialize:
pinMode(5, OUTPUT);
delay(1000);
}
;
void update(){
Serial.write(0xAA);
Serial.write(0x55);
Serial.write(0xAA);
Serial.write(0x55);
Serial.write(0xAA);
Serial.write(0x55);
Serial.write(0xEB);
Serial.write(0x90);
Serial.write(0xEB);
Serial.write(0x90);
Serial.write(0xEB);
Serial.write(0x90);
Serial.write(0x16); // versione indico 1
Serial.write(0xA0); // Richiedo al regolatore i dati in tempo reale.
Serial.write(0x00); // Lunghezza dei dati
Serial.write(0xB1); // Check sum
Serial.write(0xA7); // Check sum
Serial.write(0x7F);
delay(500);
if (Serial.available() > 40) {
digitalWrite(5, HIGH);
data_long = Serial.available();
for (int n=0; n < data_long; n++){
data[n] = Serial.read();
}
}
tensione_pannello = (data[12]<<8)