sayweather(перенесено в readWeatherToday)
|
Болтовня к Яндексу
/*$status="";
$status.="Сегодня ".gg("Moscow.Type").".";
say($status,1);
$status="";
$w=round(gg("Moscow.Temp"));
$tempw=$w;
if($tempw >= 11 and $tempw <= 14){
$tempcels=" градусов ";
}
else{
while ($tempw > 9){
$tempw=$tempw-10;
}
if($tempw == 0 or $tempw >= 5 and $tempw <= 9){
$tempcels= градусов ; }
if($tempw == 1){
$tempcels= градус ; }
if($tempw >= 2 and $tempw <= 4){
$tempcels= градуса ; }
}
//$tNew = abs((float)getGlobal('Moscow.Temp'));
$status.=' Температура '.getGlobal('Moscow.Temp')." ".$tempcels." цельсия";
say($status,1);
$tempw="";
$tempcels="";
$status="";
$h=round(gg("Moscow.Humidity"));
$tempw=$h;
if($tempw >= 11 and $tempw <= 14){
$tempcels=" процентов ";
}
else{
while ($tempw > 9){
$tempw=$tempw-10;
}
if($tempw == 0 or $tempw >= 5 and $tempw <= 9){
$tempcels= процентов ; }
if($tempw == 1){
$tempcels= процент ; }
if($tempw >= 2 and $tempw <= 4){
$tempcels= процента ; }
}
$status.="Относительная влажность ".gg("Moscow.Humidity")." ".$tempcels. ".";
say($status,1);
$tempw="";
$tempcels="";
$status="";
$pressure=(float)gg("Moscow.Pressure");
if ($pressure<728) {
$status.=' Атмосферное давление пониженное';
} elseif ($pressure>768) {
$status.=' Атмосферное давление повышенное.';
} else {
$status.=' Атмосферное давление нормальное.';
}
say($status,1);
$status="";
// ветер
$WindSpeed=(float)gg("Moscow.WindSpeed");
if ($WindSpeed<1) {
$status.=' Ветра нет.';
} elseif ($WindSpeed<3) {
$status.=' Ветер слабый.';
} elseif ($WindSpeed<6) {
$status.=' Ветер сильный.';
} elseif ($WindSpeed<9) {
$status.=' Ветер очень сильный.';
} else {
$status.=' Ветер очень! Очень сильный.';
}
$status.=' Направление '.getGlobal('Moscow.WindDir').'.';
say($status,1);
*/
|
test
|
setTimeOut('testTimer','say("Hello world!");',30);
|
testnew
|
//$weather.="Сегодня ожидается ".str_replace('°',' ',getGlobal('weatherToday'));
//$weather.=". Завтра ".str_replace('°',' ',getGlobal('weatherTomorrow'));
//$weather.=". Ночью ".getGlobal(Moscow.temperature_night').'.';
//$weather=str_replace('°','',$weather);
//say($weather,2);
//$weather.="Сегодня ожидается ".str_replace('°',' ',getGlobal('weatherToday'));
//$weather.=". Завтра ".str_replace('°',' ',getGlobal('weatherTomorrow'));
//$weather.=". Ночью ".getGlobal('Moscow.temperature_night').'.';
//$weather=str_replace('°','',$weather);
//say($weather,2);
|
timeNow
|
|
Yandex
|
$city_id=27612;
$data_file="http://export.yandex.ru/weather-ng/forecasts/$city_id.xml?".rand(); // адрес xml файла
$xml = simplexml_load_file($data_file); // раскладываем xml на массив
$temp=$xml->fact->temperature; // температура сегодна
// Если значение температуры положительно, для наглядности добавляем "+"
if ($temp>0) {$temp='+'.$temp;}
$temp1=$xml->yesterday->temperature; // температура вчера
// Если значение температуры положительно, для наглядности добавляем "+"
if ($temp1>0) {$temp1='+'.$temp1;}
sg("Moscow.yesterday",$temp1);
sg("Moscow.Temp",$temp);
sg("Moscow.City",$xml->fact->station);
sg("Moscow.Type",$xml->fact->weather_type); //состояние неба
sg("Moscow.Pressure",$xml->fact->pressure); //давление
sg("Moscow.Humidity",$xml->fact->humidity); //влажность
sg("Moscow.mslp_pressure",$xml->fact->mslp_pressure); //Среднее давление на уровне моря hPa гПа (Гектопаскаль)
sg("Moscow.WindSpeed",$xml->fact->wind_speed); //скорость ветра
sg("Moscow.Image",$xml->fact->{'image-v3'});//картинка
sg("Moscow.UpTime",$xml->fact->uptime); //последнее обновление
sg("Moscow.SunRise",$xml->day[0]->sunrise); //Восход солнца
sg("Moscow.SunSet",$xml->day[0]->sunset); //Заход солнца
foreach($xml->informer->temperature as $item) {
if ($item["type"] == "night") { //температура ночью
sg("Moscow.temperature_night",$item);
} elseif ($item["type"] == "tomorrow") { //температура завтра
sg("Moscow.temperature_tomorrow",$item);
}
}
//$dir2 = $xml->informer->temperature;
$dir = $xml->fact->wind_direction;
switch ($dir){
case 's':
$dir="южное";
break;
case 'n':
$dir="северное";
break;
case 'w':
$dir="западное";
break;
case 'e':
$dir="восточное";
break;
case 'sw':
$dir="юго-западное";
break;
case 'nw':
$dir="северо-западное";
break;
case 'ne':
$dir="северо-восточное";
break;
case 'se':
$dir="юго-восточное";
break;
case 'calm':
$dir="штиль";
break;
}
sg("Moscow.WindDir",$dir); //направление ветра
$dir1 = $xml->fact->season;
switch ($dir1){
case 'winter':
$dir1="ЗИМА";
break;
case 'summer':
$dir1="ЛЕТО";
break;
case 'autumn':
$dir1="ОСЕНЬ";
break;
case 'spring':
$dir1="ВЕСНА";
break;
}
sg("Moscow.season",$dir1); //времена года
say("Читаю прогноз погоды с Yandex", 0);
|
DATA
|
Узнаем дату
//Узнаем и разбираем текущую дату
$days=array('воскресенье','понедельник','вторник','среда','четверг','пятница','суббота');
$months=array(1=>'январь','февраль','март','апрель','май','июнь','июль','август','сентябрь','октябрь','ноябрь','декабрь');
$months2=array(1=>'января','февраля','марта','апреля','мая','июня','июля','августа','сентября','октября','ноября','декабря');
$daymonth=array(1=>'первое','второе','третье','четвертое','пятое','шестое','седьмое','восьмое','девятое','десятое','одинадцатое','двенадцатое','тринадцатое','четырнадцатое','пятнадцатое','шестнадцатое','семнадцатое','восемнадцатое','девятнадцатое','двадцатое','двадцать первое','двадцать второе','двадцать третье','двадцать четвертое','двадцать пятое','двадцать шестое','двадцать седьмое','двадцать восьмое','двадцать девятое','тридцатое','тридцать первое');
$day_num=(int)date('w');
$month_num=(int)date('m');
$day_month=(int)date('j');
$day_of_month=$daymonth[$day_month];
$day_of_week=$days[$day_num];
$month_txt1=$months[$month_num];
$month_txt2=$months2[$month_num];
addClass('Time'); addClassObject('Time', 'Time');
sg('Time.MonthNum',$month_num);
sg('Time.MonthTXT',$month_txt1);
sg('Time.MonthTXTalt',$month_txt2);
sg('Time.DayOfMonthNum',$day_month);
sg('Time.DayOfMonthTXT',$day_of_month);
sg('Time.DayOfWeekTXT',$day_of_week);
sg('Time.DayOfWeekNum',$day_num);
say("Узнаю и разбираю текущую дату", 0);
|
DS18S20
|
Опрос датчиков температуры
$read = file_get_contents('http://192.168.1.150/getdev');
if ($read)
{
parse_str($read);
setGlobal("sensorT0.temp", $T0);
setGlobal("dht11.Humidity", $Humidity);
setGlobal("dht11.temp", $Temperature);
callMethod('sensorT0.tempChanged',array('t'=>$T0));
callMethod('dht11.tempChanged',array('t'=>$Humidity));
callMethod('dht11.tempChanged',array('t'=>$Temperature));
}
say("Опрашиваю датчики", 0);
//$T0 = round($T0, 1);
//callMethod('sensorT0.tempChanged',array('t'=>$T0));
//if ($read)
//{
// parse_str($read);
//}
//if ($T0<>"") //and $T0<>0 and $T0<>127 and $T0<>-127)
//{
//$T0 = round($T0,1);
//setGlobal("sensorT0.temp", $T0);температура
//setGlobal("sensorT0.ID",$); //Мас адрес датчика
//callMethod('sensorT0.tempChanged',array('t'=>$T0));
//}
//$read = "T0:28FF91F74C040074:65.50;";
/*
if ($read)
{
parse_str($read);
}
$array_sensor = explode(';', $read);
foreach ($array_sensor as $key => $sensor) {
$array = explode(':', $sensor);
}
$T0 = $array[2];
if ($T0<>"" and $T0<>0 and $T0<>127)
{
$T0 = round($T0,1);
setGlobal("sensorT0.temp", $T0);
callMethod('sensorT0.tempChanged',array('t'=>$T0));
}
*/
/*
if ($read)
{
parse_str($read);
}
if ($T0<>"" and $T0<>0 and $T0<>127)
{
$T0 = round($T0,1);
sg("sensorT0.temp", $T0); // Присваиваю значение, а затем...
callMethod('sensorT0.tempChanged',array('t'=>$T0)); // еще раз передаю через метод. Думаю достаточно передавать через метод.
}
if ($T1<>"" and $T1<>0 and $T1<>127 and $T1<>-127)
{
$T1 = round($T1,1);
callMethod('sensorT1.tempChanged',array('t'=>$T1));
}
if ($T2<>"" and $T2<>0 and $T2<>127 and $T2<>-127)
{
$T2 = round($T2,1);
callMethod('sensorT2.tempChanged',array('t'=>$T2));
}
if ($T3<>"" and $T3<>0 and $T3<>127 and $T3<>-127)
{
$T3 = round($T3,1);
callMethod('sensorT3.tempChanged',array('t'=>$T3));
*/
|
readWeatherToday
|
Болтовня
//$weather.="Сегодня ожидается ".str_replace('°',' ',getGlobal('weatherToday'));
//$weather.=". Завтра ".str_replace('°',' ',getGlobal('weatherTomorrow'));
//$weather.=". Сейчас на улице ".getGlobal('Moscow.Temp').'.';
//$weather=str_replace('°','',$weather);
//say($weather,2);
$status="";
$status.="Сегодня ".gg("Moscow.Type").".";
say($status,1);
$status="";
$w=round(gg("Moscow.Temp"));
$tempw=$w;
if($tempw >= 11 and $tempw <= 14){
$tempcels=" градусов ";
}
else{
while ($tempw > 9){
$tempw=$tempw-10;
}
if($tempw == 0 or $tempw >= 5 and $tempw <= 9){
$tempcels= градусов ; }
if($tempw == 1){
$tempcels= градус ; }
if($tempw >= 2 and $tempw <= 4){
$tempcels= градуса ; }
}
//$tNew = abs((float)getGlobal('Moscow.Temp'));
$status.=' Температура '.getGlobal('Moscow.Temp')." ".$tempcels." цельсия";
say($status,1);
$tempw="";
$tempcels="";
$status="";
$h=round(gg("Moscow.Humidity"));
$tempw=$h;
if($tempw >= 11 and $tempw <= 14){
$tempcels=" процентов ";
}
else{
while ($tempw > 9){
$tempw=$tempw-10;
}
if($tempw == 0 or $tempw >= 5 and $tempw <= 9){
$tempcels= процентов ; }
if($tempw == 1){
$tempcels= процент ; }
if($tempw >= 2 and $tempw <= 4){
$tempcels= процента ; }
}
$status.="Относительная влажность ".gg("Moscow.Humidity")." ".$tempcels. ".";
say($status,1);
$tempw="";
$tempcels="";
$status="";
$pressure=(float)gg("Moscow.Pressure");
if ($pressure<728) {
$status.=' Атмосферное давление пониженное';
} elseif ($pressure>768) {
$status.=' Атмосферное давление повышенное.';
} else {
$status.=' Атмосферное давление нормальное.';
}
say($status,1);
$status="";
// ветер
$WindSpeed=(float)gg("Moscow.WindSpeed");
if ($WindSpeed<1) {
$status.=' Ветра нет.';
} elseif ($WindSpeed<3) {
$status.=' Ветер слабый.';
} elseif ($WindSpeed<6) {
$status.=' Ветер сильный.';
} elseif ($WindSpeed<9) {
$status.=' Ветер очень сильный.';
} else {
$status.=' Ветер очень! Очень сильный.';
}
$status.=' Направление '.getGlobal('Moscow.WindDir').'.';
say($status,1);
|
YANDEX2
|
$objects=getObjectsByClass("YANDEXX"); //имя класса
foreach($objects as $obj) {
$city_id=gg($obj['TITLE'].".city_id"); //ID города узнаем тут: https://pogoda.yandex.ru/static/cities.xml
$data_file="http://export.yandex.ru/weather-ng/forecasts/$city_id.xml?".rand(); // адрес xml файла
//say($data_file);
$xml = simplexml_load_file($data_file); // раскладываем xml на массив
$temp_yesterday=$xml->yesterday->temperature; //узнаем вчерашнюю температуру в это же время
if ($temp_yesterday>0) {$temp_yesterday='+'.$temp_yesterday;} // Если значение температуры положительно, для наглядности добавляем "+"
sg($obj['TITLE'].".TempYesterday",$temp_yesterday);
$temp=$xml->fact->temperature;
if (date('G')==13) {sg($obj['TITLE'].".Temp13h",$temp);}
if (date('G')==21) {sg($obj['TITLE'].".Temp21h",$temp);}
if ($temp>0) {$temp='+'.$temp;} // Если значение температуры положительно, для наглядности добавляем "+"
sg($obj['TITLE'].".Temp",$temp);
sg($obj['TITLE'].".Type",$xml->fact->weather_type);
sg($obj['TITLE'].".Pressure",$xml->fact->pressure);
sg($obj['TITLE'].".Humidity",$xml->fact->humidity);
sg($obj['TITLE'].".WindSpeed",$xml->fact->wind_speed);
sg($obj['TITLE'].".Image",$xml->fact->{'image-v3'});
sg($obj['TITLE'].".City",$xml->fact->station);
sg($obj['TITLE'].".City2",$xml[city]);
$rain1=gg($obj['TITLE'].".Type");
$rain2=$xml->day[0]->day_part[0]->weather_type;
$rain3=$xml->day[0]->day_part[1]->weather_type;
$rain4=$xml->day[0]->day_part[2]->weather_type;
$rain5=$xml->day[0]->day_part[3]->weather_type;
$rain=($rain1. $rain2. $rain3. $rain4. $rain5);
$pos = strpos($rain, "дожд");
if ($pos === false) {
sg($obj['TITLE'].".Rain",0);
} else {
sg($obj['TITLE'].".Rain",1);
// say("Возможен дождь",2);
}
$dir = $xml->fact->wind_direction;
switch ($dir){
case 's':
$dir="южный";
break;
case 'n':
$dir="северный";
break;
case 'w':
$dir="западный";
break;
case 'e':
$dir="восточный";
break;
case 'sw':
$dir="юго-западный";
break;
case 'nw':
$dir="северо-западный";
break;
case 'se':
$dir="юго-восточный";
break;
case 'ne':
$dir="северо-восточный";
break;
case 'calm':
$dir="штиль";
break;
}
sg($obj['TITLE'].".WindDir",$dir);
sg($obj['TITLE'].".SunRise",$xml->day[0]->sunrise);
sg($obj['TITLE'].".SunSet",$xml->day[0]->sunset);
// $metcast="";
$metcast="На улице ".gg($obj['TITLE'].".Type").".";
// ветер
$WindSpeed=(float)gg($obj['TITLE'].".WindSpeed");
if ($WindSpeed<1) { $metcast.=' Ветра, скорее всего, нет.';
} elseif ($WindSpeed<3) { $metcast.=' Возможен слабый ветер.';
} elseif ($WindSpeed<6) { $metcast.=' Возможен сильный ветер.';
} elseif ($WindSpeed<9) { $metcast.=' Возможен довольно сильный ветер.';
} else { $metcast.=' Возможен очень сильный ветер.';
}
$w=round(strip_tags(gg($obj['TITLE'].".Temp")));
$tempw=$w;
if($w < "0"){ $tempw=abs($w); }
if($w > "0"){ $templus=" плюс "; }
if($tempw >= 11 and $tempw <= 14){ $tempcels=" градусов";}
else{
while ($tempw > 9){
$tempw=$tempw-10;
}
if($tempw == 0 or $tempw >= 5 and $tempw <= 9){ $tempcels=" градусов"; }
if($tempw == 1){ $tempcels=" градус"; }
if($tempw >= 2 and $tempw <= 4){ $tempcels=" градуса"; }
}
$metcast.=' Температура '.gg($obj['TITLE'].".Temp").' '.$tempcels.'.';
$tm=(float)gg($obj['TITLE'].".Temp");
if ($tm<-40) { $metcast.=' Мы морозов не боимся!';
} elseif ($tm<-30) { $metcast.=' Очень холодно, оденьтесь теплее.';
} elseif ($tm<-20) { $metcast.=' Самое время есть мороженое.';
} elseif ($tm<-10) { $metcast.=' Холодновато.';
} elseif ($tm<-3) { $metcast.=' Не особо холодно.';
} elseif ($tm<3) { $metcast.=' Значит, возможно, гололёд.';
} elseif ($tm<10) { $metcast.=' Тепловато.';
} elseif ($tm<25) { $metcast.=' Тепло.';
} elseif ($tm<30) { $metcast.=' Жарко.';
} elseif ($tm>30) { $metcast.=' Ташкент.';
}
// $metcast.=' Восход солнца сегодня в '.gg($obj['TITLE'].".SunRise").',';
// $metcast.=' закат в '.gg($obj['TITLE'].".SunSet").'.';
sg($obj['TITLE'].".metcast",$metcast);
//
$w3days="Сегодня ночью будет ";
$temp=$xml->day[0]->day_part[3]->temperature_from;
if ($temp>0) {$temp='+'.$temp;}
$w3days.=$temp;
$w3days.="°, ";
$w3days.=$xml->day[0]->day_part[3]->weather_type;
$w3days.=".\r\nЗавтра днём будет ";
$temp=$xml->day[1]->day_part[1]->temperature_from;
if ($temp>0) {$temp='+'.$temp;}
$w3days.=$temp;
$w3days.="°, ";
$w3days.=$xml->day[1]->day_part[1]->weather_type;
$w3days.=". Послезавтра ночью ";
$temp=$xml->day[1]->day_part[3]->temperature_from;
if ($temp>0) {$temp='+'.$temp;}
$w3days.=$temp;
$w3days.="°, ";
$w3days.=$xml->day[1]->day_part[3]->weather_type;
$w3days.=".";
$dir1 = $xml->fact->season;
switch ($dir1){
case 'winter':
$dir1="зима";
break;
case 'summer':
$dir1="лето";
break;
case 'autumn':
$dir1="осень";
break;
case 'spring':
$dir1="весна";
break;
}
sg($obj['TITLE'].".season",$dir1); //время года
sg($obj['TITLE'].".forecast",$w3days);
sg($obj['TITLE'].".updated" , date("H:i",time()));}
say("Читаю прогноз погоды с Yandex2", 0);
|