Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Дмитрий Решетей
/
OREGON
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit ce68d530
authored
Sep 16, 2020
by
Дмитрий Решетей
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update wifi_reciver.ino
1 parent
31ba33e6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
691 additions
and
693 deletions
wifi_reciver/wifi_reciver.ino
wifi_reciver/wifi_reciver.ino
View file @
ce68d53
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Скетч для передачи показаний с беспроводных датчиков Oregon Scientific THN132N или THGN132N на сервис “Народный Мониторинг” (narodmon.ru)
//Скетч для передачи показаний с беспроводных датчиков Oregon Scientific THN132N или THGN132N на сервис “Народный Мониторинг” (narodmon.ru)
//с помощью Arduino-совместимых плат на основе ESP8266 (Wemos D1, NodeMCU).
//с помощью Arduino-совместимых плат на основе ESP8266 (Wemos D1, NodeMCU).
//Для подключения необходимы:
//Для подключения необходимы:
//- Сам датчик Oregon Scientific THN132N, THGN132N, THGN123 и т.п.,
//- Сам датчик Oregon Scientific THN132N, THGN132N, THGN123 и т.п.,
//- ПРоцессорная плата на основе ESP8266 (Wemos D1 или NodeMCU),
//- ПРоцессорная плата на основе ESP8266 (Wemos D1 или NodeMCU),
//- Приёмник OOK 433Мгц (Питание 3В, подключается к D7 процессорной платы),
//- Приёмник OOK 433Мгц (Питание 3В, подключается к D7 процессорной платы),
//- WiFi подключение к Интернет
//- WiFi подключение к Интернет
//- Arduino IDE с установленной поддержкой ESP8266-совместимых устройств и библиотекой Oregon_NR
//- Arduino IDE с установленной поддержкой ESP8266-совместимых устройств и библиотекой Oregon_NR
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <Oregon_NR_MY.h>
#include <Oregon_NR_MY.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <WiFiClient.h>
//#include <ESP8266WebServer.h>
//#include <ESP8266WebServer.h>
//#include <ESP8266mDNS.h>
//#include <ESP8266mDNS.h>
//#include <Wire.h> // Подключаем библиотеку Wire
//#include <Wire.h> // Подключаем библиотеку Wire
//#include <Adafruit_BME280.h> // Подключаем библиотеку Adafruit_BME280
//#include <Adafruit_BME280.h> // Подключаем библиотеку Adafruit_BME280
//#include <Adafruit_Sensor.h> // Подключаем библиотеку Adafruit_Sensor
//#include <Adafruit_Sensor.h> // Подключаем библиотеку Adafruit_Sensor
/*#include <SPI.h>
/*#include <SPI.h>
#define BME_SCK 14
#define BME_SCK 14
#define BME_MISO 12
#define BME_MISO 12
#define BME_MOSI 13
#define BME_MOSI 13
#define BME_CS 15*/
#define BME_CS 15*/
//Режимы работы
//Режимы работы
#define TEST_MODE false //Режим отладки (данные на narodmon.ru не отсылаются)
#define TEST_MODE false //Режим отладки (данные на narodmon.ru не отсылаются)
//#undef TEST_MODE
//#undef TEST_MODE
#define SEND_INTERVAL 120000 //350000 - 5 min //Как часто отсылать данные на сервер
#define SEND_INTERVAL 120000 //350000 - 5 min //Как часто отсылать данные на сервер
//#define SEND_INTERVAL 12000
//#define SEND_INTERVAL 12000
#define CONNECT_TIMEOUT 10000 //Время ожидания соединения
#define CONNECT_TIMEOUT 10000 //Время ожидания соединения
#define DISCONNECT_TIMEOUT 10000 //Время ожидания отсоединения
#define DISCONNECT_TIMEOUT 10000 //Время ожидания отсоединения
//#define mac "#FF:FF:FF:FF:FF:FF" //МАС-адрес на narodmon.ru d8-f1-5b-07-1c-0b
//#define mac "#FF:FF:FF:FF:FF:FF" //МАС-адрес на narodmon.ru
//#define mac "#D8:F1:5B:07:1C:0B" //МАС-адрес на narodmon.ru d8-f1-5b-07-1c-0b
#define mac "#ESP8266FFFFFFFF" //ID или MAC на narodmon.ru
#define mac "#ESP826677671C0B" //МАС-адрес на narodmon.ru d8-f1-5b-07-1c-0b
//#define mac "#ESP8266FFFFFFFF" //ID или MAC на narodmon.ru
const
char
*
ssid
=
"ASUS"
;
//Параметры входа в WiFi
const
char
*
password
=
"123456789"
;
const
char
*
ssid
=
"ASUS"
;
//Параметры входа в WiFi
//настройки сети для хитрого маршрута
const
char
*
password
=
"123456789"
;
//IPAddress ip(192,168,137,17); //статический IP
//настройки сети для хитрого маршрута
//IPAddress gateway(192,168,137,1);
//IPAddress ip(192,168,137,17); //статический IP
//IPAddress subnet(255,255,255,0);
//IPAddress gateway(192,168,137,1);
//IPAddress dns1(8,8,8,8);
//IPAddress subnet(255,255,255,0);
//ESP8266WebServer server(80);
//IPAddress dns1(8,8,8,8);
//****************************************************************************************
//ESP8266WebServer server(80);
//****************************************************************************************
//Oregon_NR oregon(13, 13, 2, true);// Приёмник 433Мгц подключён к D7 (GPIO13), Светодиод на D2 подтянут к +пит.
Oregon_NR
oregon
(
15
,
15
,
3
,
true
);
// Приёмник 433Мгц подключён к D7 (GPIO13), Светодиод на D2 подтянут к +пит.
//Oregon_NR oregon(13, 13, 2, true);// Приёмник 433Мгц подключён к D7 (GPIO13), Светодиод на D2 подтянут к +пит.
Oregon_NR
oregon
(
15
,
15
,
3
,
true
);
// Приёмник 433Мгц подключён к D7 (GPIO13), Светодиод на D2 подтянут к +пит.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Массивы для хранения полученных данных для датчиков Oregon:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
float
r_tmp
[
3
];
//Температура
//Массивы для хранения полученных данных для датчиков Oregon:
float
r_hmdty
[
3
];
//Влажность. Если = 101 - значит нет данных
float
r_tmp
[
3
];
//Температура
bool
r_bat
[
3
],
bat_pcr
,
bat_wrt
;
//Флаг батареи
float
r_hmdty
[
3
];
//Влажность. Если = 101 - значит нет данных
bool
r_isreceived
[
3
];
//Флаг о том, что по данному каналу приходил хоть один правильный пакет и данные актуальны
bool
r_bat
[
3
],
bat_pcr
,
bat_wrt
;
//Флаг батареи
word
r_type
[
3
];
//Тип датчика
bool
r_isreceived
[
3
];
//Флаг о том, что по данному каналу приходил хоть один правильный пакет и данные актуальны
unsigned
long
rcv_time
[
3
];
// времена прихода последних пакетов
word
r_type
[
3
];
//Тип датчика
float
number_of_receiving
[
3
];
//сколько пакетов получено в процессе сбора данных
unsigned
long
rcv_time
[
3
];
// времена прихода последних пакетов
float
wa_speed
;
// Скорость ветра
float
number_of_receiving
[
3
];
//сколько пакетов получено в процессе сбора данных
float
mw_speed
;
// Макс скорость ветра
float
wa_speed
;
// Скорость ветра
float
w_d
;
// Направление ветра
float
mw_speed
;
// Макс скорость ветра
float
r_rate
;
// Интенсивность осадков - дождя
float
w_d
;
// Направление ветра
float
r_total
;
// Колличество осадков - дождя
float
r_rate
;
// Интенсивность осадков - дождя
float
tempC
;
// Температура
float
r_total
;
// Колличество осадков - дождя
float
humidity
;
// Влажность
float
tempC
;
// Температура
float
pressureHgmm
;
// Давление мм Рт.ст
float
humidity
;
// Влажность
float
pressureHgmm
;
// Давление мм Рт.ст
//****************************************************************************************
//****************************************************************************************
#define BLUE_LED 2 //Индикация подключения к WiFi
#define GREEN_LED 14 //Индикатор успешной доставки пакета а народмон
#define BLUE_LED 2 //Индикация подключения к WiFi
#define RED_LED 255 //Индикатор ошибки доставки пакета на народмон
#define GREEN_LED 14 //Индикатор успешной доставки пакета а народмон
// #define BME280_ADDRESS 0x77
#define RED_LED 255 //Индикатор ошибки доставки пакета на народмон
// Adafruit_BME280 bme;
// #define BME280_ADDRESS 0x77
// Adafruit_BME280 bme;
//Параметоы соединения с narodmon:
//IPAddress nardomon_server(94,19,113,221);
//Параметоы соединения с narodmon:
char
narodomon_server
[]
=
"narodmon.ru"
;
//IPAddress nardomon_server(94,19,113,221);
int
port
=
8283
;
char
narodomon_server
[]
=
"narodmon.ru"
;
WiFiClient
client
;
//Клиент narodmon
int
port
=
8283
;
WiFiServer
server
(
80
);
// Указываем порт Web-сервера
WiFiClient
client
;
//Клиент narodmon
String
header
;
WiFiServer
server
(
80
);
// Указываем порт Web-сервера
const
unsigned
long
postingInterval
=
SEND_INTERVAL
;
String
header
;
unsigned
long
lastConnectionTime
=
0
;
const
unsigned
long
postingInterval
=
SEND_INTERVAL
;
boolean
lastConnected
=
false
;
unsigned
long
lastConnectionTime
=
0
;
unsigned
long
cur_mark
;
boolean
lastConnected
=
false
;
unsigned
long
cur_mark
;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//SETUP//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//SETUP//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void
setup
()
{
void
setup
()
{
pinMode
(
BLUE_LED
,
OUTPUT
);
pinMode
(
GREEN_LED
,
OUTPUT
);
pinMode
(
BLUE_LED
,
OUTPUT
);
pinMode
(
RED_LED
,
OUTPUT
);
pinMode
(
GREEN_LED
,
OUTPUT
);
// pinMode(1, INPUT);
pinMode
(
RED_LED
,
OUTPUT
);
// pinMode(2, INPUT);
// pinMode(1, INPUT);
// pinMode(3, INPUT);
// pinMode(2, INPUT);
// pinMode(4, INPUT);
// pinMode(3, INPUT);
// pinMode(5, INPUT);
// pinMode(4, INPUT);
digitalWrite
(
2
,
LOW
);
// pinMode(5, INPUT);
digitalWrite
(
1
,
LOW
);
digitalWrite
(
2
,
LOW
);
digitalWrite
(
15
,
LOW
);
digitalWrite
(
1
,
LOW
);
digitalWrite
(
15
,
LOW
);
/////////////////////////////////////////////////////
//Инициализация памяти
/////////////////////////////////////////////////////
for
(
int
i
=
0
;
i
<
3
;
i
++
)
//Инициализация памяти
{
for
(
int
i
=
0
;
i
<
3
;
i
++
)
rcv_time
[
i
]
=
7000000
;
{
r_isreceived
[
i
]
=
0
;
rcv_time
[
i
]
=
7000000
;
number_of_receiving
[
i
]
=
0
;
r_isreceived
[
i
]
=
0
;
}
number_of_receiving
[
i
]
=
0
;
}
/////////////////////////////////////////////////////
//Запуск Serial-ов
/////////////////////////////////////////////////////
Serial
.
begin
(
115200
);
//Запуск Serial-ов
Serial
.
println
(
""
);
Serial
.
begin
(
115200
);
if
(
TEST_MODE
)
Serial
.
println
(
"Test mode"
);
Serial
.
println
(
""
);
if
(
TEST_MODE
)
Serial
.
println
(
"Test mode"
);
/////////////////////////////////////////////////////
//Запуск Wifi
/////////////////////////////////////////////////////
wifi_connect
();
//Запуск Wifi
/////////////////////////////////////////////////////
wifi_connect
();
/////////////////////////////////////////////////////
digitalWrite
(
BLUE_LED
,
HIGH
);
if
(
test_narodmon_connection
()){
digitalWrite
(
BLUE_LED
,
HIGH
);
digitalWrite
(
GREEN_LED
,
HIGH
);
if
(
test_narodmon_connection
()){
digitalWrite
(
RED_LED
,
LOW
);
digitalWrite
(
GREEN_LED
,
HIGH
);
}
digitalWrite
(
RED_LED
,
LOW
);
else
{
}
digitalWrite
(
GREEN_LED
,
LOW
);
else
{
digitalWrite
(
RED_LED
,
HIGH
);
digitalWrite
(
GREEN_LED
,
LOW
);
}
digitalWrite
(
RED_LED
,
HIGH
);
}
//вкючение прослушивания радиоканала
oregon
.
start
();
//вкючение прослушивания радиоканала
oregon
.
receiver_dump
=
false
;
oregon
.
start
();
//Если не распознаются последние байты принятого пакета можно попробовать подстроить частоту захвата данных
oregon
.
receiver_dump
=
false
;
oregon
.
timing_correction
=
0
;
// коррекция частоты завхвата данных. Обычно достаоточно подобрать значение от -5 до 5
//Если не распознаются последние байты принятого пакета можно попробовать подстроить частоту захвата данных
oregon
.
decode_method
=
1
;
//или использовать метод 3 для декодирования
oregon
.
timing_correction
=
0
;
// коррекция частоты завхвата данных. Обычно достаоточно подобрать значение от -5 до 5
oregon
.
decode_method
=
1
;
//или использовать метод 3 для декодирования
//подключение датчика давления, температуры и влажности BME280
// Wire.begin(D1, D2);
//подключение датчика давления, температуры и влажности BME280
// Wire.setClock(100000);
// Wire.begin(D1, D2);
// if (!bme.begin(BME280_ADDRESS )) { // Проверка инициализации датчика
// Wire.setClock(100000);
// Serial.println("Could not find a valid BME280 sensor, check wiring!"); // Печать, об ошибке инициализации.
// if (!bme.begin(BME280_ADDRESS )) { // Проверка инициализации датчика
// while (1) delay(3000); // Зацикливаем
// Serial.println("Could not find a valid BME280 sensor, check wiring!"); // Печать, об ошибке инициализации.
// }
// while (1) delay(3000); // Зацикливаем
// Wire.begin();
// }
// Wire.setClock(100000);
// Wire.begin();
// if (!bme.begin(BME280_ADDRESS ))
// Wire.setClock(100000);
// {
// if (!bme.begin(BME280_ADDRESS ))
// Serial.println("Could not find a valid BME280 sensor, check wiring!");
// {
// while (1)
// Serial.println("Could not find a valid BME280 sensor, check wiring!");
// {
// while (1)
// yield();
// {
// delay(3000);
// yield();
// }
// delay(3000);
// }
// }
//
// }
server
.
begin
();
//
}
server
.
begin
();
//////////////////////////////////////////////////////////////////////
}
//LOOP//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//LOOP//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void
loop
()
{
void
loop
()
// if (!bme.begin(BME280_ADDRESS ))
{
// {
// if (!bme.begin(BME280_ADDRESS ))
// Serial.println("Could not find a valid BME280 sensor, check wiring!");
// {
//// while (1)
// Serial.println("Could not find a valid BME280 sensor, check wiring!");
// {
//// while (1)
// yield();
// {
// // delay(3000);
// yield();
// }
// // delay(3000);
// }
// }
WiFiClient
client
=
server
.
available
();
// Получаем данные, посылаемые клиентом
// }
WiFiClient
client
=
server
.
available
();
// Получаем данные, посылаемые клиентом
//////////////////////////////////////////////////////////////////////
//Защита от подвисаний/////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//Защита от подвисаний/////////////////////////////////////////
if
(
micros
()
>
0xFFF00000
)
while
(
micros
()
<
0xFFF00000
);
//Висим секунду до переполнения
//////////////////////////////////////////////////////////////////////
if
(
millis
()
>
0xFFFFFC0F
)
while
(
millis
()
<
0xFFFFFC0F
);
//Висим секунду до переполнения
if
(
micros
()
>
0xFFF00000
)
while
(
micros
()
<
0xFFF00000
);
//Висим секунду до переполнения
if
(
millis
()
>
0xFFFFFC0F
)
while
(
millis
()
<
0xFFFFFC0F
);
//Висим секунду до переполнения
//////////////////////////////////////////////////////////////////////
//Проверка полученных данных,/////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//Проверка полученных данных,/////////////////////////////////////////
bool
is_a_data_to_send
=
false
;
//////////////////////////////////////////////////////////////////////
for
(
int
i
=
0
;
i
<
3
;
i
++
){
bool
is_a_data_to_send
=
false
;
if
(
r_isreceived
[
i
])
is_a_data_to_send
=
1
;
// Есть ли данные для отправки?
for
(
int
i
=
0
;
i
<
3
;
i
++
){
}
if
(
r_isreceived
[
i
])
is_a_data_to_send
=
1
;
// Есть ли данные для отправки?
}
is_a_data_to_send
=
1
;
//Отладка!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
is_a_data_to_send
=
1
;
//Отладка!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//////////////////////////////////////////////////////////////////////
//Отправка данных на narodmon.ru/////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//Отправка данных на narodmon.ru/////////////////////////////////////
//////////////////////////////////////////////////////////////////////
if
(
millis
()
-
lastConnectionTime
>
postingInterval
&&
is_a_data_to_send
)
{
//Обязательно отключить прослушивание канала
if
(
millis
()
-
lastConnectionTime
>
postingInterval
&&
is_a_data_to_send
)
{
oregon
.
stop
();
//Обязательно отключить прослушивание канала
digitalWrite
(
BLUE_LED
,
HIGH
);
oregon
.
stop
();
if
(
send_data
()){
digitalWrite
(
BLUE_LED
,
HIGH
);
digitalWrite
(
GREEN_LED
,
HIGH
);
if
(
send_data
()){
digitalWrite
(
RED_LED
,
LOW
);
digitalWrite
(
GREEN_LED
,
HIGH
);
}
digitalWrite
(
RED_LED
,
LOW
);
else
{
}
digitalWrite
(
GREEN_LED
,
LOW
);
else
{
digitalWrite
(
RED_LED
,
HIGH
);
digitalWrite
(
GREEN_LED
,
LOW
);
}
digitalWrite
(
RED_LED
,
HIGH
);
oregon
.
start
();
}
}
oregon
.
start
();
}
//////////////////////////////////////////////////////////////////////
//Захват пакета,//////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//Захват пакета,//////////////////////////////////////////////
oregon
.
capture
(
0
);
// (1) - отладка отображается в консоль
//////////////////////////////////////////////////////////////////////
//
oregon
.
capture
(
0
);
// (1) - отладка отображается в консоль
//Захваченные данные годны до следующего вызова capture
//
//Захваченные данные годны до следующего вызова capture
//////////////////////////////////////////////////////////////////////
//ОБработка полученного пакета//////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
if
(
oregon
.
captured
)
//ОБработка полученного пакета//////////////////////////////////////////////
{
if
(
oregon
.
captured
)
//Вывод информации в Serial
{
if
((
oregon
.
sens_type
==
THGN132
||
oregon
.
sens_type
==
THN132
)
&&
oregon
.
crc_c
){
//Вывод информации в Serial
Serial
.
print
(
"TIME:
\t
"
);
if
((
oregon
.
sens_type
==
THGN132
||
oregon
.
sens_type
==
THN132
)
&&
oregon
.
crc_c
){
Serial
.
print
(
millis
()
/
1000
);
Serial
.
print
(
"TIME:
\t
"
);
Serial
.
print
(
"sec
\t
"
);
Serial
.
print
(
millis
()
/
1000
);
//if (oregon.sens_type == THGN132) for (int q = 0;q < PACKET_LENGTH - 2; q++) Serial.print(oregon.packet[q], HEX);
Serial
.
print
(
"sec
\t
"
);
if
(
oregon
.
sens_type
==
THGN132
)
for
(
int
q
=
0
;
q
<
PACKET_LENGTH
-
1
;
q
++
)
Serial
.
print
(
oregon
.
packet
[
q
],
HEX
);
//if (oregon.sens_type == THGN132) for (int q = 0;q < PACKET_LENGTH - 2; q++) Serial.print(oregon.packet[q], HEX);
//if (oregon.sens_type == THN132) for (int q = 0;q < PACKET_LENGTH - 4; q++) Serial.print(oregon.packet[q], HEX);
if
(
oregon
.
sens_type
==
THGN132
)
for
(
int
q
=
0
;
q
<
PACKET_LENGTH
-
1
;
q
++
)
Serial
.
print
(
oregon
.
packet
[
q
],
HEX
);
if
(
oregon
.
sens_type
==
THN132
)
for
(
int
q
=
0
;
q
<
PACKET_LENGTH
-
4
;
q
++
)
Serial
.
print
(
oregon
.
packet
[
q
],
HEX
);
//if (oregon.sens_type == THN132) for (int q = 0;q < PACKET_LENGTH - 4; q++) Serial.print(oregon.packet[q], HEX);
Serial
.
print
(
" TYPE: "
);
if
(
oregon
.
sens_type
==
THN132
)
for
(
int
q
=
0
;
q
<
PACKET_LENGTH
-
4
;
q
++
)
Serial
.
print
(
oregon
.
packet
[
q
],
HEX
);
if
(
oregon
.
sens_type
==
THGN132
)
Serial
.
print
(
"THGN132N"
);
Serial
.
print
(
" TYPE: "
);
if
(
oregon
.
sens_type
==
THN132
)
Serial
.
print
(
"THN132N "
);
if
(
oregon
.
sens_type
==
THGN132
)
Serial
.
print
(
"THGN132N"
);
Serial
.
print
(
" CHNL: "
);
if
(
oregon
.
sens_type
==
THN132
)
Serial
.
print
(
"THN132N "
);
Serial
.
print
(
oregon
.
sens_chnl
);
Serial
.
print
(
" CHNL: "
);
if
(
oregon
.
sens_tmp
>
0
&&
oregon
.
sens_tmp
<
10
)
Serial
.
print
(
" TMP: "
);
Serial
.
print
(
oregon
.
sens_chnl
);
if
(
oregon
.
sens_tmp
<
0
&&
oregon
.
sens_tmp
>-
10
)
Serial
.
print
(
" TMP: "
);
if
(
oregon
.
sens_tmp
>
0
&&
oregon
.
sens_tmp
<
10
)
Serial
.
print
(
" TMP: "
);
if
(
oregon
.
sens_tmp
<=
-
10
)
Serial
.
print
(
" TMP:"
);
if
(
oregon
.
sens_tmp
<
0
&&
oregon
.
sens_tmp
>-
10
)
Serial
.
print
(
" TMP: "
);
if
(
oregon
.
sens_tmp
>=
10
)
Serial
.
print
(
" TMP: "
);
if
(
oregon
.
sens_tmp
<=
-
10
)
Serial
.
print
(
" TMP:"
);
Serial
.
print
(
oregon
.
sens_tmp
,
1
);
if
(
oregon
.
sens_tmp
>=
10
)
Serial
.
print
(
" TMP: "
);
Serial
.
print
(
"C "
);
Serial
.
print
(
oregon
.
sens_tmp
,
1
);
if
(
oregon
.
sens_type
==
THGN132
)
{
Serial
.
print
(
"C "
);
Serial
.
print
(
"HUM: "
);
if
(
oregon
.
sens_type
==
THGN132
)
{
Serial
.
print
(
oregon
.
sens_hmdty
,
1
);
Serial
.
print
(
"HUM: "
);
Serial
.
print
(
"%"
);
Serial
.
print
(
oregon
.
sens_hmdty
,
1
);
}
Serial
.
print
(
"%"
);
}
Serial
.
print
(
" BAT: "
);
if
(
oregon
.
sens_battery
)
Serial
.
print
(
"F "
);
else
Serial
.
print
(
"e "
);
Serial
.
print
(
" BAT: "
);
Serial
.
print
(
"ID: "
);
if
(
oregon
.
sens_battery
)
Serial
.
print
(
"F "
);
else
Serial
.
print
(
"e "
);
Serial
.
print
(
oregon
.
sens_id
,
HEX
);
Serial
.
print
(
"ID: "
);
//Serial.print(" PACKETS: ");
Serial
.
print
(
oregon
.
sens_id
,
HEX
);
//Serial.print(oregon.packets_received);
//Serial.print(" PACKETS: ");
//Serial.print(" PROC. TIME: ");
//Serial.print(oregon.packets_received);
//Serial.print(oregon.work_time);
//Serial.print(" PROC. TIME: ");
//Serial.println("ms ");
//Serial.print(oregon.work_time);
Serial
.
println
(
""
);
//Serial.println("ms ");
Serial
.
println
(
""
);
byte
_chnl
=
oregon
.
sens_chnl
-
1
;
number_of_receiving
[
_chnl
]
++
;
byte
_chnl
=
oregon
.
sens_chnl
-
1
;
r_type
[
_chnl
]
=
oregon
.
sens_type
;
number_of_receiving
[
_chnl
]
++
;
r_bat
[
_chnl
]
=
oregon
.
sens_battery
;
r_type
[
_chnl
]
=
oregon
.
sens_type
;
r_isreceived
[
_chnl
]
=
1
;
r_bat
[
_chnl
]
=
oregon
.
sens_battery
;
r_tmp
[
_chnl
]
=
r_tmp
[
_chnl
]
*
((
number_of_receiving
[
_chnl
]
-
1
)
/
number_of_receiving
[
_chnl
])
+
oregon
.
sens_tmp
/
number_of_receiving
[
_chnl
];
r_isreceived
[
_chnl
]
=
1
;
r_hmdty
[
_chnl
]
=
r_hmdty
[
_chnl
]
*
((
number_of_receiving
[
_chnl
]
-
1
)
/
number_of_receiving
[
_chnl
])
+
oregon
.
sens_hmdty
/
number_of_receiving
[
_chnl
];
r_tmp
[
_chnl
]
=
r_tmp
[
_chnl
]
*
((
number_of_receiving
[
_chnl
]
-
1
)
/
number_of_receiving
[
_chnl
])
+
oregon
.
sens_tmp
/
number_of_receiving
[
_chnl
];
rcv_time
[
_chnl
]
=
millis
();
r_hmdty
[
_chnl
]
=
r_hmdty
[
_chnl
]
*
((
number_of_receiving
[
_chnl
]
-
1
)
/
number_of_receiving
[
_chnl
])
+
oregon
.
sens_hmdty
/
number_of_receiving
[
_chnl
];
}
rcv_time
[
_chnl
]
=
millis
();
}
if
(
!
oregon
.
crc_c
&&
oregon
.
packets_received
)
{
if
(
!
oregon
.
crc_c
&&
oregon
.
packets_received
)
Serial
.
println
(
"TIME:
\t
"
);
{
Serial
.
print
(
millis
()
/
1000
);
Serial
.
println
(
"TIME:
\t
"
);
Serial
.
print
(
"sec
\t
"
);
Serial
.
print
(
millis
()
/
1000
);
for
(
int
q
=
0
;
q
<
PACKET_LENGTH
-
1
;
q
++
)
{
Serial
.
print
(
"sec
\t
"
);
if
(
oregon
.
valid_p
[
q
]
>=
0x0F
)
Serial
.
print
(
oregon
.
packet
[
q
],
HEX
);
for
(
int
q
=
0
;
q
<
PACKET_LENGTH
-
1
;
q
++
)
{
else
Serial
.
print
(
"x"
);
if
(
oregon
.
valid_p
[
q
]
>=
0x0F
)
Serial
.
print
(
oregon
.
packet
[
q
],
HEX
);
}
else
Serial
.
print
(
"x"
);
Serial
.
println
(
" CORRUPTED PACKET "
);
}
}
Serial
.
println
(
" CORRUPTED PACKET "
);
}
}
}
if
(
oregon
.
sens_type
==
WGR800
&&
oregon
.
crc_c
){
Serial
.
println
(
"
\t
"
);
if
(
oregon
.
sens_type
==
WGR800
&&
oregon
.
crc_c
){
float
wnddata
;
Serial
.
println
(
"
\t
"
);
Serial
.
print
(
" TYPE: "
);
float
wnddata
;
Serial
.
print
(
"WGR800"
);
Serial
.
print
(
" TYPE: "
);
Serial
.
print
(
" AVG WS: "
);
Serial
.
print
(
"WGR800"
);
Serial
.
print
(
oregon
.
sens_avg_ws
,
1
);
Serial
.
print
(
" AVG WS: "
);
Serial
.
print
(
"m/s MAX WS: "
);
Serial
.
print
(
oregon
.
sens_avg_ws
,
1
);
Serial
.
print
(
oregon
.
sens_max_ws
,
1
);
Serial
.
print
(
"m/s MAX WS: "
);
Serial
.
print
(
"m/s WDIR: "
);
//N = 0, E = 4, S = 8, W = 12
Serial
.
print
(
oregon
.
sens_max_ws
,
1
);
Serial
.
print
(
oregon
.
sens_wdir
);
Serial
.
print
(
"m/s WDIR: "
);
//N = 0, E = 4, S = 8, W = 12
Serial
.
print
(
" BAT: "
);
Serial
.
print
(
oregon
.
sens_wdir
);
if
(
oregon
.
sens_battery
)
Serial
.
print
(
"F "
);
else
Serial
.
print
(
"e "
);
Serial
.
print
(
" BAT: "
);
Serial
.
print
(
"ID: "
);
if
(
oregon
.
sens_battery
)
Serial
.
print
(
"F "
);
else
Serial
.
print
(
"e "
);
Serial
.
print
(
oregon
.
sens_id
,
HEX
);
Serial
.
print
(
"ID: "
);
Serial
.
print
(
oregon
.
sens_id
,
HEX
);
//####
// float wa_speed[3]; // Скорость ветра
//####
// float mw_speed[3]; // Макс скорость ветра
// float wa_speed[3]; // Скорость ветра
// bool w_direction[3]; // Направление ветра
// float mw_speed[3]; // Макс скорость ветра
// float r_rate[3]; // Интенсивность осадков - дождя
// bool w_direction[3]; // Направление ветра
// float r_total[3]; // Колличество осадков - дождя
// float r_rate[3]; // Интенсивность осадков - дождя
//####
// float r_total[3]; // Колличество осадков - дождя
byte
_chnl
=
oregon
.
sens_chnl
-
1
;
//####
number_of_receiving
[
_chnl
]
++
;
byte
_chnl
=
oregon
.
sens_chnl
-
1
;
r_type
[
_chnl
]
=
oregon
.
sens_type
;
number_of_receiving
[
_chnl
]
++
;
r_bat
[
_chnl
]
=
oregon
.
sens_battery
;
r_type
[
_chnl
]
=
oregon
.
sens_type
;
r_isreceived
[
_chnl
]
=
1
;
r_bat
[
_chnl
]
=
oregon
.
sens_battery
;
//r_tmp[_chnl] = r_tmp[_chnl] * ((number_of_receiving[_chnl] - 1) / number_of_receiving[_chnl]) + oregon.sens_tmp / number_of_receiving[_chnl];
r_isreceived
[
_chnl
]
=
1
;
bat_wrt
=
oregon
.
sens_battery
;
//r_tmp[_chnl] = r_tmp[_chnl] * ((number_of_receiving[_chnl] - 1) / number_of_receiving[_chnl]) + oregon.sens_tmp / number_of_receiving[_chnl];
wa_speed
=
oregon
.
sens_avg_ws
;
bat_wrt
=
oregon
.
sens_battery
;
mw_speed
=
oregon
.
sens_max_ws
;
wa_speed
=
oregon
.
sens_avg_ws
;
// translate rumb to direction in DEG
mw_speed
=
oregon
.
sens_max_ws
;
switch
(
oregon
.
sens_wdir
)
{
// translate rumb to direction in DEG
case
0
:
{
w_d
=
360
;
break
;}
// 0-N
switch
(
oregon
.
sens_wdir
)
{
case
1
:
{
w_d
=
22.5
;
break
;}
// 1-NNE
case
0
:
{
w_d
=
360
;
break
;}
// 0-N
case
2
:
{
w_d
=
45
;
break
;}
// 2-NE
case
1
:
{
w_d
=
22.5
;
break
;}
// 1-NNE
case
3
:
{
w_d
=
67.5
;
break
;}
// 3-ENE
case
2
:
{
w_d
=
45
;
break
;}
// 2-NE
case
4
:
{
w_d
=
90
;
break
;}
// 4-E
case
3
:
{
w_d
=
67.5
;
break
;}
// 3-ENE
case
5
:
{
w_d
=
112.5
;
break
;}
// 5-ESE
case
4
:
{
w_d
=
90
;
break
;}
// 4-E
case
6
:
{
w_d
=
135
;
break
;}
// 6-SE
case
5
:
{
w_d
=
112.5
;
break
;}
// 5-ESE
case
7
:
{
w_d
=
157.5
;
break
;}
// 7-SSE
case
6
:
{
w_d
=
135
;
break
;}
// 6-SE
case
8
:
{
w_d
=
180
;
break
;}
// 8-S
case
7
:
{
w_d
=
157.5
;
break
;}
// 7-SSE
case
9
:
{
w_d
=
202.5
;
break
;}
// 9-SSW
case
8
:
{
w_d
=
180
;
break
;}
// 8-S
case
10
:
{
w_d
=
225
;
break
;}
// A-SW
case
9
:
{
w_d
=
202.5
;
break
;}
// 9-SSW
case
11
:
{
w_d
=
247.5
;
break
;}
// B-WSW
case
10
:
{
w_d
=
225
;
break
;}
// A-SW
case
12
:
{
w_d
=
270
;
break
;}
// C-W
case
11
:
{
w_d
=
247.5
;
break
;}
// B-WSW
case
13
:
{
w_d
=
292.5
;
break
;}
// D-WNW
case
12
:
{
w_d
=
270
;
break
;}
// C-W
case
14
:
{
w_d
=
315
;
break
;}
// E-NW
case
13
:
{
w_d
=
292.5
;
break
;}
// D-WNW
case
15
:
{
w_d
=
337.5
;
break
;}
// F-NNW
case
14
:
{
w_d
=
315
;
break
;}
// E-NW
}
case
15
:
{
w_d
=
337.5
;
break
;}
// F-NNW
rcv_time
[
_chnl
]
=
millis
();
}
}
rcv_time
[
_chnl
]
=
millis
();
if
(
oregon
.
sens_type
==
PCR800
&&
oregon
.
crc_c
){
}
Serial
.
println
(
"
\t
"
);
if
(
oregon
.
sens_type
==
PCR800
&&
oregon
.
crc_c
){
float
wnddata
;
Serial
.
println
(
"
\t
"
);
Serial
.
print
(
" TYPE: "
);
float
wnddata
;
Serial
.
print
(
"PCR800,"
);
Serial
.
print
(
" TYPE: "
);
Serial
.
print
(
" RAIN RATE: "
);
Serial
.
print
(
"PCR800,"
);
Serial
.
print
(
oregon
.
rain_rate
,
4
);
Serial
.
print
(
" RAIN RATE: "
);
//Serial.print(oregon.rain_rate, 3);
Serial
.
print
(
oregon
.
rain_rate
,
4
);
//Serial.print(" | ");
//Serial.print(oregon.rain_rate, 3);
//Serial.print(oregon.rain_rate, 1);
//Serial.print(" | ");
Serial
.
print
(
" mm/h, "
);
//Serial.print(oregon.rain_rate, 1);
Serial
.
print
(
" TOTAL RAIN: "
);
Serial
.
print
(
" mm/h, "
);
Serial
.
print
(
oregon
.
total_rain
,
5
);
Serial
.
print
(
" TOTAL RAIN: "
);
//Serial.print(" | ");
Serial
.
print
(
oregon
.
total_rain
,
5
);
//Serial.print(oregon.total_rain, DEC);
//Serial.print(" | ");
Serial
.
print
(
" mm, "
);
//Serial.print(oregon.total_rain, DEC);
Serial
.
print
(
" BAT: "
);
Serial
.
print
(
" mm, "
);
if
(
oregon
.
sens_battery
)
Serial
.
print
(
"F "
);
else
Serial
.
print
(
"e "
);
Serial
.
print
(
" BAT: "
);
Serial
.
print
(
"ID: "
);
if
(
oregon
.
sens_battery
)
Serial
.
print
(
"F "
);
else
Serial
.
print
(
"e "
);
Serial
.
print
(
oregon
.
sens_id
,
HEX
);
Serial
.
print
(
"ID: "
);
//Serial.print(oregon.sens_battery, HEX);
Serial
.
print
(
oregon
.
sens_id
,
HEX
);
//Serial.print(oregon.oregon_data);
//Serial.print(oregon.sens_battery, HEX);
//Serial.print("checksumm = ");
//Serial.print(oregon.oregon_data);
//Serial.print(oregon.crc_c, HEX);
//Serial.print("checksumm = ");
//Serial.print(oregon.sens_id);
//Serial.print(oregon.crc_c, HEX);
bat_pcr
=
oregon
.
sens_battery
;
//Serial.print(oregon.sens_id);
r_rate
=
oregon
.
rain_rate
;
bat_pcr
=
oregon
.
sens_battery
;
r_total
=
oregon
.
total_rain
;
r_rate
=
oregon
.
rain_rate
;
}
r_total
=
oregon
.
total_rain
;
// tempC = bme.readTemperature();
}
// humidity = bme.readHumidity();
// tempC = bme.readTemperature();
// pressureHgmm = bme.readPressure() / 133.322;
// humidity = bme.readHumidity();
// pressureHgmm = bme.readPressure() / 133.322;
// Print to serial monitor
// printToSerial(tempC, humidity, pressureHgmm);
// Print to serial monitor
////////////////////////////////////////////
// printToSerial(tempC, humidity, pressureHgmm);
/// JSON client ////////////////////////////
////////////////////////////////////////////
if
(
client
)
{
/// JSON client ////////////////////////////
Serial
.
println
(
"New Client."
);
// Отправка "Новый клиент"
if
(
client
)
{
String
currentLine
=
""
;
// Создаем строку для хранения входящих данных от клиента
Serial
.
println
(
"New Client."
);
// Отправка "Новый клиент"
while
(
client
.
connected
())
{
// Пока есть соединение с клиентом
String
currentLine
=
""
;
// Создаем строку для хранения входящих данных от клиента
if
(
client
.
available
())
{
// Если клиент активен
while
(
client
.
connected
())
{
// Пока есть соединение с клиентом
char
c
=
client
.
read
();
// Считываем посылаемую информацию в переменную "с"
if
(
client
.
available
())
{
// Если клиент активен
Serial
.
write
(
c
);
// Отправка в Serial port
char
c
=
client
.
read
();
// Считываем посылаемую информацию в переменную "с"
header
+=
c
;
Serial
.
write
(
c
);
// Отправка в Serial port
if
(
c
==
'\n'
)
{
// Вывод HTML страницы
header
+=
c
;
if
(
currentLine
.
length
()
==
0
)
{
if
(
c
==
'\n'
)
{
// Вывод HTML страницы
client
.
println
(
"HTTP/1.1 200 OK"
);
// Стандартный заголовок HTTP
if
(
currentLine
.
length
()
==
0
)
{
client
.
println
(
"Access-Control-Allow-Origin: *"
);
// разрешаю cross-origin запросы
client
.
println
(
"HTTP/1.1 200 OK"
);
// Стандартный заголовок HTTP
client
.
println
(
"Content-type:text/html "
);
client
.
println
(
"Access-Control-Allow-Origin: *"
);
// разрешаю cross-origin запросы
client
.
println
(
"Connection: close"
);
// Соединение будет закрыто после завершения ответа
client
.
println
(
"Content-type:text/html "
);
client
.
println
(
"Refresh: 13"
);
// Автоматическое обновление каждые 13 сек
client
.
println
(
"Connection: close"
);
// Соединение будет закрыто после завершения ответа
client
.
println
();
client
.
println
(
"Refresh: 13"
);
// Автоматическое обновление каждые 13 сек
// Формирую данные в формате JSON
client
.
println
();
client
.
print
(
"{
\"
w_d
\"
:
\"
"
);
// Формирую данные в формате JSON
client
.
print
(
w_d
);
client
.
print
(
"{
\"
w_d
\"
:
\"
"
);
client
.
print
(
"
\"
,
\"
wa_speed
\"
:
\"
"
);
client
.
print
(
w_d
);
client
.
print
(
wa_speed
);
client
.
print
(
"
\"
,
\"
wa_speed
\"
:
\"
"
);
client
.
print
(
"
\"
,
\"
mw_speed
\"
:
\"
"
);
client
.
print
(
wa_speed
);
client
.
print
(
mw_speed
);
client
.
print
(
"
\"
,
\"
mw_speed
\"
:
\"
"
);
client
.
println
(
"
\"
}"
);
client
.
print
(
mw_speed
);
client
.
println
();
client
.
println
(
"
\"
}"
);
break
;
client
.
println
();
}
else
{
break
;
currentLine
=
""
;
}
else
{
}
currentLine
=
""
;
}
else
if
(
c
!=
'\r'
)
{
}
currentLine
+=
c
;
}
else
if
(
c
!=
'\r'
)
{
}
currentLine
+=
c
;
}
}
}
}
header
=
""
;
}
client
.
stop
();
header
=
""
;
Serial
.
println
(
"Client disconnected."
);
client
.
stop
();
Serial
.
println
(
""
);
Serial
.
println
(
"Client disconnected."
);
}
Serial
.
println
(
""
);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
//***************************************************************************************************************************************
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//***************************************************************************************************************************************
void
wifi_connect
()
{
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void
wifi_connect
()
{
Serial
.
println
();
Serial
.
print
(
"Connecting to "
);
Serial
.
println
();
Serial
.
print
(
ssid
);
Serial
.
print
(
"Connecting to "
);
unsigned
long
cur_mark
=
millis
();
Serial
.
print
(
ssid
);
bool
blink
=
0
;
unsigned
long
cur_mark
=
millis
();
//WiFi.config(ip, gateway, subnet, dns1); ////////// comment if dhcp
bool
blink
=
0
;
WiFi
.
begin
(
ssid
,
password
);
//WiFi.config(ip, gateway, subnet, dns1); ////////// comment if dhcp
do
{
WiFi
.
begin
(
ssid
,
password
);
while
(
WiFi
.
status
()
!=
WL_CONNECTED
)
{
do
{
if
(
blink
)
{
while
(
WiFi
.
status
()
!=
WL_CONNECTED
)
{
digitalWrite
(
BLUE_LED
,
LOW
);
if
(
blink
)
{
digitalWrite
(
BLUE_LED
,
LOW
);
}
else
{
}
digitalWrite
(
BLUE_LED
,
HIGH
);
else
{
digitalWrite
(
BLUE_LED
,
HIGH
);
}
blink
=
!
blink
;
}
delay
(
500
);
blink
=
!
blink
;
Serial
.
print
(
"."
);
delay
(
500
);
//Подключаемся слишком долго. Переподключаемся....
Serial
.
print
(
"."
);
if
((
millis
()
-
cur_mark
)
>
CONNECT_TIMEOUT
){
//Подключаемся слишком долго. Переподключаемся....
blink
=
0
;
if
((
millis
()
-
cur_mark
)
>
CONNECT_TIMEOUT
){
digitalWrite
(
BLUE_LED
,
HIGH
);
blink
=
0
;
WiFi
.
disconnect
();
digitalWrite
(
BLUE_LED
,
HIGH
);
delay
(
3000
);
WiFi
.
disconnect
();
cur_mark
=
millis
();
delay
(
3000
);
WiFi
.
begin
(
ssid
,
password
);
cur_mark
=
millis
();
}
WiFi
.
begin
(
ssid
,
password
);
}
}
}
while
(
WiFi
.
status
()
!=
WL_CONNECTED
);
}
}
while
(
WiFi
.
status
()
!=
WL_CONNECTED
);
Serial
.
println
(
""
);
Serial
.
println
(
"WiFi connected"
);
Serial
.
println
(
""
);
Serial
.
println
(
WiFi
.
localIP
());
Serial
.
println
(
"WiFi connected"
);
Serial
.
println
(
WiFi
.
localIP
());
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool
test_narodmon_connection
()
{
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if
(
client
.
connect
(
narodomon_server
,
port
))
{
bool
test_narodmon_connection
()
{
client
.
println
(
"##"
);
if
(
client
.
connect
(
narodomon_server
,
port
))
{
cur_mark
=
millis
();
client
.
println
(
"##"
);
do
{
cur_mark
=
millis
();
wait_timer
(
10
);
do
{
if
((
millis
()
-
cur_mark
)
>
CONNECT_TIMEOUT
)
{
wait_timer
(
10
);
Serial
.
println
(
"narodmon.ru is not responding"
);
if
((
millis
()
-
cur_mark
)
>
CONNECT_TIMEOUT
)
{
client
.
stop
();
Serial
.
println
(
"narodmon.ru is not responding"
);
return
0
;
client
.
stop
();
}
return
0
;
}
while
(
!
client
.
connected
());
}
Serial
.
println
(
"narodmon.ru is attainable"
);
}
while
(
!
client
.
connected
());
client
.
stop
();
Serial
.
println
(
"narodmon.ru is attainable"
);
return
1
;
client
.
stop
();
}
return
1
;
else
{
}
Serial
.
println
(
"connection to narodmon.ru failed"
);
else
{
client
.
stop
();
Serial
.
println
(
"connection to narodmon.ru failed"
);
return
0
;
client
.
stop
();
}
return
0
;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool
send_data
()
{
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool
send_data
()
{
//Если соединения с сервером нет, по переподключаемся
if
(
WiFi
.
status
()
!=
WL_CONNECTED
)
wifi_connect
();
//Если соединения с сервером нет, по переподключаемся
if
(
WiFi
.
status
()
!=
WL_CONNECTED
)
wifi_connect
();
bool
what_return
=
false
;
if
(
client
.
connect
(
narodomon_server
,
port
))
{
bool
what_return
=
false
;
//Отправляем MAC-адрес
if
(
client
.
connect
(
narodomon_server
,
port
))
{
Serial
.
println
(
' '
);
//Отправляем MAC-адрес
String
s
=
mac
;
Serial
.
println
(
' '
);
Serial
.
print
(
s
);
String
s
=
mac
;
if
(
!
TEST_MODE
)
client
.
print
(
s
);
Serial
.
print
(
s
);
// if (TEST_MODE) Serial.println(s);
if
(
!
TEST_MODE
)
client
.
print
(
s
);
// if (TEST_MODE) Serial.println("YOU IN TEST MODE !!!!!!!!!!!");
// if (TEST_MODE) Serial.println(s);
// if (TEST_MODE) Serial.println("YOU IN TEST MODE !!!!!!!!!!!");
// if (TEST_MODE) Serial.println("YOU IN TEST MODE !!!!!!!!!!!");
// if (!TEST_MODE) Serial.println("YOU ARE NOT IN THE TEST MODE !!!!!!!!!!!");
// if (TEST_MODE) Serial.println("YOU IN TEST MODE !!!!!!!!!!!");
//Отправляем данные Oregon
// if (!TEST_MODE) Serial.println("YOU ARE NOT IN THE TEST MODE !!!!!!!!!!!");
sendOregonData
();
//Отправляем данные Oregon
sendOregonData
();
//Завершаем передачу
client
.
print
(
"##"
);
//Завершаем передачу
Serial
.
println
(
"##"
);
client
.
print
(
"##"
);
//Ждём отключения клиента
Serial
.
println
(
"##"
);
cur_mark
=
millis
();
//Ждём отключения клиента
do
{
cur_mark
=
millis
();
yield
();
do
{
if
(
millis
()
>
cur_mark
+
DISCONNECT_TIMEOUT
)
break
;
yield
();
}
while
(
!
client
.
connected
());
if
(
millis
()
>
cur_mark
+
DISCONNECT_TIMEOUT
)
break
;
}
while
(
!
client
.
connected
());
Serial
.
println
(
' '
);
client
.
stop
();
Serial
.
println
(
' '
);
what_return
=
true
;
client
.
stop
();
}
what_return
=
true
;
else
{
}
Serial
.
println
(
"connection to narodmon.ru failed"
);
else
{
client
.
stop
();
Serial
.
println
(
"connection to narodmon.ru failed"
);
}
client
.
stop
();
lastConnectionTime
=
millis
();
}
lastConnectionTime
=
millis
();
//Обнуляем флаги полученных данных
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
//Обнуляем флаги полученных данных
r_isreceived
[
i
]
=
0
;
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
number_of_receiving
[
i
]
=
0
;
r_isreceived
[
i
]
=
0
;
}
number_of_receiving
[
i
]
=
0
;
}
return
what_return
;
}
return
what_return
;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void
sendOregonData
()
{
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// float rain_deviation, rain_deviation_2;
void
sendOregonData
()
{
// rain_deviation = random(1, 3) * 0.001;
// float rain_deviation, rain_deviation_2;
// rain_deviation_2 = random(1, 3) * 0.0001;
// rain_deviation = random(1, 3) * 0.001;
// rain_deviation_2 = random(1, 3) * 0.0001;
String
s
;
// WRT800 wind average speed ####
String
s
;
s
=
"
\n
#WS1#"
;
// WRT800 wind average speed ####
s
+=
(
float
)
wa_speed
;
s
=
"
\n
#WS1#"
;
Serial
.
println
(
s
);
s
+=
(
float
)
wa_speed
;
if
(
!
TEST_MODE
)
client
.
print
(
s
);
Serial
.
println
(
s
);
if
(
!
TEST_MODE
)
client
.
print
(
s
);
// WRT800 max wind speed ########
s
=
"
\n
#WS2#"
;
// WRT800 max wind speed ########
s
+=
mw_speed
;
s
=
"
\n
#WS2#"
;
Serial
.
print
(
s
);
s
+=
mw_speed
;
if
(
!
TEST_MODE
)
client
.
print
(
s
);
Serial
.
print
(
s
);
if
(
!
TEST_MODE
)
client
.
print
(
s
);
// WRT800 wind direction #########
w_d
+=
random
(
-
1
,
1
)
*
0.01
;
//added deviation
// WRT800 wind direction #########
s
=
"
\n
#DIR#"
;
w_d
+=
random
(
-
1
,
1
)
*
0.01
;
//added deviation
s
+=
w_d
;
s
=
"
\n
#DIR#"
;
//was encoded 0-N, 1-NNE, 2-NE, 3-ENE, 4-E, 5-ESE, 6-SE, 7-SSE, 8-S, 9-SSW, A-SW, B-WSW, C-W, D-WNW, E-NW,F-NNW
s
+=
w_d
;
Serial
.
println
(
s
);
//was encoded 0-N, 1-NNE, 2-NE, 3-ENE, 4-E, 5-ESE, 6-SE, 7-SSE, 8-S, 9-SSW, A-SW, B-WSW, C-W, D-WNW, E-NW,F-NNW
if
(
!
TEST_MODE
)
client
.
print
(
s
);
Serial
.
println
(
s
);
// v battery
if
(
!
TEST_MODE
)
client
.
print
(
s
);
s
=
"
\n
#VBAT1#"
;
// v battery
switch
(
bat_wrt
)
{
s
=
"
\n
#VBAT1#"
;
case
1
:
{
s
+=
" 99"
;
break
;}
switch
(
bat_wrt
)
{
default:
s
+=
" 50"
;
case
1
:
{
s
+=
" 99"
;
break
;}
}
default:
s
+=
" 50"
;
// s += bat_;
}
Serial
.
println
(
s
);
// s += bat_;
if
(
!
TEST_MODE
)
client
.
print
(
s
);
Serial
.
println
(
s
);
//#####################################
if
(
!
TEST_MODE
)
client
.
print
(
s
);
//#####################################
// PCR800 rain deviation - especially for narodmon.ru #######################################
// float rain_deviation; // rain_deviation
// PCR800 rain deviation - especially for narodmon.ru #######################################
// r_rate = oregon.rain_rate;
// float rain_deviation; // rain_deviation
// r_total = oregon.total_rain;
// r_rate = oregon.rain_rate;
// rain_deviation = random(1, 3) * 0.0025;
// r_total = oregon.total_rain;
// total_rain_deviation = random(1, 3) * 0.0001;
// rain_deviation = random(1, 3) * 0.0025;
// total_rain_deviation = random(1, 3) * 0.0001;
// PCR800 rain rate ########################################################################
s
=
"
\n
#RAIN1#"
;
// PCR800 rain rate ########################################################################
// r_rate += rain_deviation; // addin deviation of last digit - .00$ - important for narodmon.ru
s
=
"
\n
#RAIN1#"
;
r_rate
+=
random
(
0
,
3
)
*
0.0026
;
// r_rate += rain_deviation; // addin deviation of last digit - .00$ - important for narodmon.ru
s
+=
String
(
r_rate
,
4
);
// show .000 digits - important for narodmon.ru
r_rate
+=
random
(
0
,
3
)
*
0.0026
;
Serial
.
println
(
s
);
s
+=
String
(
r_rate
,
4
);
// show .000 digits - important for narodmon.ru
if
(
!
TEST_MODE
)
client
.
print
(
s
);
Serial
.
println
(
s
);
// PCR800 total rain ######################################################################
if
(
!
TEST_MODE
)
client
.
print
(
s
);
s
=
"
\n
#RAIN2#"
;
// PCR800 total rain ######################################################################
// r_total += rain_deviation;
s
=
"
\n
#RAIN2#"
;
r_total
+=
random
(
0
,
3
)
*
0.0026
;
// r_total += rain_deviation;
s
+=
String
(
r_total
,
4
);
// show .0000 digits - for narodmon.ru
r_total
+=
random
(
0
,
3
)
*
0.0026
;
Serial
.
println
(
s
);
s
+=
String
(
r_total
,
4
);
// show .0000 digits - for narodmon.ru
if
(
!
TEST_MODE
)
client
.
print
(
s
);
Serial
.
println
(
s
);
// v battery
if
(
!
TEST_MODE
)
client
.
print
(
s
);
s
=
"
\n
#VBAT2#"
;
// v battery
//s += bat_;
s
=
"
\n
#VBAT2#"
;
switch
(
bat_pcr
)
{
//s += bat_;
case
1
:
{
s
+=
" 99"
;
break
;}
switch
(
bat_pcr
)
{
default:
s
+=
" 50"
;
case
1
:
{
s
+=
" 99"
;
break
;}
}
default:
s
+=
" 50"
;
Serial
.
println
(
s
);
}
if
(
!
TEST_MODE
)
client
.
println
(
s
);
Serial
.
println
(
s
);
if
(
!
TEST_MODE
)
client
.
println
(
s
);
// // TEMPERATURE ##
// s = "\n#T1#";
// // TEMPERATURE ##
// s += tempC;
// s = "\n#T1#";
// Serial.println(s);
// s += tempC;
// if (!TEST_MODE) client.print(s);
// Serial.println(s);
//
// if (!TEST_MODE) client.print(s);
// // HUMIDITY ##
//
// s = "\n#H1#";
// // HUMIDITY ##
// s += humidity;
// s = "\n#H1#";
// Serial.println(s);
// s += humidity;
// if (!TEST_MODE) client.print(s);
// Serial.println(s);
//
// if (!TEST_MODE) client.print(s);
// // PRESURE ##
//
// s = "\n#P1#";
// // PRESURE ##
// s += pressureHgmm;
// s = "\n#P1#";
// Serial.println(s);
// s += pressureHgmm;
// if (!TEST_MODE) client.print(s);
// Serial.println(s);
// ########################################################################################
// if (!TEST_MODE) client.print(s);
// ########################################################################################
// if (r_isreceived[0]) {
// s = "\n#T1#";
// if (r_isreceived[0]) {
// s += r_tmp[0];
// s = "\n#T1#";
// if (r_hmdty[0] > 0 && r_hmdty[0] <= 100 ){
// s += r_tmp[0];
// s += "\n#H1#";
// if (r_hmdty[0] > 0 && r_hmdty[0] <= 100 ){
// s += r_hmdty[0];
// s += "\n#H1#";
// }
// s += r_hmdty[0];
// Serial.println(s);
// }
// if (!TEST_MODE) client.println(s);
// Serial.println(s);
//
// if (!TEST_MODE) client.println(s);
// }
//
// if (r_isreceived[1]) {
// }
// s = "\n#T2#";
// if (r_isreceived[1]) {
// s += r_tmp[1];
// s = "\n#T2#";
// if (r_hmdty[1] > 0 && r_hmdty[1] <= 100 ){
// s += r_tmp[1];
// s += "\n#H2#";
// if (r_hmdty[1] > 0 && r_hmdty[1] <= 100 ){
// s += r_hmdty[1];
// s += "\n#H2#";
// }
// s += r_hmdty[1];
// s += "\n#W1#";
// }
// s += "0.1 m/s";
// s += "\n#W1#";
// Serial.println(s);
// s += "0.1 m/s";
// if (!TEST_MODE) client.println(s);
// Serial.println(s);
// }
// if (!TEST_MODE) client.println(s);
// if (r_isreceived[2]) {
// }
// s = "\n#T3#";
// if (r_isreceived[2]) {
// s += r_tmp[2];
// s = "\n#T3#";
// if (r_hmdty[2] > 0 && r_hmdty[2] <= 100 ){
// s += r_tmp[2];
// s += "\n#H3#";
// if (r_hmdty[2] > 0 && r_hmdty[2] <= 100 ){
// s += r_hmdty[2];
// s += "\n#H3#";
// }
// s += r_hmdty[2];
// s += "\n#W1#";
// }
// s += "0.3 m/s";
// s += "\n#W1#";
// Serial.println(s);
// s += "0.3 m/s";
// if (!TEST_MODE) client.println(s);
// Serial.println(s);
// }
// if (!TEST_MODE) client.println(s);
}
// }
}
/////////////////////////////////////////////////////////////////////////////
void
printToSerial
(
float
tempC
,
float
humidity
,
float
pressurePascals
)
/////////////////////////////////////////////////////////////////////////////
{
void
printToSerial
(
float
tempC
,
float
humidity
,
float
pressurePascals
)
//// Temperature
{
Serial
.
print
(
"Temperature: "
);
//// Temperature
Serial
.
print
(
tempC
);
Serial
.
print
(
"Temperature: "
);
Serial
.
println
(
"C"
);
Serial
.
print
(
tempC
);
//// Barometric pressure
Serial
.
println
(
"C"
);
Serial
.
print
(
"Pressure: "
);
//// Barometric pressure
Serial
.
print
(
pressureHgmm
);
Serial
.
print
(
"Pressure: "
);
Serial
.
println
(
"Hgmm"
);
Serial
.
print
(
pressureHgmm
);
//// Humidity
Serial
.
println
(
"Hgmm"
);
Serial
.
print
(
"Humidity: "
);
//// Humidity
Serial
.
print
(
humidity
);
Serial
.
print
(
"Humidity: "
);
Serial
.
println
(
"%"
);
Serial
.
print
(
humidity
);
delay
(
3000
);
Serial
.
println
(
"%"
);
}
delay
(
3000
);
//////////////////////////////
}
//////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
// ЗАМЕНА DELAY, которая работает и не приводит к вылету...
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
// ЗАМЕНА DELAY, которая работает и не приводит к вылету...
void
wait_timer
(
int
del
){
////////////////////////////////////////////////////////////////////////////////////////
unsigned
long
tm_marker
=
millis
();
void
wait_timer
(
int
del
){
while
(
millis
()
-
tm_marker
<
del
)
yield
();
unsigned
long
tm_marker
=
millis
();
return
;
while
(
millis
()
-
tm_marker
<
del
)
yield
();
return
;
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment