I. Overview
In order to make up for the loss of code, wooden boat IOT platform is working overtime to carry out research and development, the back is not just for the IOT device access to the report, alarm, video management, configuration data visualization screen, there will be a rapid construction of the micro-services platform, the use of tools to generate micro-services based on the database table, intermediate services, which will allow programmers to quickly complete the tasks handed over to the BOSS, so that in the involution of this society can to have a place in this involutional society. These are empty words without accomplishing the task, and now the purpose of this post is the author has the ability to develop an excellent IOT platform, first introduce a more prominent feature, is that you can add network components based on shared or independent configuration, the following to introduce how to add network components.
One click to run the packaged finished download:/s/11hcf9ieCkJxlGrzvIuxeQA?pwd=ajsr
Tested by: fanly
Test Password: 123456
In order to let you save time, can run the product as soon as possible to see the effect, there is a key to run above the packaged product can be downloaded to test run.
Second, how to test run
Here is the catalog structure, the
IDE:consul Registry
:: Gateway
:: Microservices
apache-skywalking-apm: skywalking link tracking
Above is the directory structure, you do not need to run one by one, just open and run, if you need to test skywalking, only need apache-skywalking-apm\bin\ file on it, the following is the running interface
III. How to add components
1. Add the http service component.
Open the platform interface, then click Device Access ->Network Components, then you can see the following interface
And then click on the new component or edit the component, after the completion of the start state is closed state, at this time and can not be accessed for the function of the component call, only to open the start state, you can access the call!
Above is the http service component, startup is complete, how to set up the webservice and swagger, you can access the webservice and swagger whether you can access the
2. Add/Edit Tcp Service Components
When adding/editing the Tcp component, set Host:127.0.0.1 ,port:248 and there are options for the parsing method, inside the options there are not processed, fixed length, delimiter, custom script, below we will look at custom scripts
Add the script as follows:
(4).Handler( function(buffer){ var buf = (buffer,1,4); ().Result(buf); }).Handler( function(buffer){(8).Result(buffer);} ).Handler(function(buffer){ ('Processing complete','gb2312').Complete(); } )
The TCP-based service code is as follows, and needs to inherit from TcpBehavior
internal class TcpDeviceDataService : TcpBehavior, ITcpDeviceDataService { private readonly IDeviceProvider _deviceProvider; public TcpDeviceDataService(IDeviceProvider deviceProvider) { _deviceProvider = deviceProvider; } public override void Load(string clientId, NetworkProperties tcpServerProperties) { var deviceStatus = _deviceProvider.IsConnected(clientId); this.().Subscribe(async buffer => await ParserBuffer(buffer)); } public override void DeviceStatusProcess(DeviceStatus status, string clientId, NetworkProperties tcpServerProperties) { //throw new NotImplementedException(); } public async Task ParserBuffer(IByteBuffer buffer) { List<string> result = new List<string>(); while ( > 0) { ((this.(), ("gb2312"))); } // var str= (, Encoding.UTF8); var byteBuffer = (); ("\r\n", Encoding.UTF8); ("Processing complete.", ("gb2312")); await (byteBuffer); // await ("Message Received",("gb2312")); this.(); } public Task<bool> ChangeDeviceStage(string deviceId) { throw new NotImplementedException(); } }
The results with the Test Tcp debugging tool are as follows
3. Add/edit UDP service components
When adding/editing UDP components, set Host:127.0.0.1 ,port:267 and enable or disable multicast.
And based on the udp service code is as follows, need to inherit from theUdpBehavior
internal class UdpDeviceDataService : UdpBehavior, IUdpDeviceDataService { public Task<bool> ChangeDeviceStage(string deviceId) { throw new NotImplementedException(); } public override async Task Dispatch(IEnumerable<byte> bytes) { await ("\r\n", Encoding.UTF8); await ("Processing complete.", ("gb2312")); } }
The test results are as follows:
4. Add/Edit WebSocket Service Components
When adding/editing WebSocket components, set Host:127.0.0.1 ,port:55
And based on the websocket service code is as follows, need to inherit from WSBehavior
internal class WSDeviceDataService : WSBehavior, IWSDeviceDataService { protected override void OnMessage(MessageEventArgs e) { this.($"send:{},\r\n reply:hello,welcome to you!",ID); } protected override void OnOpen() { } }
The test results are as follows:
5. Add/edit UDP service components
When adding/editing WebSocket components, set Host:127.0.0.1 ,port:345
Add the file with the following script:
syntax = "proto3"; package Greet; service Greeter { // Sends a greeting rpc ChangeDeviceStage (DeviceRequest) returns (DeviceReply) {} } message DeviceRequest { string deviceId = 1; } message DeviceReply { bool message = 1; }
Then create GreeterBehavior, inheriting, IServiceBehavior, with the following code
public partial class GreeterBehavior : , IServiceBehavior { private ServerReceivedDelegate received; public event ServerReceivedDelegate Received { add { if (value == null) { received += value; } } remove { received -= value; } } public string MessageId { get; } = ().ToString("N"); public async Task Write(object result, int statusCode = 200, string exceptionMessage = "") { if (received == null) return; var message = new TransportMessage(MessageId, new ReactiveResultMessage { ExceptionMessage = exceptionMessage, StatusCode = statusCode, Result = result }); await received(message); } public T CreateProxy<T>(string key) where T : class { return <IServiceProxyFactory>().CreateProxy<T>(key); } public object CreateProxy(Type type) { return <IServiceProxyFactory>().CreateProxy(type); } public object CreateProxy(string key, Type type) { return <IServiceProxyFactory>().CreateProxy(key, type); } public T CreateProxy<T>() where T : class { return <IServiceProxyFactory>().CreateProxy<T>(); } public T GetService<T>(string key) where T : class { if (<T>(key)) return <T>(key); else return <IServiceProxyFactory>().CreateProxy<T>(key); } public T GetService<T>() where T : class { if (<T>()) return <T>(); else return <IServiceProxyFactory>().CreateProxy<T>(); } public object GetService(Type type) { if ((type)) return (type); else return <IServiceProxyFactory>().CreateProxy(type); } public object GetService(string key, Type type) { if ((key, type)) return (key, type); else return <IServiceProxyFactory>().CreateProxy(key, type); } public void Publish(IntegrationEvent @event) { GetService<IEventBus>().Publish(@event); } }
And the grpc-based service code is as follows, which needs to inherit from the GreeterBehavior just created
public class GrpcDeviceDataService : GreeterBehavior, IGrpcDeviceDataService { public override Task<DeviceReply> ChangeDeviceStage(DeviceRequest request, ServerCallContext context) { return (new DeviceReply { Message = true }) ; } }
Here are the test results:
6. Add/Edit MQTT Service Components
When adding/editing WebSocket components, set Host:127.0.0.1 ,port:425
And based on the mqtt service code is as follows, need to inherit from MqttBehavior
public class MQTTDeviceDataService : MqttBehavior, IMQTTDeviceDataService { public override async Task<bool> Authorized(string username, string password) { bool result = false; if (username == "admin" && password == "123456") result = true; return await (result); } public async Task<bool> IsOnline(string deviceId) { return await base.GetDeviceIsOnine(deviceId); } public async Task Publish(string deviceId, WillMessage message) { var willMessage = new MqttWillMessage { WillMessage = , Qos = , Topic = , WillRetain = }; await Publish(deviceId, willMessage); await RemotePublish(deviceId, willMessage); } }
Here are the test results:
III. Summary
Wooden boat IOT platform will be in the github open source community version, you can freely change the code, used for commercial projects, but not self-owned platforms, such as low-code platforms, IOT platforms, etc., if you violate the consequences of their own, and it is best not to change the namespace, and then say with the company that they are their own R & D. If I know, I blog the whole network to inform the person, the previous surging-related events even if the If you know, I will inform this person in the whole network of my blog, and the previous incidents related to surging will be forgotten. If you encounter difficulties, more urgent words, you can contact the author, plus group: 744677125