[STM32MP135F-DK]测评 ⑥自动网络校时+获取天气信息
<div class='showpostmsg'> 本帖最后由 不爱胡萝卜的仓鼠 于 2023-12-17 19:19 编辑<p> 本篇对应的是测评计划中的网络相关测评,本来想着学习一下网络相关的驱动啥的,但是ST已经做好了,我到手插上网线就可以用,那我就为最终demo做一下网络相关的前期工作</p>
<p> </p>
<p><span style="font-size:22px;">1.自动网络校时</span></p>
<p> 自从我拿到开发板后,每次使用shutdown命令,系统给我的时间都是错误的,搞得我很难受。用手动校准吧,因为没有整上RTC电池,一关机断电,时间就不会更新了,那我还是得整一下自动校时</p>
<p> 同时参与135评测的其他朋友已经做了自动校时的内容,链接在此(<a href="https://bbs.eeworld.com.cn/thread-1267051-1-1.html#pid3286979" target="_blank">https://bbs.eeworld.com.cn/thread-1267051-1-1.html#pid3286979</a>),给我提供了很多参考</p>
<p> 首先修改一下ntp的配置文件,mobaxterm编辑文件很方便,直接双击就可以打开编辑,不用在终端使用vim。配置文件在/etc/ntp.conf</p>
<div style="text-align: center;"></div>
<div>在图中位置加入这句话,告诉ntp应该去那个地址获取时间信息</div>
<div>
<div style="text-align: center;"></div>
<div> </div>
<pre>
<code>server cn.pool.ntp.org prefer</code></pre>
<p>cn.pool.ntp.org是ntp网络授时组织的中国授时源</p>
<p> 修改完配置文件后,重启NTP</p>
<pre>
<code>systemctl restart ntpd</code></pre>
<p>过一会儿就会自动更新时间了</p>
<p> 但是过一会儿时间更新后,日期对了,时间还是错的,用</p>
<pre>
<code>timedatectl</code></pre>
<p>命令看了一下,是时区还没有设置,还是默认的格林威治时间(UTC+0)</p>
<div style="text-align: center;"></div>
<p>用</p>
<pre>
<code>timedatectl list-timezones</code></pre>
<p>命令查看一下所有可供选择的时区</p>
<pre>
<code>root@stm32mp1:~# timedatectl list-timezones
Africa/Abidjan
Africa/Algiers
Africa/Bissau
Africa/Cairo
Africa/Casablanca
Africa/Ceuta
Africa/El_Aaiun
Africa/Johannesburg
Africa/Juba
Africa/Khartoum
Africa/Lagos
Africa/Maputo
Africa/Monrovia
Africa/Nairobi
Africa/Ndjamena
Africa/Sao_Tome
Africa/Tripoli
Africa/Tunis
Africa/Windhoek
America/Adak
America/Anchorage
America/Araguaina
America/Argentina/Buenos_Aires
America/Argentina/Catamarca
America/Argentina/Cordoba
America/Argentina/Jujuy
America/Argentina/La_Rioja
America/Argentina/Mendoza
America/Argentina/Rio_Gallegos
America/Argentina/Salta
America/Argentina/San_Juan
America/Argentina/San_Luis
America/Argentina/Tucuman
America/Argentina/Ushuaia
America/Asuncion
America/Bahia
America/Bahia_Banderas
America/Barbados
America/Belem
America/Belize
America/Boa_Vista
America/Bogota
America/Boise
America/Cambridge_Bay
America/Campo_Grande
America/Cancun
America/Caracas
America/Cayenne
America/Chicago
America/Chihuahua
America/Ciudad_Juarez
America/Costa_Rica
America/Cuiaba
America/Danmarkshavn
America/Dawson
America/Dawson_Creek
America/Denver
America/Detroit
America/Edmonton
America/Eirunepe
America/El_Salvador
America/Fort_Nelson
America/Fortaleza
America/Glace_Bay
America/Goose_Bay
America/Grand_Turk
America/Guatemala
America/Guayaquil
America/Guyana
America/Halifax
America/Havana
America/Hermosillo
America/Indiana/Indianapolis
America/Indiana/Knox
America/Indiana/Marengo
America/Indiana/Petersburg
America/Indiana/Tell_City
America/Indiana/Vevay
America/Indiana/Vincennes
America/Indiana/Winamac
America/Inuvik
America/Iqaluit
America/Jamaica
America/Juneau
America/Kentucky/Louisville
America/Kentucky/Monticello
America/La_Paz
America/Lima
America/Los_Angeles
America/Maceio
America/Managua
America/Manaus
America/Martinique
America/Matamoros
America/Mazatlan
America/Menominee
America/Merida
America/Metlakatla
America/Mexico_City
America/Miquelon
America/Moncton
America/Monterrey
America/Montevideo
America/New_York
America/Nome
America/Noronha
America/North_Dakota/Beulah
America/North_Dakota/Center
America/North_Dakota/New_Salem
America/Nuuk
America/Ojinaga
America/Panama
America/Paramaribo
America/Phoenix
America/Port-au-Prince
America/Porto_Velho
America/Puerto_Rico
America/Punta_Arenas
America/Rankin_Inlet
America/Recife
America/Regina
America/Resolute
America/Rio_Branco
America/Santarem
America/Santiago
America/Santo_Domingo
America/Sao_Paulo
America/Scoresbysund
America/Sitka
America/St_Johns
America/Swift_Current
America/Tegucigalpa
America/Thule
America/Tijuana
America/Toronto
America/Vancouver
America/Whitehorse
America/Winnipeg
America/Yakutat
Antarctica/Casey
Antarctica/Davis
Antarctica/Macquarie
Antarctica/Mawson
Antarctica/Palmer
Antarctica/Rothera
Antarctica/Troll
Asia/Almaty
Asia/Amman
Asia/Anadyr
Asia/Aqtau
Asia/Aqtobe
Asia/Ashgabat
Asia/Atyrau
Asia/Baghdad
Asia/Baku
Asia/Bangkok
Asia/Barnaul
Asia/Beirut
Asia/Bishkek
Asia/Chita
Asia/Choibalsan
Asia/Colombo
Asia/Damascus
Asia/Dhaka
Asia/Dili
Asia/Dubai
Asia/Dushanbe
Asia/Famagusta
Asia/Gaza
Asia/Hebron
Asia/Ho_Chi_Minh
Asia/Hong_Kong
Asia/Hovd
Asia/Irkutsk
Asia/Jakarta
Asia/Jayapura
Asia/Jerusalem
Asia/Kabul
Asia/Kamchatka
Asia/Karachi
Asia/Kathmandu
Asia/Khandyga
Asia/Kolkata
Asia/Krasnoyarsk
Asia/Kuching
Asia/Macau
Asia/Magadan
Asia/Makassar
Asia/Manila
Asia/Nicosia
Asia/Novokuznetsk
Asia/Novosibirsk
Asia/Omsk
Asia/Oral
Asia/Pontianak
Asia/Pyongyang
Asia/Qatar
Asia/Qostanay
Asia/Qyzylorda
Asia/Riyadh
Asia/Sakhalin
Asia/Samarkand
Asia/Seoul
Asia/Shanghai
Asia/Singapore
Asia/Srednekolymsk
Asia/Taipei
Asia/Tashkent
Asia/Tbilisi
Asia/Tehran
Asia/Thimphu
Asia/Tokyo
Asia/Tomsk
Asia/Ulaanbaatar
Asia/Urumqi
Asia/Ust-Nera
Asia/Vladivostok
Asia/Yakutsk
Asia/Yangon
Asia/Yekaterinburg
Asia/Yerevan
Atlantic/Azores
Atlantic/Bermuda
Atlantic/Canary
Atlantic/Cape_Verde
Atlantic/Faroe
Atlantic/Madeira
Atlantic/South_Georgia
Atlantic/Stanley
Australia/Adelaide
Australia/Brisbane
Australia/Broken_Hill
Australia/Darwin
Australia/Eucla
Australia/Hobart
Australia/Lindeman
Australia/Lord_Howe
Australia/Melbourne
Australia/Perth
Australia/Sydney
Europe/Andorra
Europe/Astrakhan
Europe/Athens
Europe/Belgrade
Europe/Berlin
Europe/Brussels
Europe/Bucharest
Europe/Budapest
Europe/Chisinau
Europe/Dublin
Europe/Gibraltar
Europe/Helsinki
Europe/Istanbul
Europe/Kaliningrad
Europe/Kirov
Europe/Kyiv
Europe/Lisbon
Europe/London
Europe/Madrid
Europe/Malta
Europe/Minsk
Europe/Moscow
Europe/Paris
Europe/Prague
Europe/Riga
Europe/Rome
Europe/Samara
Europe/Saratov
Europe/Simferopol
Europe/Sofia
Europe/Tallinn
Europe/Tirane
Europe/Ulyanovsk
Europe/Vienna
Europe/Vilnius
Europe/Volgograd
Europe/Warsaw
Europe/Zurich
Indian/Chagos
Indian/Maldives
Indian/Mauritius
Pacific/Apia
Pacific/Auckland
Pacific/Bougainville
Pacific/Chatham
Pacific/Easter
Pacific/Efate
Pacific/Fakaofo
Pacific/Fiji
Pacific/Galapagos
Pacific/Gambier
Pacific/Guadalcanal
Pacific/Guam
Pacific/Honolulu
Pacific/Kanton
Pacific/Kiritimati
Pacific/Kosrae
Pacific/Kwajalein
Pacific/Marquesas
Pacific/Nauru
Pacific/Niue
Pacific/Norfolk
Pacific/Noumea
Pacific/Pago_Pago
Pacific/Palau
Pacific/Pitcairn
Pacific/Port_Moresby
Pacific/Rarotonga
Pacific/Tahiti
Pacific/Tarawa
Pacific/Tongatapu
UTC
</code></pre>
<p> </p>
</div>
<p>设置一下时区为上海</p>
<pre>
<code>timedatectl set-timezone Asia/Shanghai</code></pre>
<p>再重新重启一下NTP,时间终于正确了</p>
<div style="text-align: center;"></div>
<p> </p>
<p><span style="font-size:22px;">2.获取天气信息</span></p>
<p> 天气信息我这边使用的是知心天气,他可以免费试用,网址如下:<a href="https://www.seniverse.com/" target="_blank">https://www.seniverse.com/</a></p>
<p> 怎么注册账号、登录我就不说了,登录后之间点击免费使用</p>
<div style="text-align: center;"></div>
<p>然后选择这个免费的</p>
<div style="text-align: center;"></div>
<p>然后就可以得到一个公钥和私钥</p>
<div style="text-align: center;"></div>
<p>直接访问下面的网址就可以得到json的天气数据</p>
<pre>
<code>https://api.seniverse.com/v3/weather/now.json?key=私钥&location=城市编码</code></pre>
<p>其中私钥文本要更换成刚才得到的私钥,城市编码可以在以下网址得到:<a href="https://docs.seniverse.com/api/start/start.html" target="_blank">https://docs.seniverse.com/api/start/start.html</a></p>
<div style="text-align: center;"></div>
<p>点击下载的到一个excel,找到对应的城市,我这边以杭州为例</p>
<div style="text-align: center;"></div>
<p>直接在浏览器中输入刚才的网址,得到对应的json信息</p>
<div style="text-align: center;"></div>
<p>现在确定了,这个天气信息是可以得到的,现在去135上试试</p>
<p>使用</p>
<pre>
<code>curl -X GET "网址"</code></pre>
<p>命令就可以拉下来天气的json数据</p>
<div style="text-align: center;"></div>
<p>OK,可以拉下来</p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script>
页:
[1]