Skip to content

Commit 4faf804

Browse files
committed
firts IOT commit
1 parent 160734e commit 4faf804

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

Firmware/Station/Station.ino

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/*
2-
Weather station based on NIXIE lamps
3-
Ver 6.5
2+
Weather IOT station based on NIXIE lamps
3+
Ver 0.1
44
55
Hardware required:
66
- Temperature sensor DS18B20
77
- Humidity sensor DHT11 (DHT12,DHT21,DHT22)
88
- 433 MHz radio receiver (MX-RM-5V)
9+
- ESP8266 on TX-RX
910
1011
Autor: V. Nezlo
1112
E-mail: vlladimirka@gmail.com
@@ -22,6 +23,7 @@ uint8_t k;
2223
#define ADDRESS 111
2324
//radio
2425

26+
#include <EasyTS.h>
2527
#include <OneWire.h>
2628
#include "DHT.h"
2729
#include <GyverTimer.h>
@@ -39,6 +41,7 @@ int digits[4]; // nums
3941
char display_mode; //mode
4042
char display_mode_temp; //for cathode healing
4143
char P=0; //for carhode healing
44+
int sendmode;
4245

4346
bool connection=0; //connection flag
4447
bool farenheit; //celsium or farenheit
@@ -73,6 +76,7 @@ GTimer Tcathode_switch(MS, 500);//cathode healing switch time
7376
GTimer Tled_lowbat(MS, 300);//led switching (low battery)
7477
GTimer Tled_noconn(MS, 800);//led switching (noconnection)
7578
GTimer Tvalidate_radio(MS, 600000); //time to validate data
79+
GTimer Tsend_data(MS,15000); //ThingSpeak send data timer
7680

7781
const int bright = 1; // Value of "bright" of indicators
7882

@@ -102,9 +106,8 @@ void check_radio(void){
102106

103107
//dot1f = 1;
104108

105-
connection=TRUE;
109+
connection=true;
106110
Tvalidate_radio.reset();
107-
//Serial.println("Connection established");
108111
}
109112

110113
}
@@ -113,9 +116,7 @@ void check_radio(void){
113116
void check_validate_radio(void){
114117
if (Tvalidate_radio.isReady())
115118
{
116-
connection=FALSE;
117-
//Serial.print("Connection lost and value is ");
118-
//Serial.println(connection);
119+
connection=false;
119120
}
120121
}
121122

@@ -225,11 +226,10 @@ void pin_set(void){
225226
}
226227

227228
void led_blinking(void){
228-
if (connection==FALSE) {
229+
if (connection==false) {
229230
if (Tled_noconn.isReady())
230231
{
231232
dot1f = !dot1f;
232-
//Serial.println("blink!");
233233
}
234234
}
235235
else if (voltage<370){
@@ -253,8 +253,6 @@ void check_sensors_first(void){
253253
void check_humidity(void){
254254
float h = dht.readHumidity();
255255
humi=h*10;
256-
//Serial.print("Humidity is ");
257-
//Serial.println(humi);
258256
}
259257

260258
void conversion_start(void){
@@ -264,13 +262,11 @@ void conversion_start(void){
264262
}
265263

266264
void conversion_read(void){
267-
//Serial.println("Im start lagging boiii");
268265
ds.reset(); //
269266
ds.write(0xCC);
270267
ds.write(0xBE);
271268
ds_data[0] = ds.read();
272269
ds_data[1] = ds.read();
273-
//Serial.println("Im done");
274270

275271
float temperature = ((ds_data[1] << 8) | ds_data[0]) * 0.0625;
276272

@@ -283,8 +279,6 @@ void conversion_read(void){
283279
if (tempin>0) tempin_z = 7;
284280
else tempin_z = 8;
285281

286-
//Serial.print("In temperature is ");
287-
//Serial.println(tempin);
288282
}
289283

290284
void displayMode(void){
@@ -383,7 +377,6 @@ void displayMode(void){
383377
{
384378
display_mode = display_mode_temp; //restore mode after healing
385379
Tmode_switch.resume();
386-
//Serial.println("Display mode restored");
387380
P=0;
388381
}
389382
}
@@ -394,7 +387,6 @@ void displayMode(void){
394387
void switchMode(void){
395388
if (Tmode_switch.isReady())
396389
{
397-
//Serial.println("Display mode switched");
398390
switch (display_mode)
399391
{
400392
case 0:
@@ -410,7 +402,6 @@ if (Tmode_switch.isReady())
410402
break;
411403

412404
case 2:
413-
//Serial.println("Current mode is out,switching to in");
414405
display_mode=0;
415406
delay(30);
416407
break;
@@ -425,26 +416,45 @@ void cathodeHeal(void){
425416
display_mode_temp = display_mode;//save display_mode value
426417
display_mode=3;
427418
Tmode_switch.stop();
428-
//Serial.println("Cathode healing enable");
429419
}
430420

431421
}
432422

423+
void iot_senddata(){
424+
char String_senddata[30];
425+
if (Tsend_data.isReady()){
426+
switch(sendmode){
427+
case 0:
428+
sprintf (String_senddata, "%u.%u", tempin/10, tempin%10);
429+
easyts.send("VF5VWODQICAG5BG3", 1, String_senddata);
430+
sendmode=1;
431+
break;
432+
case 1:
433+
sprintf (String_senddata, "%d", humi);
434+
easyts.send("VF5VWODQICAG5BG3", 2, String_senddata);
435+
sendmode=2;
436+
break;
437+
case 2:
438+
sprintf (String_senddata, "%u.%u", tempout/10, tempout%10);
439+
easyts.send("VF5VWODQICAG5BG3", 3, String_senddata);
440+
sendmode=0;
441+
break;
442+
}
443+
}
444+
}
445+
433446
void setup(){
434447

435-
Serial.begin(9600);
448+
Serial.begin(115200);
449+
easyts.std_connect("Nokia 7.1","12345678");
436450
radio_init();
437451
pin_set();
438452
dht.begin();
439453
delay(300);
440454
check_sensors_first();//first run with delay
441455
check_humidity();
442456
farenheit = digitalRead(A0);
443-
444457

445-
//Serial.print("farenheit is ");
446-
//Serial.println(farenheit);
447-
448458
display_mode=0;
449459
}
450460

@@ -455,6 +465,7 @@ void loop(){
455465
check_validate_radio();
456466
led_blinking();
457467
cathodeHeal();
468+
iot_senddata();
458469
}
459470

460471

0 commit comments

Comments
 (0)