粒子网格算法 pm

This post is originally from my blog on www.jaredwolff.com.

这篇文章最初来自我在www.jaredwolff.com上的博客。

Writing an app takes time. It takes even more time to write one that works with hardware.

编写应用程序需要时间。 编写与硬件兼容的代码需要花费更多时间。

Luckily there's a solution to this problem.

幸运的是,有一个解决此问题的方法。

Enter Blynk.

输入Blynk 。

It's an app that connects to your hardware. It has a drag and drop interface with pre built widgets. That means you can build an app in seconds. Then upload your device sensors readings within minutes.

这是一个连接到您的硬件的应用程序。 它具有带有预构建小部件的拖放界面。 这意味着您可以在几秒钟内构建一个应用程序。 然后在几分钟之内上传设备传感器的读数。

Blynk does work with Argon, Boron or ethernet connected Xenon. Unfortunately it doesn't work over a Particle Mesh network. In this article you'll learn some of the workarounds to get your mesh based projects up an running.

Blynk可以与氩气,硼或以太网连接的氙气一起使用。 不幸的是,它不能在粒子网格网络上工作。 在本文中,您将学习一些变通方法,以使基于网格的项目正常运行。

从粒子云到布林克 (From Particle Cloud to Blynk)

Let's start with the most simple use case: getting data from any Particle Device to Blynk.

让我们从最简单的用例开始:将数据从任何粒子设备获取到Blynk。

The Air Quality data from Particle Squared is perfect for this example. So, i'll be using that.

对于这个例子,来自Particle Squared的空气质量数据是完美的。 所以,我将使用它。

First let's create a new Blynk Project

首先让我们创建一个新的Blynk项目

Grab the Auth Token we'll need that in a bit. You can tap the Auth Token to copy it to your clipboard.

取得Auth Token,我们稍后将需要它。 您可以点击身份验证令牌将其复制到剪贴板。

Next, let's add a SuperChart for this example.

接下来,让我们为该示例添加一个超级图表

Configure the SuperChart to use a Virtual Pin. We don't have access to the actual hardware pins on the device. V0 is a good choice.

配置超级图表以使用虚拟引脚。 我们无权访问设备上的实际硬件引脚。 V0是一个不错的选择。

To update values in Blynk, we'll have to connect somehow. The best way is to use an Integration in the Particle Console.

要更新Blynk中的值,我们必须以某种方式进行连接。 最好的方法是在粒子控制台中使用集成

In Particle Console, click the icon below the terminal icon. Then click on New Integration.

在粒子控制台中,单击终端图标下方的图标。 然后单击“ 新集成”。

Look at the example below to see how I filled everything out.

查看下面的示例,看看我如何填写所有内容。

Particle Squared uses the Event Name as ****blob. For other projects this may be different. Remember: your event name is the same as from Particle.publish(eventName, data).

粒子平方将事件名称用作**** blob 。 对于其他项目,可能会有所不同。 请记住:您的事件名称与来自Particle.publish(eventName, data)名称相同。

The URL is set to use the blink-cloud.com address. According to their API a sample URL looks like:

URL设置为使用blink-cloud.com地址。 根据他们的API,URL示例如下:

I'll also include it here so it's easier to copy

我也将其包含在此处,以便于复制

http://blynk-cloud.com/auth_token/update/pin?value=value

Replace auth_token with the Auth Token we got earlier.

auth_token替换为我们之前获得的Auth令牌

Replace pin with the virtual pin we want to modify. In this case V0

pin替换为我们要修改的虚拟引脚。 在这种情况下, V0

Replace the value with the value you want to use.

用您要使用的值替换该value

We'll reference one of the values in the Particle Squared blob. It's organized like this:

我们将引用“粒子平方” blob中的值之一。 它的组织方式如下:

{"temperature": 28.60,"humidity": 45.00,"sgp30_tvoc": 18,"sgp30_c02": 400,"bme680_temp": 27.36,"bme680_pres": 1012.43,"bme680_hum": 43.80,"bme680_iaq": 43.90,"bme680_temp_calc": 27.30,"bme680_hum_calc": 43.97
}

Particle uses mustache templates. As you can see in the screenshot above, you can set value to {{{temperature}}}.

粒子使用胡须模板 。 如您在上面的屏幕截图中所见,您可以将value设置为{{{temperature}}}

Note: If you're working on your own project, it's important to publish with JSON. As a reference the Particle.publish command looks like:

注意:如果您正在处理自己的项目,则使用JSON发布非常重要。 作为参考, Particle.publish命令如下所示:

// Publish data
Particle.publish("blob", String::format("{\"temperature\":%.2f,\"humidity\":%.2f}",si7021_data.temperature, si7021_data.humidity) , PRIVATE, WITH_ACK);

Click the big blue Save button at the bottom of the screen. Then we can move on to the next step!

点击屏幕底部的蓝色大保存按钮 。 然后,我们可以继续下一步!

测试中 (Testing)

Since creating our Particle Webhook Integration, it's been publishing data to Blynk. Let's go see if it's working.

自创建我们的Particle Webhook集成以来,它一直在将数据发布到Blynk。 让我们看看它是否正在工作。

First, let's go back to the Blynk app. Hit the Play Button in the top Right in Blynk screen.

首先,让我们回到Blynk应用程序。 点击 Blynk屏幕右上方的“播放”按钮

If your integration has been running for a while, you should see the graph populate with data! In the case you don't see anything, let's check the logs.

如果您的集成已经运行了一段时间,您应该会看到图形中填充了数据! 如果您什么都看不到,让我们检查一下日志。

Go back to your integration and scroll towards the bottom. We want to see if there are any errors.

返回到您的集成滚动到底部 。 我们想看看是否有任何错误。

Not sure what that looks like? Here's an example of an integration with errors:

不确定是什么样子? 这是一个有错误的集成示例:

You can scroll further down to investigate why the error has occurred.

您可以进一步向下滚动以调查发生错误的原因。

All the way at the bottom shows the response from the server. Depending on the service, they'll give you information why your API call failed. In my case, I was missing values for two fields.

底部的所有方式均显示了服务器的响应。 根据服务的不同,他们将为您提供API调用失败的原因。 就我而言,我缺少两个字段的值。

Blynk的粒子正在运行! (Particle to Blynk is working!)

You now have a basic way of publishing to a virtual pin in Blynk. There are drawbacks though. Most importantly, you'll have to create an integration for every signal virtual pin. If you have eight readings, that means eight integrations.

您现在有了在Blynk中发布到虚拟图钉的基本方法。 虽然有缺点。 最重要的是,您必须为每个信号虚拟引脚创建一个集成。 如果您有八个读数,则意味着八个积分。

Bummer.

笨蛋

In the next section, you'll learn a different way to configure Blynk. Let's go!

在下一节中,您将学习配置Blynk的另一种方法。 我们走吧!

使用Blynk库的局部网格 (Local Mesh Using Blynk Library)

Unlike the first method, we'll be focusing on changing firmware only.

与第一种方法不同,我们将只专注于更改固件。

We’ll use a Argon, Boron or Ethernet Connected Xenon and one regular Xenon. For the rest of this tutorial, we'll call these devices an “edge router”.

我们将使用氩,硼或以太网连接的氙气和一个普通的氙气。 在本教程的其余部分中,我们将这些设备称为“边缘路由器”。

The Xenon will run the Particle Squared code. Instead of using Particle.publish we'll be using Mesh.publish. This allows us to publish only to the local mesh network.

Xenon将运行粒子平方代码。 而不是使用Particle.publish我们将使用Mesh.publish 。 这使我们只能发布到本地网状网络。

Meanwhile the edge router is listening for the message. It collects the values and then uses the Blynk API to publish to the app.

同时,边缘路由器正在侦听消息。 它收集值,然后使用Blynk API发布到应用程序。

Here are the steps:

步骤如下:

设置我们的边缘路由器 (Setup our Edge Router)

Pull up the menu by pressing Cmd+Shift+P. Type Install Library.

按下Cmd + Shift + P上拉菜单。 键入安装库。

Then enter blynk. The library should download if you haven't already.

然后输入blynk。 如果尚未下载该库,则应下载。

Once installed you can include the library at the top of your .ino file like so:

安装后,您可以将库包含在.ino文件顶部,如下所示:

#include <blynk.h>

In our setup() function let's init the Blynk library:

在我们的setup()函数中,让我们初始化Blynk库:

// Put initialization like pinMode and begin functions here.
Blynk.begin(auth);

In our setup() function, subscribe to the temperature event. The connected Xenon will generate this event.

在我们的setup()函数中,订阅temperature事件。 连接的氙气将生成此事件。

// Subscribe to temperature events
Mesh.subscribe("temperature",tempHandler);

Define tempHandler like this for now:

现在像这样定义tempHandler

// Temperature event handler for mesh
void tempHandler(const char *event, const char *data){
}

In the loop() function make sure we have Blynk.run();

loop()函数中,确保我们有Blynk.run();

// loop() runs over and over again, as quickly as it can execute.
void loop() {// The core of your code will likely live here.Blynk.run();
}

Finally, for tempHandler we can add a debug print to monitor events. I've used something like this:

最后,对于tempHandler我们可以添加调试打印来监视事件。 我用过这样的东西:

Serial.printlnf("event=%s data=%s", event, data ? data : "NULL");

Particle uses this in some of their examples. It's perfect for our purposes as well!

在他们的一些示例中,Particle使用了此方法。 这对于我们的目的也是完美的!

Note: make sure you have Serial.begin() called in your Setup() function!

注意:确保在Setup()函数中调用了Serial.begin()

So now we have tempHandler to receive data from the Xenon. The edge router can now take that data and upload it to Blynk. Let's use the Blynk.virtualWrite function for this:

所以现在我们有了tempHandler来接收来自氙气的数据。 边缘路由器现在可以获取该数据并将其上传到Blynk。 让我们为此使用Blynk.virtualWrite函数:

// Write the data
Blynk.virtualWrite(V0, data);

This will write the temperature value from a Xenon to the V0 pin. If you used something other than V0, be sure to change that value here. (This is the same setup as the previous Particle Cloud to Blynk example)

这会将氙气的温度值写入V0引脚。 如果您使用的不是V0,请确保在此处更改该值。 (这与前面的“ 粒子云到Blynk”示例的设置相同)

The final code for the edge router should look something like this. Compile a flash it to your device when you're ready!

边缘路由器的最终代码应如下所示。 准备好将Flash编译到设备上!

/** Project blynk-argon-forwarder* Description: Argon Blynk forwarder for Particle Mesh. Forwards data from mesh connected devices to Blynk.* Author: Jared Wolff* Date: 7/25/2019*/#include <blynk.h>char auth[] = "<ENTER YOUR AUTH KEY>";// Temperature event handler for mesh
void tempHandler(const char *event, const char *data){Serial.printlnf("event=%s data=%s", event, data ? data : "NULL");// Write the dataBlynk.virtualWrite(V0, data);
}// setup() runs once, when the device is first turned on.
void setup() {// Serial for debuggingSerial.begin();// Put initialization like pinMode and begin functions here.Blynk.begin(auth);// Subscribe to temperature eventsMesh.subscribe("temperature",tempHandler);}// loop() runs over and over again, as quickly as it can execute.
void loop() {// The core of your code will likely live here.Blynk.run();}

Remember to set auth using the AUTH TOKEN in the Blynk app!

切记在Blynk应用程序中使用AUTH TOKEN设置auth

设置氙气 (Setting up a Xenon)

Create a new project. This time it will be for the Xenon capturing "temperature data."

创建一个新项目。 这次将是氙气捕获“温度数据”的时间。

Let's add a variable called time_millis to the top of the file. The type is system_tick_t. We'll use it to create a simple delay timer for the temperature readings.

让我们在文件顶部添加一个名为time_millis的变量。 类型是system_tick_t 。 我们将使用它为温度读数创建一个简单的延迟计时器。

// Global variable to track time (used for temp sensor readings)
system_tick_t time_millis;

For the interval, let's use a preprocessor define

对于间隔,让我们使用预处理器定义

#define INTERVAL_MS 2000

Now let's tie those together in the loop() function. We'll use an if statement to compare our current system time with that of the last event plus offset. If you ever need a simple timer, this is one of the best ways to do it!

现在让我们在loop()函数中将它们绑在一起。 我们将使用if语句将当前系统时间与上一个事件加偏移量的时间进行比较。 如果您需要一个简单的计时器,这是最好的方法之一!

// Check if our interval > 2000msif( millis() - time_millis > INTERVAL_MS ) {}

Once we're inside, make sure you reset timer_millis:

一旦进入内部,请确保您重置timer_millis

//Set time to the 'current time' in millistime_millis = millis();

Then, we'll generate the temperature value using the random() function. We'll use the two parameter variant. That way we can set the minimum value and the maximum value:

然后,我们将使用random()函数生成温度值。 我们将使用两个参数的变体。 这样我们可以设置最小值和最大值:

// Create a random numberint rand = random(20,30);

Finally we'll Mesh.publish the value:

最后,我们将Mesh.publish值:

// Publish our "temperature" valueMesh.publish("temperature",String::format("%d",rand));

When this example runs, the temperature is broadcast to the mesh network. Then, the edge router receives it and forwards it on to Blynk!

运行此示例时,温度将广播到网状网络。 然后,边缘路由器将其接收并将其转发给Blynk!

You can flash this firmware whenever you're ready. Here's the full code for the Xenon so you can cross compare:

准备就绪后,即可刷新此固件。 这是Xenon的完整代码,因此您可以交叉比较:

/** Project blynk-xenon-rgb* Description: Recieve RGB level from connected Edge Router. Sends simiulated temperature values via mesh to the Blynk cloud.* Author: Jared Wolff* Date: 7/25/2019*/// How often we update the temperature
#define INTERVAL_MS 2000// Global variable to track time (used for temp sensor readings)
system_tick_t time_millis;
// setup() runs once, when the device is first turned on.
void setup() {// Set time to 0time_millis = 0;}// loop() runs over and over again, as quickly as it can execute.
void loop() {// Check if our interval > 2000msif( millis() - time_millis > INTERVAL_MS ) {//Set time to the 'current time' in millistime_millis = millis();// Create a random numberint rand = random(20,30);// Publish our "temperature" valueMesh.publish("temperature",String::format("%d",rand));}}

给它一个测试! (Give it a test!)

Now that we've programmed both devices let's get them talking to each other.

现在,我们已经为这两种设备编程了,让我们让它们彼此交谈。

I've already set up the Argon with a mesh network called 8f-9. I'll explain how to get the Xenon connected with the CLI. You can also used the Particle App.

我已经使用称为8f-9的网状网络设置了Argon 我将解释如何使Xenon与CLI连接。 您也可以使用粒子应用程序。

First, let's connect the Xenon to USB and get it into Listening Mode. After connect, hold the Mode button until blinking blue.

首先,让我们将Xenon连接到USB,并使它进入聆听模式。 连接后,按住“ 模式”按钮,直到闪烁蓝色。

Then use the CLI to set up the mesh network. First let's get the device ID:

然后使用CLI设置网状网络。 首先让我们获取设备ID:

Jareds-MacBook-Pro:nrfjprog.sh jaredwolff$ particle identify
? Which device did you mean?/dev/tty.usbmodem146401 - Argon
❯ /dev/tty.usbmodem146101 - Xenon

If you have multiple devices connect, make sure you select the right one! If prompted, select a device. Your output should look something like:

如果有多个设备连接,请确保选择正确的设备! 如果出现提示,请选择设备。 您的输出应类似于:

Your device id is e00fce682d9285fbf4412345
Your system firmware version is 1.3.0-rc.1

We'll need the id for the next step. Now, let's run the particle mesh command.

下一步需要ID 。 现在,让我们运行particle mesh命令。

particle mesh add <xenon id> <id of your argon, boron, etc>

Here's an example below:

下面是一个示例:

particle mesh add e00fce682d9285fbf4412345 hamster_turkey
? Enter the network password [hidden]
▄ Adding the device to the network...

At the end of it you'll see:

在它的结尾,您将看到:

Done! The device should now connect to the cloud.

This process is not perfect. During the Adding the device to the network... stage, I had to remove the Xenon using particle mesh remove. Then re-run the particle mesh add command after resetting the Argon.

这个过程并不完美。 在“ Adding the device to the network...阶段,我不得不使用particle mesh remove Adding the device to the network... particle mesh remove氙气。 然后在重置Argon后重新运行particle mesh add命令。

Now here comes to finale.

现在到了结局。

Connect the two devices to serial using particle serial monitor --follow

使用particle serial monitor --follow将两个设备连接到串行- particle serial monitor --follow

If you have the two devices connected, particle serial monitor will prompt you to select:

如果您连接了两个设备, particle serial monitor将提示您选择:

Jareds-MacBook-Pro:blynk-xenon-rgb jaredwolff$ particle serial monitor --follow
Polling for available serial device...
? Which device did you mean? /dev/tty.usbmodem146101 - Xenon
Opening serial monitor for com port: "/dev/tty.usbmodem146101"
Serial monitor opened successfully:

Remember: You have to run particle serial monitor for each device you want to connect to.

切记:您必须为要连接的每个设备运行particle serial monitor

If all is working, you'll likely see some output from the edge router!

如果一切正常,您可能会看到边缘路由器的一些输出!

Serial monitor opened successfully:
event=temperature data=21
event=temperature data=28
event=temperature data=21
event=temperature data=27
event=temperature data=28
event=temperature data=26
event=temperature data=23
event=temperature data=26
event=temperature data=21

Looking at the app, the Super Chart should be reacting to this new data.

查看该应用程序, 超级图表应对此新数据做出React。

Compare the last value in the command line to the last on the chart? Do they match? If so, you made it to the end of this example!

将命令行中的最后一个值与图表中的最后一个进行比较? 他们匹配吗? 如果是这样,那么您就可以完成本示例!

结论 (Conclusion)

In this tutorial you've learned how to forward Particle Cloud data to Blynk. You've also learned how to do the same using a Particle Argon, Boron or ethernet connected Xenon. Awe yea.

粒子网格算法 pm_使粒子网格与Blynk一起使用的2种最佳方法相关推荐

  1. 粒子群算法(8)---混合粒子群算法的实现

    混合粒子群算法将全局粒子群算法与局部粒子群算法结合,其速度更新采用公式 其中G(k+1)是全局版本的速度更新公式,而L(k+1)是局部版本的速度更新公式,混合粒子群算法采用H(k+1)的公式. 位置更 ...

  2. 粒子群算法tsp java_粒子群算法解决TSP问题汇总.doc

    PAGE \* MERGEFORMAT 14 河南理工大学计算机科学与技术学院课程设计报告 2014- 2015学年第一学期 课程名称 Java语言程序设计 设计题目 利用粒子群算法解决TSP问题 姓 ...

  3. 粒子群算法tsp java_粒子群算法解决TSP问题

    1. 粒子群算法简介 粒子群算法(particle swarm optimization,PSO)由Kennedy和Eberhart在1995年提出,属于进化算法的一种,是通过对模拟鸟群扑食行为设计的 ...

  4. 粒子群算法python_python实现粒子群算法

    粒子群算法 粒子群算法源于复杂适应系统(Complex Adaptive System,CAS).CAS理论于1994年正式提出,CAS中的成员称为主体.比如研究鸟群系统,每个鸟在这个系统中就称为主体 ...

  5. 粒子群算法java_基于粒子群算法求解求解TSP问题(JAVA)

    一.TSP问题 TSP问题(Travelling Salesman Problem)即旅行商问题,又译为旅行推销员问题.货郎担问题,是数学领域中著名问题之一.假设有一个旅行商人要拜访n个城市,他必须选 ...

  6. 算法题目中元素为二元(坐标)的几种解决方法

    方法一,开结构体(比较好用) struct pp {int x,y; }; queue<node>q; pp st; st.x=sx;st.y=sy; q.push(st); //q是队列 ...

  7. 粒子群算法(1)----粒子群简要

    一.历史粒子群算法  从复杂适应系统衍生PSO算法(Complex Adaptive System,CAS).CAS理论于1994年正式提出,CAS中的成员称为主体.比方研究鸟群系统,每一个鸟在这个系 ...

  8. 【MATLAB】混合粒子群算法原理、代码及详解

    目录 1.算法 1.1.原理 1.2.性能比较 1.3.步骤 2.代码 2.1.源码及注释 2.2.执行与效果 1.算法 1.1.原理 \qquad建议没接触过粒子群算法的朋友先看较为基础的全局粒子群 ...

  9. 【转】粒子群算法----粒子群算法简介

    一.粒子群算法的历史  粒子群算法源于复杂适应系统(Complex Adaptive System,CAS).CAS理论于1994年正式提出,CAS中的成员称为主体.比如研究鸟群系统,每个鸟在这个系统 ...

最新文章

  1. Linux中rsync备份数据使用实例
  2. 如何查看mysql连接相关参数
  3. enyo官方开发入门教程翻译一Controls之Buttons
  4. jquery easyui combobox设置默认选中第一项
  5. 操作系统的中断,陷阱,异常
  6. Know more about commit
  7. LeetCode 1569. 将子数组重新排序得到同一个二叉查找树的方案数(DP)
  8. Spark Streaming + Elasticsearch构建App异常监控平台
  9. redis入门——Spring整合篇
  10. 手把手教你用jmeter做压力测试(详图)
  11. Unity世界坐标转换屏幕坐标(测试)
  12. UC浏览器去广告、联网、升级(支持新版8.1)
  13. Bandizip下载安装教程
  14. 3.VM虚拟机网络设置--仅主机模式
  15. 数据挖掘工具---Spark SQL使用
  16. 诚龙网刻报错_诚龙网刻|诚龙网维全自动PXE网刻工具 V 11.0 官方版-完美软件下载...
  17. Docker可视化工具 DockerUI 和 Shipyard 的区别
  18. 编程题 java 密码锁_Java实现 蓝桥杯VIP 算法提高 密码锁
  19. 手机上好用的记事本工具
  20. 沐神点赞!同济子豪兄精读AI经典论文,包括图像分类、目标检测、生成对抗网络、轻量化卷积神经网络等领域...

热门文章

  1. Ansible-----循环
  2. 2015年10月13日
  3. .NET Framework 工具
  4. Atitit. 提升软件开发效率and 开发质量---java 实现dsl 4gl 的本质and 精髓 O725
  5. [导入]ASP.NET MVC框架开发系列课程(1):MVC模式与ASP.NET MVC框架概述.zip(8.80 MB)
  6. Weblogic 节点启动
  7. 怎样在减少数据中心成本的同时不牺牲性能?
  8. Cloud in Action: Install OpenStack Ocata from scratch
  9. 微习惯虽好,但是最重要的还是坚持
  10. CentOS系统根目录组织结构