Created
February 26, 2020 15:45
-
-
Save vimarsh244/d3d09b8dcfb82ff1f4a4e30a9d3687a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Developed by: Eduardo Zola - Zola Lab 2018 - www.zolalab.com.br - egzola@gmail.com | |
Ultrasonic Data Communication | |
Modified by Vimarsh - vimarsh.space | |
To send recieved weather data to IOT app sevice Bly | |
*/ | |
int pos = 0; | |
unsigned char CH = 0; | |
unsigned int bits1 = 0; | |
boolean capture = false; | |
#define BLYNK_PRINT Serial | |
#include <ESP8266WiFi.h> | |
#include <BlynkSimpleEsp8266.h> | |
// You should get Auth Token in the Blynk App. | |
// Go to the Project Settings (nut icon). | |
char auth[] = "YourAuthToken"; | |
// Your WiFi credentials. | |
// Set password to "" for open networks. | |
char ssid[] = "ssid"; | |
char pass[] = "psk"; | |
void setup() | |
{ | |
Serial.begin(115200); | |
pinMode(5, INPUT_PULLUP); | |
Blynk.begin(auth, ssid, pass); | |
} | |
void loop() | |
{ | |
Blynk.run(); | |
if (digitalRead(5)) | |
{ | |
bits1 = 0; | |
unsigned long deltaT = millis(); | |
while (millis() - deltaT <= 10) if (digitalRead(5)) bits1 ++; | |
//Serial.println(bits1); | |
String s; | |
if (capture) | |
{ | |
boolean b = 0; | |
if (bits1 > 290 && bits1 < 600) b = 0; | |
if (bits1 > 20 && bits1 < 290) b = 1; | |
if (b) bitSet(CH, 7 - pos); else bitClear(CH, 7 - pos); | |
//Serial.print(b); | |
pos++; | |
if (pos == 8) | |
{ | |
if ((char)CH == '#') | |
send_data(s); | |
s += (char)CH; | |
//Serial.print((char)CH); | |
pos = 0; | |
capture = false; | |
} | |
} | |
if (bits1 > 600) | |
{ | |
capture = true; | |
pos = 0; | |
} | |
} | |
} | |
void send_data(String s) { | |
String buff = ""; int k = 1; | |
String temp, humid, pressure; | |
for (int i = 0; i < s.length(); i++) { | |
if (s[i] != ',') | |
buff += s[i]; | |
if (s[i] == ',') { | |
//buff.resize(buff.size() - 1); This works with std:string not String :-( | |
if (k == 1) | |
temp = buff; | |
else if (k == 2) | |
pressure = buff; | |
else if (k == 3) | |
humid = buff; | |
k++; | |
buff = ""; | |
} | |
} | |
Blynk.virtualWrite(V1, temp); | |
Blynk.virtualWrite(V2, pressure); | |
Blynk.virtualWrite(V1, humid); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment