public ActionResult SendCommand(bool state) { MqttHelper mqttHelper = new MqttHelper("", "asd"); mqttHelper.SendCommand(state ? Commands.Start1 : Commands.Stop1); return(Json("chamara", JsonRequestBehavior.AllowGet)); }
private void InitPassMessagesToSubscribers() { Receive <MqttMessageEvent>(mqttEvent => { var i = 0; //todo resolve double match topic checking inside actor and here foreach (var sub in _subs .Where(x => x.Type == TriggerTypeEnum.Mqtt && x is SubToMqtt mx && MqttHelper.IsSubscribed(patternTopic: mx.Topic, actualTopic: mqttEvent.Topic) && !x.Subscriber.IsNobody())) { i++; sub.Subscriber.Tell(mqttEvent); } _logger.Debug($"{nameof(MqttMessageEvent)} delivered to {i} actors"); }); Receive <ActionResultEvent>(actionEvent => { var i = 0; //todo resolve double match action checking inside actor and here foreach (var sub in _subs .Where(x => x.Type == TriggerTypeEnum.Action && x is SubToAction ma && actionEvent.ActionName.Equals(ma.ActionName, StringComparison.InvariantCultureIgnoreCase))) { i++; sub.Subscriber.Tell(actionEvent); } _logger.Debug($"{nameof(ActionResultEvent)} delivered to {i} actors"); }); }
public ActionResult SendCommand(bool state, string message, string topic, string ipAddress) { MqttHelper mqttHelper = new MqttHelper(ipAddress, topic); mqttHelper.SendCommand(state?Commands.Start1:Commands.Stop1); return(Json("chamara", JsonRequestBehavior.AllowGet)); }
public async Task StartAsync(CancellationToken cancellationToken) { _logger.LogInformation("Scraping Service starting"); _mqttHelper = new MqttHelper(_mqttOptions, _logger); _gameDayTimer = new Timer(PollGameDay, null, TimeSpan.Zero, TimeSpan.FromHours(24)); return; }
//private Dictionary<System.Guid, ScanContext> scanContextMap = new Dictionary<System.Guid, ScanContext>(); // we may use a dictionary to store many scans waiting for results ... let's start with one for now // Use this for initialization void Start() { angleRadian = horizontalAngle * (Math.PI / 180); gaze = CoreServices.InputSystem.GazeProvider; cursor?.SetActive(false);//disable cursor shutterSound = GetComponent <AudioSource>() as AudioSource; labeler = GetComponent <ObjectLabeler>() as ObjectLabeler; mqttHelper = GetComponent <MqttHelper>() as MqttHelper; mqttHelper.Subscribe(ResultReceiver); // Debug.Log("File path " + Application.persistentDataPath); // take lower resolution available if ((PhotoCapture.SupportedResolutions != null) && (PhotoCapture.SupportedResolutions.Count() > 0)) { cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).Last(); ratio = (float)cameraResolution.height / (float)cameraResolution.width; Debug.Log("Resolution " + cameraResolution.height + " x " + cameraResolution.width); } else { ratio = 9f / 16f; } scanContext = new ScanContext(horizontalAngle, ratio, Camera.main.transform); // create a context with Camera position. ScannerScreen.SetActive(false); // remove the scanner Vector3 scale = ScannerScreen.transform.localScale; scale.x = 2f * scannerScreenDistance * (float)Math.Tan(angleRadian / 2f); scale.y = scale.x * ratio; // scale the entire photo on height ScannerScreen.transform.localScale = scale; Debug.Log("scanContext init " + scanContext.ToString()); // Create a PhotoCapture object PhotoCapture.CreateAsync(false, delegate(PhotoCapture captureObject) { photoCaptureObject = captureObject; CameraParameters cameraParameters = new CameraParameters(); cameraParameters.hologramOpacity = 0.0f; cameraParameters.cameraResolutionWidth = cameraResolution.width; cameraParameters.cameraResolutionHeight = cameraResolution.height; cameraParameters.pixelFormat = CapturePixelFormat.BGRA32; //cameraParameters.pixelFormat = showPicture == true ? CapturePixelFormat.BGRA32 : CapturePixelFormat.JPEG; photoCaptureObject.StartPhotoModeAsync(cameraParameters, delegate(PhotoCapture.PhotoCaptureResult result) { // Take a picture Debug.Log("camera ready to take picture"); }); }); PointerUtils.SetGazePointerBehavior(PointerBehavior.AlwaysOn); }
private void MqttServer_OnClientApplicationMessageReceive(MqttSession session, MqttClientApplicationMessage message) { if (message.Topic == "ndiwh是本地AIHDniwd") // 用户客户端的压力测试 { mqttServer.PublishTopicPayload(session, message.Topic, message.Payload); } if (session.Protocol == "HUSL") { // 当前的会话是同步通信的情况 if (message.Topic == "A") { // 测试回传一条数据信息 mqttServer.PublishTopicPayload(session, "B", Encoding.UTF8.GetBytes("这是回传的一条测试数据")); } else if (message.Topic == "B") { System.Threading.Thread.Sleep(1000); // 假设服务器处理数据要耗费10秒钟 for (int i = 0; i < 10; i++) { System.Threading.Thread.Sleep(1000); mqttServer.ReportProgress(session, ((i + 1) * 10).ToString( ), $"当前正在处理{i + 1}步"); } System.Threading.Thread.Sleep(1000); mqttServer.PublishTopicPayload(session, StringResources.Language.SuccessText, Encoding.UTF8.GetBytes("B操作处理成功")); } else if (message.Topic == "C") { // 回传一条1M的数据 byte[] buffer = new byte[1024 * 1024]; for (int i = 0; i < buffer.Length; i++) { buffer[i] = 0x30; } mqttServer.PublishTopicPayload(session, "C", buffer); } else if (message.Topic == "D") { // 返回一条操作失败的信息 mqttServer.ReportOperateResult(session, "当前的功能码不支持!"); } else if (message.Topic == "E") { // 返回一条操作结果的信息 if (random.Next(100) < 50) { mqttServer.ReportOperateResult(session, new OperateResult <string>("当前的结果为失败信息")); } else { mqttServer.ReportOperateResult(session, OperateResult.CreateSuccessResult("成功")); } } else if (message.Topic == "F") { // 返回当前对象支持的API信息 mqttServer.PublishTopicPayload(session, "list", Encoding.UTF8.GetBytes(JArray.FromObject(MqttHelper.GetSyncServicesApiInformationFromObject(this)).ToString( ))); } else { // 如果不回传数据,客户端就会引发超时,关闭连接 // 下面是示例,支持了一个CheckName的接口数据,返回类型必须是 OperateResult<string> // mqttServer.ReportObjectApiMethod( session, message, this ); } } Invoke(new Action(() => { if (!isStop) { receiveCount++; if (message.Payload?.Length > 100) { textBox8.AppendText($"Cliend Id[{message.ClientId}] Topic:[{message.Topic}] Payload:[{Encoding.UTF8.GetString( message.Payload.SelectBegin( 100 ) )}...]" + Environment.NewLine); } else { textBox8.AppendText($"Cliend Id[{message.ClientId}] Topic:[{message.Topic}] Payload:[{Encoding.UTF8.GetString( message.Payload )}]" + Environment.NewLine); } } })); }
public void SetMqttListener(MqttHelper mqttHelper) { _mqttHelper = mqttHelper; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory, IOptions <SenparcSetting> senparcSetting, IOptions <SenparcWeixinSetting> senparcWeixinSetting, IHostApplicationLifetime appLifetime, MqttHelper mQtt) { #region 控制程序生命周期 // 发生在应用启动成功以后,也就是Startup.Configure()方法结束后。 //appLifetime.ApplicationStarted.Register(async () => //{ // await mQtt.ConnectMqttServerAsync(); //}); //// 发生在程序正在完成正常退出的时候,所有请求都被处理完成。程序会在处理完这货的Action委托代码以后退出 //appLifetime.ApplicationStopped.Register(async () => //{ // MqttHelper.IsReconnect = false; // await MqttHelper.MqttClient.DisconnectAsync(); //}); // 发生在程序正在执行退出的过程中,此时还有请求正在被处理。应用程序也会等到这个事件完成后,再退出。 //appLifetime.ApplicationStopping.Register(() => //{ //}); #endregion if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseRouting(); app.UseAuthorization(); app.UseSession(); #region 微信相关 //RegisterService.Start(env, senparcSetting.Value) // .UseSenparcGlobal() // 启动 CO2NET 全局注册,必须! // .RegisterTraceLog(ConfigTraceLog) //配置TraceLog // .UseSenparcWeixin(senparcWeixinSetting.Value, senparcSetting.Value) // .RegisterMpAccount(senparcWeixinSetting.Value, "【刘哲测试】公众号"); app.UseSenparcGlobal(env, senparcSetting.Value, globalRegister => { #region 注册日志(按需,建议) globalRegister.RegisterTraceLog(ConfigTraceLog);//配置TraceLog #endregion }, true).UseSenparcWeixin(senparcWeixinSetting.Value, weixinRegister => { weixinRegister.RegisterMpAccount(senparcWeixinSetting.Value, "【刘哲测试】公众号"); }); app.UseMessageHandlerForMp("/WeixinAsync", CustomMessageHandler.GenerateMessageHandler, options => { //此处为委托,可以根据条件动态判断输入条件(必须) options.AccountSettingFunc = context => senparcWeixinSetting.Value; //对 MessageHandler 内异步方法未提供重写时,调用同步方法(按需) options.DefaultMessageHandlerAsyncEvent = DefaultMessageHandlerAsyncEvent.SelfSynicMethod; }); #endregion app.UseEndpoints(endpoints => { endpoints.MapHub <ChatHub>("/chathub"); endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); }
public void IsSubscribedTests(string patternTopic, string topic, bool expected) { Assert.Equal(expected, MqttHelper.IsSubscribed(patternTopic, topic)); }