I create local Blynk server and he work perfect,but i have problem with arduino…He goes offline randomly.I search forum for similar topics but i can’t find solution.When i reset arduino he work randomly time.
I use iteaduino mega+enc28j60 Ethernet module+five DS18B20+k type max6675 thermocouple
• Blynk Library version 0.6.0
•CODE
#include <UIPEthernet.h>
#include <BlynkSimpleUIPEthernet.h> // This part is for Ethernet stuff
#include <OneWire.h>
#include <max6675.h>
// OneWire DS18S20, DS18B20, DS1822 Temperature Example
//
// http://www.pjrc.com/teensy/td_libs_OneWire.html
//
// The DallasTemperature library can do all this work for you!
// http://milesburton.com/Dallas_Temperature_Control_Library
int thermoDO = 4; // SO of MAX6675 module to D4
int thermoCS = 5; // CS of MAX6675 module to D5
int thermoCLK = 6; // SCK of MAX6675 module to D6
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
OneWire ds(7); // on pin 7 (a 4.7K resistor is necessary) make sure you change this from the original pin 10 to an unused pin.
int adr;
float s1;
float s2;
float s3;
float s4;
float s5;
float s6;
float s7;
char auth[] = "7-y6TDfWCh0ZK7uGnAVORCvLkgOTTRGa"; // Put your Auth Token here. (see Step 3 above)
void setup()
{
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth, IPAddress(192,168,1,7), 8080); // Here your Arduino connects to the Blynk Cloud.
}
BLYNK_READ(V12){
Blynk.virtualWrite(V12, thermocouple.readCelsius());
}
void loop()
{
Blynk.run(); // All the Blynk Magic happens here...
// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
if ( !ds.search(addr)) {
Serial.println("No more addresses.");
Serial.println();
ds.reset_search();
delay(250);
return;
}
// Serial.print("ROM =");
for( i = 0; i < 8; i++) { //we need to drop 8 bytes of data
}
adr = (addr[7]);
if (OneWire::crc8(addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return;
}
Serial.println();
ds.reset();
ds.select(addr);
ds.write(0x44, 1); // start conversion, with parasite power on at the end
delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for ( i = 0; i < 9; i++) { // we need 9 bytes to drop off
data[i] = ds.read();
}
Serial.println();
// Convert the data to actual temperature
// because the result is a 16 bit signed integer, it should
// be stored to an "int16_t" type, which is always 16 bits
// even when compiled on a 32 bit processor.
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// "count remain" gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
// at lower res, the low bits are undefined, so let's zero them
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
//// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
if(adr == 242) { //replace ??? with value of sensor number 1
s1 = celsius; //change celsius to fahrenheit if you prefer output in Fahrenheit
}
if(adr == 58) { //replace ??? with value of sensor number 2
s2 = celsius; //change celsius to fahrenheit if you prefer output in Fahrenheit
}
if(adr == 144) { //replace ??? with value of sensor number 3
s3 = celsius; //change celsius to fahrenheit if you prefer output in Fahrenheit
}
if(adr == 37) { //replace ??? with value of sensor number 4
s4 = celsius; //change celsius to fahrenheit if you prefer output in Fahrenheit
}
if(adr == 21) { //replace ??? with value of sensor number 5
s5 = celsius; //change celsius to fahrenheit if you prefer output in Fahrenheit
}
//if(adr == ???) { //replace ??? with value of sensor number 6
// s6 = celsius; //change celsius to fahrenheit if you prefer output in Fahrenheit
// }
// if(adr == ???) { //replace ??? with value of sensor number 7. If you use more sensors just add them below this section. Delete unused sections, or you will get "expected primary-expression before '?' token"
// s7 = celsius; //change celsius to fahrenheit if you prefer output in Fahrenheit
// }
Serial.print(" Sensor 1 = ");
Serial.print(s1);
Serial.print(" Sensor 2 = ");
Serial.print(s2);
Serial.print(" Sensor 3 = ");
Serial.print(s3);
Serial.print(" Sensor 4 = ");
Serial.print(s4);
Serial.print(" Sensor 5 = ");
Serial.print(s5);
Serial.print(" Sensor 6 = ");
Serial.print(s6);
Serial.print(" Sensor 7 = "); //add or delete if you need more or less
Serial.print(s7);
Serial.print("Deg C = ");
Serial.println(thermocouple.readCelsius());
Blynk.virtualWrite(V5, s1);
Blynk.virtualWrite(V6, s2);
Blynk.virtualWrite(V7, s3);
Blynk.virtualWrite(V8, s4);
Blynk.virtualWrite(V9, s5);
Blynk.virtualWrite(V10, s6);
Blynk.virtualWrite(V11, s7);//add or delete if you need more or less
}.```