School call to .NET Micro Framework with remote control
Post reveals the implementation of the school call using the FEZ Domino debug board. The schedule is managed via a web page. FEZ Domino has ported the .NET Micro Framework . C # programming language. The prehistory of the post is ... Habrovchan prostosergik published the post New Year's Raspberry - fasten the HD44780 screen to the Raspberry Pi . In the comments between me and prostosergik, a dispute arose about the appropriateness of using Raspberry Pi for these tasks. prostosergik in the comments reported on the already completed project of the school bell on the Raspberry Pi. Later the post School call on the Raspberry Pi with remote control was published. Now it is my turn to implement this task. According to the results of the correspondence formed the following TK: Purpose: to include a call in accordance with the schedule of school calls in the school Mechanism of work: the call is made in accordance with the filed signal "1" on the contact relay. When the relay closes, the bell rings. Requirements
The ability to change the schedule of calls through the Web-interface
Time synchronization with NTP server from the Internet
The presence of a reset button to the "factory" settings
Call time does not change, and always 5 seconds
Security. Setting a list of IP addresses from which system management is possible. Login / password authorization (not implemented, but technically possible)
Time schedule calls for each working day, equally
Call button at any time
Implementation I must say, due to technical limitations on the Arduino UNO R3, it was not possible to fully implement this project. When choosing a controller was guided by the following rules
Arduino-compatible shildam and work methodology.
Lack of Linux in any form
Affordable price
Not for the industry segment
FEZ Domino is not mentioned in the title, not by chance. The program code between microcontrollers running on the .NET Micro Framework is always portable without changes, subject to the version. In this case, FEZ Domino is easily replaced with the NET Duino Plus 2 card, without sacrificing functionality.
// FEZ_Components.Button Button_ManualCall = new FEZ_Components.Button(FEZ_Pin.Interrupt.Di5); // FEZ_Components.Button Button_HardReset = new FEZ_Components.Button(FEZ_Pin.Interrupt.Di6); // Button_ManualCall.ButtonPressEvent += new FEZ_Components.Button.ButtonPressEventHandler(Button_ManualCall_ButtonPressEvent); // Button_HardReset.ButtonPressEvent += new FEZ_Components.Button.ButtonPressEventHandler(Button_HardReset_ButtonPressEvent);
Then set the sleep mode to 5 seconds to reset the default settings. The LED is lit and the inscription on the “Starting ...” screen is displayed. Reading settings from an SD memory card
// appset = new AppSettings(); appset.ReadSettings();
Network initialization
netinter = new netinteface();
Reading time from RTC. RTC is integrated into the chip. To ensure the progress of the clock, it is necessary to connect the battery v3.3 to the contacts
Utility.SetLocalTime(RealTimeClock.GetTime());
Run time synchronization stream with NTP server. The synchronization interval is set in the settings.
Thread ThreadUpdateTimeNTP = new Thread(UpdateTimeNTPThread); ThreadUpdateTimeNTP.Start();
Starting the call flow. Matches current time and time of calls. In case of coincidence, gives a call.
Thread ThreadTimeBells = new Thread(TimeBells); ThreadTimeBells.Start();
Features of the implementation From Arduino UNO had to be almost immediately abandoned for the following reasons: At the same time, network and SD card operation is not supported. There is an implementation of ladyada Arduino Ethernet + SD , but I didn’t manage to launch it. Arduino supports two parallel threads or two interrupts. In my implementation, I got 4 threads: interruption to the button for manual call serving, synchronization with the NTP server, call tracking time flow, server maintenance flow http. For Arduino, UNO is too much. Compared with the project on the Raspberry pi, the ease of implementation of support for Watchdog. Unfortunately, tracking the presence of a physical Ethernet data medium does not work (it is impossible to determine whether the device is connected to the switch). In the event of a physical break, the network must be initialized. As a solution to this problem, periodically poll (ping) some node (by IP address) on the network. In the absence of a response, re-initialize the network. But this is a CLR flaw for the FEZ Domino microcontroller. Call time tracking is done with second accuracy. To exclude the “call skip” situation, the previous time and the new one are saved. The “call skip” situation arises due to the time spent on executing the program code and the pause in the stream - 1 second.
At the time of the call, the LED is on. RTC is embedded. Enough to power up the pins VBAT IN and Ground. To simplify the templates, html pages were placed in the resources to the project. Used libraries:
Surprise was the absence of replacing strings in substrings in the Net Micro Framework. String.Replace () library from William
The implementation took 3 days x 4 hours = 12 man-hours. Sometimes, with http requests, an exception was detected about the excess of RAM (~ 62KB). Because of this, it was necessary to apply the new settings only when rebooting, not on-line. Costings