Ciao Uwe,
probabilmente non mi sono spiegato benissimo, semplicemente, ciò che volevo sapere, era capire se c'era un modo di verificare se arduino ha ancora "capacità di calcolo" prima di provare lo sketch.
In ogni caso il mio programmino è questo (si deve interfacciare al server domotico e quello sotto è solo un esempio):
//For serial set to 0 and for Ethernet set to 1
#define ISIP 0
#if ISIP == 1
#include <EEPROM.h>
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#endif
// Pin impulso
const int getpulsepin = 2;
// variabili
float assorbimento = 0.0;
unsigned long startime = 0;
unsigned long durata = 0;
int stato = 0;
int pinval = 0;
int durata2 = 0;
//Address of the board.
const byte BoardAdd = 2;
#if ISIP == 1
byte mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02};
//************Do not change anything in Here*****************
int FromHS[10]; // *
boolean IsConnected = false; // *
#if ISIP == 1 // *
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; // *
EthernetUDP Udp; // *
const unsigned int ServerPort = 8888; // *
#endif // *
void(* resetFunc) (void) = 0; // *
//***********************************************************
void setup() {
HSSetup();
pinMode(getpulsepin, INPUT); // pin del sensore
digitalWrite (getpulsepin, HIGH);//abilito resistenza pull up
}
void loop() {
#if ISIP == 1
IsUDP();
#endif
pinval = digitalRead(getpulsepin); // legge il pin del sensore
if ((stato == 1) & (pinval == 0)) { // punto di transizione
durata = millis() - startime; // calcola la durata della pulsazione
startime = millis(); // setta il nuovo tempo di partenza
assorbimento = 3600.0/durata*10; // calcola consumo
SendToHS(1,assorbimento);
durata2 = durata;
SendToHS(2,durata2);
//stato = pinval;
}
stato = pinval; // imposta lo stato uguale alla lettura del pin
/*connection status*/
if (IsConnected == true) {
}
}
const char* Version = "API1";
byte Byte1,Byte2,Byte3;
int Byte4,Byte5;
void HSSetup() {
#if ISIP == 1
if (EEpromVersion!=22) {
ServerIP=HomeseerIP;
EEPROM.write(2,ServerIP[0]);
EEPROM.write(3,ServerIP[1]);
EEPROM.write(4,ServerIP[2]);
EEPROM.write(5,ServerIP[3]);
EEPROM.write(250,22);
EEpromVersion=22;
}
Ethernet.begin(mac,ip);
Udp.begin(localPort);
Udp.setTimeout(0);
delay(1000);
SendConnect();
#else
Serial.begin(115200);
Serial.flush();
Serial.print("Connect ");
Serial.println(BoardAdd);
#endif
IsConnected = false;
}
void SendConnect()
{
#if ISIP == 0
Serial.print("Connect ");
Serial.println(BoardAdd);
#else
Udp.print("Connect ");
Udp.print(BoardAdd);
Udp.endPacket();
if (ServerIP!=HomeseerIP) {
Udp.print("Connect ");
Udp.print(BoardAdd);
Udp.endPacket();
}
#endif
}
#if ISIP == 1
void IsUDP(){
int packetSize = Udp.parsePacket();
if(packetSize)
{
IPAddress remote = Udp.remoteIP();
Byte1 =Udp.parseInt();
Udp.read();
Byte2 =Udp.read();
Byte3 =Udp.parseInt();
Byte4 =Udp.parseInt();
Byte5 =Udp.parseInt();
DataEvent();
}
}
#else
void serialEvent() {
while (Serial.available() > 0) {
delay(17);
Byte1 = Serial.parseInt();
Serial.read();
Byte2 = Serial.read();
Byte3 = Serial.parseInt();
Byte4 = Serial.parseInt();
Byte5 = Serial.parseInt();
DataEvent();
}
}
#endif
void DataEvent() {
if (Byte1 == BoardAdd) {
switch (Byte2) {
case 'c':
IsConnected = true;
#if ISIP == 1
if (Udp.remoteIP() != ServerIP) {
ServerIP=Udp.remoteIP();
EEPROM.write(2,ServerIP[0]);
EEPROM.write(3,ServerIP[1]);
EEPROM.write(4,ServerIP[2]);
EEPROM.write(5,ServerIP[3]);
}
#endif
break;
case 'C':
#if ISIP == 1
Udp.beginPacket(Udp.remoteIP(), ServerPort);
Udp.print("Version ");
Udp.print(BoardAdd);
Udp.print(" ");
Udp.print(Version);
Udp.println(" HS3");
Udp.endPacket();
Udp.beginPacket(Udp.remoteIP(), ServerPort);
delay(100);
Udp.print("Connected ");
Udp.println(BoardAdd);
Udp.endPacket();
#else
Serial.print("Version ");
Serial.print(BoardAdd);
Serial.print(" ");
Serial.print(Version);
Serial.println(" HS3");
delay(100);
Serial.print("Connected ");
Serial.println(BoardAdd);
#endif
delay(100);
IsConnected = false;
break;
case 'K':
delay(200);
#if ISIP == 1
Udp.beginPacket(Udp.remoteIP(), ServerPort);
Udp.print("Alive ");
Udp.println(BoardAdd);
Udp.endPacket();
if (Udp.remoteIP() != ServerIP) {
ServerIP=Udp.remoteIP();
EEPROM.write(2,ServerIP[0]);
EEPROM.write(3,ServerIP[1]);
EEPROM.write(4,ServerIP[2]);
EEPROM.write(5,ServerIP[3]);
}
#else
Serial.print("Alive ");
Serial.println(BoardAdd);
#endif
break;
case 'r':
delay(200);
resetFunc(); //call reset
break;
case 'O':
FromHS[Byte3] = Byte4;
break;
case 'D':
IsConnected = false;
break;
}
}
}
void SendToHS(byte Device, long Data){
if (IsConnected == true) {
#if ISIP == 1
Udp.beginPacket(Udp.remoteIP(), ServerPort);
Udp.print(BoardAdd);
Udp.print(Data);
Udp.endPacket();
#else
Serial.print(BoardAdd);
Serial.print(" API ");
Serial.print(Device);
Serial.print(" ");
Serial.println(Data);
#endif
}
}
void SendToHS(byte Device, int Data){
if (IsConnected == true) {
#if ISIP == 1
Udp.beginPacket(Udp.remoteIP(), ServerPort);
Udp.print(BoardAdd);
Udp.print(" API ");
Udp.print(Device);
Udp.print(" ");
Udp.print(Data);
Udp.endPacket();
#else
Serial.print(BoardAdd);
Serial.print(" API ");
Serial.print(Device);
Serial.print(" ");
Serial.println(Data);
#endif
}
}
void SendToHS(byte Device, float Data){
if (IsConnected == true) {
#if ISIP == 1
Udp.beginPacket(Udp.remoteIP(), ServerPort);
Udp.print(BoardAdd);
Udp.print(" API ");
Udp.print(Device);
Udp.print(" ");
Udp.print(Data);
Udp.endPacket();
#else
Serial.print(BoardAdd);
Serial.println(Data);
#endif
}
}
Come dicevo, mi piacerebbe sapere se c'è un modo per capire (senza dover fare girare il programma in test) se arduino ha altra capacità di calcolo.