The Particle make the connection for 10 seconds breathing light blue and then turn in breathing green.
When eliminating all relations with Blynk all is fine.
The following code ran for 2 weeks error free till I made the share from my phone.
Following is the code in Photon:
/********************************************
- BeachTech
-
-
-
-
- This is a temperature logger using PHOTON and Thingspeak
-
- Use of HTTPCLIENT library as external
- Use of DS18B20 library library as local
- Use of PARTICLE-ONEWIRE library as local
-
- Thingspeak API key is set in the string directly and not as a variable
- See publishData() function
-
- DS18B20 probe is set to pin D2
-
- ******************************************/
// This #include statement was automatically added by the Particle IDE.
#include âblynk/blynk.hâ
// This #include statement was automatically added by the Particle IDE.
#include âDS18B20.hâ
// This #include statement was automatically added by the Particle IDE.
#include âParticle-OneWire.hâ
// This #include statement was automatically added by the Particle IDE.
#include âHttpClient/HttpClient.hâ
DS18B20 ds18b20 = DS18B20(D2); //Sets Pin D2 for Water Temp Sensor
int led = D7;
int state = 0;
char szInfo[64];
float pubTemp;
double celsius;
unsigned int Metric_Publish_Rate = 30000;
unsigned int MetricnextPublishTime;
int DS18B20nextSampleTime;
int DS18B20_SAMPLE_INTERVAL = 2500;
int dsAttempts = 0;
/web/
HttpClient http;
// Headers currently need to be set at init, useful for API keys etc.
http_header_t headers[] = {
{ âAcceptâ , â/â},
{ âUser-agentâ, âParticle HttpClientâ},
{ NULL, NULL } // NOTE: Always terminate headers will NULL
};
http_request_t request;
http_response_t response;
char auth[] = âmyAuthcodeâ; //blynk auth code not shown
void setup() {
Blynk.begin(auth);//connect to Blynk
while (Blynk.connect() == false) {
// Wait until connected...
}
Time.zone(-5);
Particle.syncTime();
pinMode(D2, INPUT_PULLUP);//Pullup make no difference
Particle.variable("tempHotWater", &celsius, DOUBLE);
Serial.begin(115200);
pinMode(led, OUTPUT);//Blue LED
}
void loop() {
if (millis() > DS18B20nextSampleTime){
digitalWrite(led, HIGH);
getTemp();
digitalWrite(led, LOW);
//Blynk region
Blynk.run();
//End Blynk region
}
if (millis() > MetricnextPublishTime){
Serial.println(âPublishing now.â);
publishData();
}
}
void publishData(){
if(!ds18b20.crcCheck()){
return;
}
sprintf(szInfo, â%2.2fâ, celsius);
Particle.publish(âdsTmpâ, szInfo, PRIVATE);
MetricnextPublishTime = millis() + Metric_Publish_Rate;
//ThingsSpeak region
//code not shown
//End ThingsSpeak region
//Blynk region
sprintf(szInfo, "%2.2f\n\r", celsius);
Blynk.virtualWrite(0, szInfo); // Write values to the app display
sprintf(szInfo, "%2.2f", celsius);
Blynk.virtualWrite(1, szInfo); // Write values to the app gauge
Blynk.run();
//End Blynk region
}
void getTemp(){
if(!ds18b20.search()){
ds18b20.resetsearch();
celsius = ds18b20.getTemperature();
Serial.println(celsius);
while (!ds18b20.crcCheck() && dsAttempts < 4){
Serial.println(âCaught bad value.â);
dsAttempts++;
Serial.print("Attempts to Read: ");
Serial.println(dsAttempts);
if (dsAttempts == 3){
delay(1000);
}
ds18b20.resetsearch();
celsius = ds18b20.getTemperature();
continue;
}
dsAttempts = 0;
//fahrenheit = ds18b20.convertToFahrenheit(celsius);
DS18B20nextSampleTime = millis() + DS18B20_SAMPLE_INTERVAL;
//Serial.println(farenheit);
}
}