Microsoft MVP성태의 닷넷 이야기
사물인터넷: 48. 넷두이노의 C# 네트워크 프로그램 [링크 복사], [링크+제목 복사]
조회: 13161
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

넷두이노의 C# 네트워크 프로그램

(이제는 너무 오래된) 넷두이노 모델 중 "Netduino Plus" 모델은,

넷두이노(Netduino)의 네트워크 설정 방법
; https://www.sysnet.pe.kr/2/0/11702

유선 랜을 지원합니다. 반면 최근 넷두이노 제품을 보면,

Netduino
; https://www.wildernesslabs.co/netduino

이더넷과 와이파이 모델을 모두 판매하고 있는데 대략 각각 $45, $50에 구매할 수 있습니다. 다른 아두이노 호환 모델과 비교해 이 보드의 장점이 있다면... 바로 개발이 무척 쉽다는 점입니다. 어느 정도로 쉽냐면??? 심지어 네트워크의 경우 HttpWebRequest 타입까지도 지원하기 때문에 거의 데스크톱 경험으로 개발할 수 있습니다. 일례로, 다음의 코드는 웹 페이지를 읽어오면 LED를 켜는 기능을 구현하고 있습니다.

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using System.IO;
using System.Text;
using Microsoft.SPOT.Net.NetworkInformation;
using SecretLabs.NETMF.Hardware.NetduinoPlus;

namespace NetworkLED
{
    public class Program
    {
        static byte[] _contentBuffer = new byte[1024];

        public static void Main()
        {
            OutputPort led7 = new OutputPort(Pins.ONBOARD_LED, false);
            EnableNetwork();

            while (true)
            {
                string txt = GetStringFromUrl("https://www.sysnet.pe.kr");

                led7.Write(txt != null && txt.Length != 0);
                Thread.Sleep(1000);
            }
        }

        private static void EnableNetwork()
        {
            Microsoft.SPOT.Net.NetworkInformation.NetworkInterface ni
                = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0];

            ni.PhysicalAddress = new byte[] { 0x00, 0x15, 0x5D, 0x51, 0x01, 0x06 };
            ni.EnableDynamicDns();
            ni.EnableDhcp();
            ni.RenewDhcpLease();
        }

        private static string GetStringFromUrl(string url)
        {
            HttpWebRequest hwr = HttpWebRequest.Create(url) as HttpWebRequest;
            HttpWebResponse response = null;

            try
            {
                response = hwr.GetResponse() as HttpWebResponse;

                Stream respStream = response.GetResponseStream();
                respStream.Read(_contentBuffer, 0, _contentBuffer.Length);

                response.Close();
                hwr.Dispose();

                return new string(Encoding.UTF8.GetChars(_contentBuffer));
            }
            catch { }

            return null;
        }
    }
}

위의 소스 코드를 조금만 변형하면, 웹을 이용한 장치 제어를 매우 쉽게 구현할 수 있습니다. 게다가 라인 단위의 실시간 디버깅 기능도 제공하니 이만큼 편한 개발 환경이 없을 것입니다.

반면, 당연히 단점이 있습니다. 기본적으로 TinyCLR이 올라가기 때문에 점유되는 메모리가 있으니 다른 환경에 비해 메모리 관리를 잘 해야 합니다. 사실 제가 가지고 있던 구형 넷두이노 플러스는 가용한 RAM 용량이 50+ KB라고 하니 애당초 복잡한 응용 프로그램으로는 사용할 수 없다고 봐야 합니다. 그나마 신형 모델(넷두이노 3)은 3배나 넓어졌다고 하지만... ^^; 그래도 164+ KB라고 하니 데스크톱 환경에서처럼 메모리를 신경 쓰지 않고 사용할 수는 없습니다.

그렇긴 하지만, 대개의 경우 IoT 제품들이 구현하는 기능들이 단순하다는 것을 감안하면 메모리가 문제 되는 경우는 많지 않으므로... 뭐랄까, 만약 C# 개발자라면 ^^ 하나쯤 가지고 노는 것도 재미있을만한... 그런 제품입니다. 쓰다 보니 제품 홍보가 되었는데, 실은 다른 보드들의 코딩을 실습하면서 넷두이노가 얼마나 개발 환경이 편했는지 새삼 느끼게 되었다는!!! ^^;




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 10/4/2018]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2021-08-21 12시10분
Enterprise-Grade IoT Full .NET, Real Embedded Secure & Scalable
 - Meadow is a complete, IoT platform with defense-grade security that runs full .NET Standard applications on embeddable microcontrollers.
; https://www.wildernesslabs.co/

Hello, Meadow!
; http://developer.wildernesslabs.co/Meadow/Getting_Started/Hello_World/
정성태

... 31  32  33  34  [35]  36  37  38  39  40  41  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
12742정성태7/30/20217209개발 환경 구성: 585. Azure AD 인증을 위한 사용자 인증 유형
12741정성태7/29/20218359.NET Framework: 1082. Azure Active Directory - Microsoft Graph API 호출 방법파일 다운로드1
12740정성태7/29/20217055오류 유형: 747. SharePoint - InvalidOperationException 0x80131509
12739정성태7/28/20217014오류 유형: 746. Azure Active Directory - IDW10106: The 'ClientId' option must be provided.
12738정성태7/28/20217588오류 유형: 745. Azure Active Directory - Client credential flows must have a scope value with /.default suffixed to the resource identifier (application ID URI).
12737정성태7/28/20216555오류 유형: 744. Azure Active Directory - The resource principal named api://...[client_id]... was not found in the tenant
12736정성태7/28/20217043오류 유형: 743. Active Azure Directory에서 "API permissions"의 권한 설정이 "Not granted for ..."로 나오는 문제
12735정성태7/27/20217547.NET Framework: 1081. C# - Azure AD 인증을 지원하는 데스크톱 애플리케이션 예제(Windows Forms) [2]파일 다운로드1
12734정성태7/26/202123487스크립트: 20. 특정 단어로 시작하거나/끝나는 문자열을 포함/제외하는 정규 표현식 - Look-around
12733정성태7/23/202110897.NET Framework: 1081. Self-Contained/SingleFile 유형의 .NET Core/5+ 실행 파일을 임베딩한다면? [1]파일 다운로드2
12732정성태7/23/20216227오류 유형: 742. SharePoint - The super user account utilized by the cache is not configured.
12731정성태7/23/20217316개발 환경 구성: 584. Add Internal URLs 화면에서 "Save" 버튼이 비활성화 된 경우
12730정성태7/23/20218853개발 환경 구성: 583. Visual Studio Code - Go 코드에서 입력을 받는 경우
12729정성태7/22/20217846.NET Framework: 1080. xUnit 단위 테스트에 메서드/클래스 수준의 문맥 제공 - Fixture
12728정성태7/22/20217326.NET Framework: 1079. MSTestv2 단위 테스트에 메서드/클래스/어셈블리 수준의 문맥 제공
12727정성태7/21/20218267.NET Framework: 1078. C# 단위 테스트 - MSTestv2/NUnit의 Assert.Inconclusive 사용법(?) [1]
12726정성태7/21/20218096VS.NET IDE: 169. 비주얼 스튜디오 - 단위 테스트 선택 시 MSTestv2 외의 xUnit, NUnit 사용법 [1]
12725정성태7/21/20216874오류 유형: 741. Failed to find the "go" binary in either GOROOT() or PATH
12724정성태7/21/20219512개발 환경 구성: 582. 윈도우 환경에서 Visual Studio Code + Go (Zip) 개발 환경 [1]
12723정성태7/21/20217139오류 유형: 740. SharePoint - Alternate access mappings have not been configured 경고
12722정성태7/20/20217011오류 유형: 739. MSVCR110.dll이 없어 exe 실행이 안 되는 경우
12721정성태7/20/20217627오류 유형: 738. The trust relationship between this workstation and the primary domain failed. - 세 번째 이야기
12720정성태7/19/20216963Linux: 43. .NET Core/5+ 응용 프로그램의 Ubuntu (Debian) 패키지 준비
12719정성태7/19/20216117오류 유형: 737. SharePoint 설치 시 "0x800710D8 The object identifier does not represent a valid object." 오류 발생
12718정성태7/19/20216702개발 환경 구성: 581. Windows에서 WSL로 파일 복사 시 root 소유권으로 적용되는 문제파일 다운로드1
12717정성태7/18/20216723Windows: 195. robocopy에서 파일의 ADS(Alternate Data Stream) 정보 복사를 제외하는 방법
... 31  32  33  34  [35]  36  37  38  39  40  41  42  43  44  45  ...