{"id":336,"date":"2022-03-02T16:32:36","date_gmt":"2022-03-02T16:32:36","guid":{"rendered":"https:\/\/fletch.scot\/wp\/?p=336"},"modified":"2022-03-02T16:43:49","modified_gmt":"2022-03-02T16:43:49","slug":"wspr-transmitter-keeping-time","status":"publish","type":"post","link":"https:\/\/fletch.scot\/wp\/?p=336","title":{"rendered":"WSPR Transmitter &#8212; keeping Time"},"content":{"rendered":"<p>A <a href=\"https:\/\/en.wikipedia.org\/wiki\/WSPR_(amateur_radio_software)\">WSPR<\/a> transmission starts on an even two-minute interval. So a WSPR Transmitter needs to be able to keep track of the real time. My earlier <a href=\"https:\/\/fletch.scot\/wp\/?p=302\">post<\/a>\u00a0about setting the time on an RTC isn&#8217;t suitable for my <a href=\"https:\/\/fletch.scot\/wp\/?p=319\">WSPR Transmitter<\/a> as the process of getting the time isn&#8217;t automatic. The best choice is between using <a href=\"https:\/\/en.wikipedia.org\/wiki\/Global_Positioning_System\">GPS<\/a> or <a href=\"https:\/\/en.wikipedia.org\/wiki\/Network_Time_Protocol\">NTP<\/a>. I chose NTP as my WSPR Transmitter will always be used where there is Wi-Fi available.<\/p>\n<p>Choosing NTP has some ramifications. You need to provide Wi-Fi credentials and the most convenient way for this is to ask for them once and store them somewhere. You could just store them in the code but this isn&#8217;t secure.<\/p>\n<p>You also need to use a chip that handles Wi-Fi. I normally use <a href=\"https:\/\/en.wikipedia.org\/wiki\/PIC_microcontrollers\">PIC<\/a> chips but none of the ones I had contained a Wi-Fi radio. So I looked at alternatives and chose an <a href=\"https:\/\/en.wikipedia.org\/wiki\/ESP8266\">ESP8266<\/a> based module called a <a href=\"https:\/\/www.bitsbox.co.uk\/index.php?main_page=product_info&amp;cPath=302_312&amp;products_id=3586\">D1 Mini<\/a>. This module can be programmed using the Arduino IDE via USB. It&#8217;s a little larger than most PIC chips, but is still a reasonable size.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"D1_mini.jpg\" src=\"https:\/\/fletch.scot\/wp\/wp-content\/uploads\/2022\/03\/D1_mini.jpg\" alt=\"D1 mini\" width=\"350\" height=\"335\" border=\"0\" \/><\/p>\n<p>A D1 mini doesn&#8217;t have any EEPROM&#8211;all of its memory is flash-based. However, there are libraries available which emulate EEPROM. So this is what I used to store the Wi-Fi credentials.<\/p>\n<p>Once the NTP server has been asked for the time you need to be able to keep track of the time locally. NTP isn&#8217;t really suitable to do this by itself. So a real-time clock module or RTC is used. Previously I had used a DS1307 which seemed fine, but it wasn&#8217;t available to buy so I bought a <a href=\"https:\/\/www.bitsbox.co.uk\/index.php?main_page=product_info&amp;cPath=140_166&amp;products_id=2760\">DS3231<\/a> instead. This module is driven via an <a href=\"https:\/\/en.wikipedia.org\/wiki\/I%C2%B2C\">I2C<\/a> bus. The D1 mini module also has I2C built-in. However the ESP8266 runs on 3.3 V and the DS3231 uses 5 V. So a <a href=\"https:\/\/www.bitsbox.co.uk\/index.php?main_page=product_info&amp;cPath=140_161_164&amp;products_id=2914\">level shifter<\/a> is also needed.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"rtc.jpg\" src=\"https:\/\/fletch.scot\/wp\/wp-content\/uploads\/2022\/03\/rtc.jpg\" alt=\"Rtc\" width=\"250\" height=\"206\" border=\"0\" \/><img loading=\"lazy\" decoding=\"async\" title=\"4ch_ls.jpg\" src=\"https:\/\/fletch.scot\/wp\/wp-content\/uploads\/2022\/03\/4ch_ls.jpg\" alt=\"4ch ls\" width=\"300\" height=\"292\" border=\"0\" \/><\/p>\n<p>The code to get the time and maintain it is lengthy but not complex and everything is sequential. When the ESP8266 starts a pin is checked to see if the Wi-Fi credentials should be asked for via the UART. If so, they are stored in the emulated EEPROM. The stored credentials are used to connect to the Wi-Fi. Then a packet is sent to the NTP server and the response is parsed to get the minutes and seconds of the current real time. None of the other time details are needed. The minutes and seconds are stored in the RTC module via the I2C bus. The time in the RTC may drift so the code occasionally retrieves the current time from the NTP server and updates the RTC. The code then loops waiting for the start of an even two-minute interval and transmits the WSPR tones. More about this in a later post. I&#8217;ll post the code then too.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A WSPR transmission starts on an even two-minute interval. So a WSPR Transmitter needs to be able to keep track of the real time. My earlier post\u00a0about setting the time on an RTC isn&#8217;t suitable for my WSPR Transmitter as the process of getting the time isn&#8217;t automatic. The best choice is between using GPS &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/fletch.scot\/wp\/?p=336\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;WSPR Transmitter &#8212; keeping Time&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[5,56],"class_list":["post-336","post","type-post","status-publish","format-standard","hentry","tag-programming","tag-wspr"],"_links":{"self":[{"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/posts\/336","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=336"}],"version-history":[{"count":3,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/posts\/336\/revisions"}],"predecessor-version":[{"id":339,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/posts\/336\/revisions\/339"}],"wp:attachment":[{"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=336"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}