专业的编程技术博客社区

网站首页 > 博客文章 正文

基于NET6的可视化、跨平台物联网网关:IOTGateway

baijin 2024-11-30 11:14:11 博客文章 6 ℃ 0 评论

IoTSharp 是一个 基于.Net Core 开源的物联网基础平台, 支持 HTTP、MQTT 、CoAp 协议, 属性数据和遥测数据协议简单类型丰富,简单设置即可将数据存储在PostgreSql、MySql、Oracle、SQLServer、Sqlite,是一个用于数据收集、处理、可视化与设备管理的 IoT 平台。

gitee仓库地址:https://gitee.com/dotnetchina/IoTSharp?_from=gitee_search

官方文档:https://docs.iotsharp.io/docs/intro ,具体介绍请查看官方文档。此文章只讲部署。

官方的部署方式为docker部署,但阿里云/腾讯云的windows系统本身就是虚拟机,不支持二次虚拟化,也就是在阿里云windows服务器是不能运行docker的,只能采用源码编译的方式进行编译部署。

开发IDE:vs2022

环境:netcore 6,nodejs,npm,yarn

数据库:mysql,内存存储

1.下载源码

git clone https://github.com/IoTSharp/IoTSharp.git

也可以根据自己的环境在gitee或github上下载zip文件,解压。

2.服务端源码编译

进入根目录,用vs2022打开IoTSharp.sln,右键“IoTGateway”项目,重新生成,编译项目,等待项目编译成功,第一次时间可能比较长,耐心等待。

3.修改配置文件

编译成功后,进入编译后的程序目录,打开appsettings.Production.json文件,根据需要修改参数配置,修改完成后双击“IoTSharp.exe”即可,会自动生成数据库(iotsharp)和对应的表,完成后可检查数据库是否成功。

appsettings.Production.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  },
  "DataBase": "MySql",
  "ConnectionStrings": {
    "IoTSharp": "server=localhost;user=root;password=123456;database=IoTSharp",
    "TelemetryStorage": "server=localhost;user=root;password=123456;database=IoTSharp"
  },
  "JwtKey": "iotsharpiotsharpiotsharpiotsharpiotsharp",
  "JwtExpireHours": 3,
  "JwtIssuer": "IoTSharp.Net",
  "JwtAudience": "IoTSharp.Net",
  "EventBusStore": "InMemory",
  "EventBusMQ": "InMemory",
  "TelemetryStorage": "Sharding"
}

4.前端编译

因前端使用angular,需要安装node、npm或yarn才可以进行前端编译,我这里用的yarn。dos进入"根目录\IoTSharp\ClientApp"文件夹,执行命令yarn,自动安装依赖。

yarn

依赖安装完成后,执行命令yarn build进行编译,成功后会在"根目录\IoTSharp\ClientApp"文件夹下生成dist文件夹,前端编译成功。

5.部署

服务端双击““IoTSharp.exe””或dotnet 命令运行即可,客户端使用nginx部署,在端口4441监听,通过nginx做下转发,将请求接口转发到服务端,配置完成后启动nginx即可,nginx配置如下所示。

    server {
		listen 44411;
		# gzip config
		gzip on;
		gzip_min_length 1k;
		gzip_comp_level 9;
		gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
		gzip_vary on;
		gzip_disable "MSIE [1-6]\.";
      
		root C:\iotsharp\dist;
		include mime.types;

		location /api/ {
        proxy_pass http://localhost:5000/api/; #修改此地址为后台服务地址
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $host:$server_port;
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_connect_timeout   1;
        proxy_buffering off;
        chunked_transfer_encoding off;
        proxy_cache off;
        proxy_send_timeout      30m;
        proxy_read_timeout      30m;
        client_max_body_size    100m;
		}
		
		location / {
			index  index.html;
		}

    }

6.打开浏览器,输入:http://localhost:44411/,第一次运行进入初始化界面,填写完成后点击注册,进入登录界面,密码为刚输入的密码。

7.登录成功

8.3D界面


Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表