Hey John,
So I find why in this code I was not able to make it work with the usal ICSP connector.
The picture of the connector was upside down 
So the MISO was actually the GND 
So this code is working with the wifi since 24h, I will see if it crash.
As for my other project I can't put the code here, because it's split in 5 files, so I have to look if I can upload a zip file with all of it inside.
But I jst try with the RTD on the ICSP connector, and as soon as I get something from the srial1 it crash my whole board, and the WiFi is gone as code 255.
Here is the code that crash (entering the readVbus
// Settings for the VBus decoding
#define Sync 0xAA // Synchronisation bytes
#define FrameLength 6 // Framelength
#define FrameOffset 10 // Offset start of Frames
#define FrameSeptet 4 // Septet byte in Frame
#define SENSORNOTCONNECTED 8888 // Sometimes this might be 888 instead.
/*
67. DFA (0x0010) <= SOLTOP DeltaSol S2/S3 (0x7731)
Offset Size Mask Name Factor Unit
0 2 Temperature sensor 1 0.1 °C
2 2 Temperature sensor 2 0.1 °C
Frame 2
4 2 Temperature sensor 3 0.1 °C
6 2 Temperature sensor 4 0.1 °C
Frame 3
8 2 Temperature sensor 5 0.1 °C
10 2 Temperature sensor 6 0.1 °C
Frame 4
12 2 Temperature sensor 7 0.1 °C
14 2 Temperature sensor 8 0.1 °C
Frame 5
16 1 Pump speed R1 1 %
17 1 Pump speed R2 1 %
18 1 Pump speed R3 1 %
19 1 Relay byte 1
Frame 6
20 2 Heat 1 Wh
22 2 Heat 1000 Wh
Frame 7
24 2 Heat 1000000 Wh
26 1 Scheme 1
*/
unsigned char Buffer[100];
volatile unsigned char Bufferlength;
void initVbus(){
Serial1.begin(9600);
Serial.println(F("vBus Serial open"));
solar_temp=0.0; // S1
ecs_low_temp=0.0; // S2
ecs_high_temp=0.0; // S3
solar_ret_temp=0.0; // S4
}
bool readVbusValue() {
char c;
bool start,stop,quit;
start = true;
stop = false;
quit = false;
Bufferlength=0;
lastTimeTimer = 0;
lastTimeTimer = millis();
memset(0, Buffer, sizeof(Buffer));
Serial.println(F("vBus read"));
while ((!stop) and (!quit)) {
if (Serial1.available()) {
c=Serial1.read();
if (c == Sync || c==0xFFFFFFAA) {
if (start) {
start=false;
Bufferlength=0;
} else {
if (Bufferlength<20) {
lastTimeTimer = 0;
lastTimeTimer = millis();
Bufferlength=0;
} else
stop=true;
}
}
if ((!start) and (!stop)) {
Buffer[Bufferlength]=c;
Bufferlength++;
}
} // end if mySerial.available
if ((timerInterval > 0) && (millis() - lastTimeTimer > timerInterval ) ) {
quit=true;
}
} // end while loop
lastTimeTimer = 0;
Serial.println( F("Buffer: "));
for( int i=0;i <= Bufferlength; i++ ) {
Serial.print( Buffer[i], HEX);
Serial.print( " " );
}
Serial.println("");
if (!quit) {
Destination_address = Buffer[2] << 8;
Destination_address |= Buffer[1];
Source_address = Buffer[4] << 8;
Source_address |= Buffer[3];
ProtocolVersion = (Buffer[5]>>4) + (Buffer[5] &(1<<15));
Command = Buffer[7] << 8;
Command |= Buffer[6];
Framecnt = Buffer[8];
Checksum = Buffer[9]; //TODO check if Checksum is OK
Serial.println(F("---------------"));
Serial.print(F("Destination: "));
Serial.println(Destination_address, HEX);
Serial.print(F("Source: "));
Serial.println(Source_address, HEX);
Serial.print(F("Protocol Version: "));
Serial.println(ProtocolVersion);
Serial.print(F("Command: "));
Serial.println(Command, HEX);
Serial.print(F("Framecount: "));
Serial.println(Framecnt);
Serial.print(F("Checksum: "));
Serial.println(Checksum);
Serial.print(F("Bufferlength: "));
Serial.println(Bufferlength);
Serial.println(F("---------------"));
/*
15:38:33.340 -> Destination: 10
15:38:33.340 -> Source: 7731
15:38:33.340 -> Protocol Version: 1
15:38:33.340 -> Command: 100
15:38:33.340 -> Framecount: 7
15:38:33.378 -> Checksum: 47
15:38:33.378 -> Bufferlength: 52 Sometime 38 why
*/
// Only analyse Commands 0x100 = Packet Contains data for slave
// with correct length = 10 bytes for HEADER and 6 Bytes for each frame
// Buffer length has to be 52 to be correct (7*6=42 + 10=52)
// if ((Command==0x0100) and (Bufferlength==10+Framecnt*6)) {
if ( (Command==0x0100) ) {
//Only decode the data from the correct source address
//(There might be other VBus devices on the same bus).
decodeVbusFrame(Buffer);
Serial.println(F("------Values------"));
Serial.print(F("Solar : "));
Serial.println(solar_temp);
Serial.print(F("ECS Low: "));
Serial.println(ecs_low_temp);
Serial.print(F("ECS High: "));
Serial.println(ecs_high_temp);
Serial.print(F("Solar return: "));
Serial.println(solar_ret_temp);
Serial.print(F("Pump speed1: "));
Serial.println(PumpSpeed1, HEX);
Serial.print(F("Pump speed2: "));
Serial.println(PumpSpeed2, HEX);
Serial.print(F("Pump speed3: "));
Serial.println(PumpSpeed3, HEX);
Serial.print(F("Relay: "));
Serial.println(Relay, HEX);
Serial.print(F("Heat: "));
Serial.println(HeatQuantity);
Serial.print(F("Scheme: "));
Serial.println(Scheme, HEX);
/*
14:56:55.174 -> Pump speed1: 64
14:56:55.174 -> Pump speed2: 64
14:56:55.174 -> Pump speed3: 0
14:56:55.174 -> Relay: 6
32'390,643
afficher 32 390 KWH
*/
} else {
Serial.println(F("Error vBus "));
return false;
}
}
return true;
}
void decodeVbusFrame( unsigned char *frame ){
int FO;
// Serial.println(F("Now decoding for 0x7731"));
FO=FrameOffset;
Septet=frame[FO+FrameSeptet];
InjectSeptet(frame,FO,4);
solar_temp = CalcTemp(frame[FO+1], frame[FO]);
ecs_low_temp = CalcTemp(frame[FO+3], frame[FO+2]);
/*
18:50:22.981 -> Solar : 7.80
18:50:22.981 -> ECS Low: 26.30
*/
//******************* Frame 2 *******************
FO=FrameOffset+FrameLength;
Septet=Buffer[FO+FrameSeptet];
InjectSeptet(frame,FO,4);
ecs_high_temp = CalcTemp(frame[FO+1], frame[FO]);
solar_ret_temp = CalcTemp(frame[FO+3], frame[FO+2]);
/*
18:50:22.981 -> ECS High: 44.80
18:50:22.981 -> Solar return: 21.10
*/
//******************* Frame 3 *******************
FO=FrameOffset+FrameLength+2;
Septet=Buffer[FO+FrameSeptet];
InjectSeptet(frame,FO,4);
/*
Serial.print("Temp5 : ");
Serial.println(CalcTemp(frame[FO+1], frame[FO]));
Serial.print("Temp6 : ");
Serial.println(CalcTemp(frame[FO+3], frame[FO+2]));
*/
//******************* Frame 4 *******************
FO=FrameOffset+FrameLength+3;
Septet=Buffer[FO+FrameSeptet];
InjectSeptet(frame,FO,4);
/*
Serial.print("Temp7 : ");
Serial.println(CalcTemp(frame[FO+1], frame[FO]));
Serial.print("Temp8 : ");
Serial.println(CalcTemp(frame[FO+3], frame[FO+2]));
*/
//******************* Frame 5 *******************
FO=FrameOffset+FrameLength*4;
Septet=Buffer[FO+FrameSeptet];
InjectSeptet(frame,FO,4);
PumpSpeed1 = (frame[FO] & 0X7F);
PumpSpeed2 = (frame[FO+1] & 0X7F);
PumpSpeed3 = (frame[FO+2] & 0X7F);
Relay = frame[FO+3];
if( Relay == 6 ) Relay = 1; // 2 chauffage bas
/*
Serial.println( F("Frame 5"));
Serial.println( frame[FO], HEX);
Serial.println( frame[FO+1], HEX);
Serial.println( frame[FO+2], HEX);
Serial.println( frame[FO+3], HEX);
*/
/*
18:50:29.213 -> 0
18:50:29.213 -> 0
18:50:29.213 -> 0
18:50:29.213 -> 0
*/
//******************* Frame 6 *******************
FO=FrameOffset+FrameLength*5;
Septet=Buffer[FO+FrameSeptet];
InjectSeptet(frame,FO,4);
HeatQuantity=(frame[FO+1] << 8 | frame[FO])+(frame[FO+3] << 8| frame[FO+2])*1000;
Serial.println( F("Frame 6"));
Serial.println( frame[FO+1], HEX);
Serial.println( frame[FO+2], HEX);
Serial.println( frame[FO+3], HEX);
/*
18:50:29.213 -> D5
18:50:29.213 -> 0
18:50:29.213 -> 6
18:50:29.213 -> 1
*/
//******************* Frame 7 *******************
FO=FrameOffset+FrameLength*6;
Septet=Buffer[FO+FrameSeptet];
InjectSeptet(frame,FO,4);
HeatQuantity=HeatQuantity+(frame[FO+1] << 8 | frame[FO])*1000000;
Scheme = frame[FO+2];
Serial.println( F("Frame 7"));
Serial.println( frame[FO], HEX);
Serial.println( frame[FO+1], HEX);
Serial.println( frame[FO+2], HEX);
/*
* 32'390,643
afficher 32 390 KWH
18:50:29.213 -> 20
18:50:29.213 -> 0
18:50:29.213 -> 3
*/
}
// The following is needed for decoding the data
void InjectSeptet(unsigned char *Buffer, int Offset, int Length) {
for (unsigned int i = 0; i < Length; i++) {
if (Septet & (1 << i)) {
Buffer [Offset + i] |= 0x80;
}
}
}
// This function converts 2 data bytes to a temperature value.
float CalcTemp(int Byte1, int Byte2) {
int v;
v = Byte1 << 8 | Byte2; //bit shift 8 to left, bitwise OR
if (Byte1 == 0x00){
v= v & 0xFF;
}
if (Byte1 == 0xFF)
v = v - 0x10000;
if (v==SENSORNOTCONNECTED)
v=0;
return (float)((float) v * 0.1);
}
Entering inside the readVbusValue, and passing inside the if (!quit) crash.
I think of a buffer overflow, but can't find it anywhere
I try many Serial.print to catch the point where t crash, but can't find it, since it's when I call the sendData of this wifi part.
// wifi setting
int status = WL_IDLE_STATUS;
#define SERVER "192.168.1.16" // Host to contact
#define PORT 80 // 80 = HTTP default port
#define NODE "Solar"
// 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):
WiFiClient client;
void initWifi(){
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println(F("Communication with WiFi module failed!"));
// don't continue
while (true);
}
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println(F("Please upgrade the firmware"));
}
// attempt to connect to WiFi network:
while (status != WL_CONNECTED) {
Serial.print(F("Attempting to connect to SSID: "));
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 5 seconds for connection:
delay(5000);
}
Serial.println(F("Connected to WiFi"));
setColor( 0,0,255); // red until wifi is OK
printWifiStatus();
setColor( 0,255,0); // red until wifi is OK
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print(F("SSID: "));
Serial.println(WiFi.SSID());
// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print(F("IP Address: "));
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print(F("signal strength (RSSI):"));
Serial.print(rssi);
Serial.println(" dBm");
}
void sendData(){
Serial.println(F("\nStarting connection to server..."));
if ( WiFi.status() != WL_CONNECTED ) {
setColor( 255,0,0); // red until wifi is OK
Serial.println(WiFi.status());
initWifi();
}
// if you get a connection, report back via serial:
if (client.connected()) {
Serial.println(F("Client connected to server"));
}
if (client.connect(SERVER, PORT)) {
Serial.println(F("connected to server"));
// Make a HTTP request:
String HTTP_RQS = "GET /input/post?";
HTTP_RQS += "node=";
HTTP_RQS += NODE;
HTTP_RQS += "&json={";
HTTP_RQS += "ecs_high:";
HTTP_RQS += ecs_high_temp;
HTTP_RQS += ",ecs_low:";
HTTP_RQS += ecs_low_temp;
HTTP_RQS += ",solar_temp:";
HTTP_RQS += solar_temp;
HTTP_RQS += ",solar_ret:";
HTTP_RQS += solar_ret_temp;
HTTP_RQS += ",HeatQuantity:";
HTTP_RQS += HeatQuantity/1000;
HTTP_RQS += ",PumpSpeed:";
HTTP_RQS += PumpSpeed1;
HTTP_RQS += ",Relay:";
HTTP_RQS += Relay;
HTTP_RQS += ",ecs_in:";
HTTP_RQS += ecs_in_temp;
HTTP_RQS += ",pac_top:";
HTTP_RQS += pac_top_temp;
HTTP_RQS += ",pac_out:";
HTTP_RQS += pac_out_temp;
HTTP_RQS += ",pompeStatus:";
HTTP_RQS += pompeStatus;
HTTP_RQS += "}";
HTTP_RQS += "&apikey=29ceaa8fdad3f5268a2c1f7fd730ce2c";
HTTP_RQS += " HTTP/1.1\r\n";
HTTP_RQS += "Host:192.168.1.16";
HTTP_RQS += "\r\n\r\n";
// I try this part due to some report of error sending a String class, I try to send a char[]
int str_len = HTTP_RQS.length()+1;
char HTTP_QRY[str_len];
HTTP_RQS.toCharArray( HTTP_QRY, str_len);
client.println(HTTP_QRY);
Serial.println(HTTP_QRY);
delay(2000);
while (client.available()) {
char c = client.read();
Serial.write(c);
}
client.stop();
}
}
// set the RGB led
void setColor( uint8_t red, uint8_t green, uint8_t blue ) {
WiFiDrv::analogWrite(25, green/20); // GREEN
WiFiDrv::analogWrite(26, red/20); // RED
WiFiDrv::analogWrite(27, blue/20); // BLUE
}