这篇文章描述了如何创建一个IoT项目,项目使用Arduino通过Temboo和Parse.com将推送消息发送到Android智能手机 例如,我们将构建一个基于Arduino和Android的警报系统,这是一个有趣的物联网(IoT)示例,并且该项目的目的是使用连接到Arduino板上 的红外传感器(PIR)来构建警报 将消息推送到Android智能手机 该项目融合了不同的技术和平台,我们使它们一起工作!

警报系统使用两个平台来简化项目:

  • 滕博
  • Parse.com

物联网项目概述

在深入研究该项目之前,描述这两个平台非常有用。

Temboo是一个平台,具有一组“连接器”,可用于与其他平台或服务提供商(例如eBay,Yahoo!Weather,Google等)交换数据。 Temboo有趣的部分是它与
Arduino开发板 ,以便这些连接器可以在Arduino上导出。

Parse.com是我们在上一篇文章中使用的平台,用于发送android push消息 。

物联网项目的主要概述如下所示:

IoT项目:Arduino使用Parse.com的Temboo向Android发送推送通知_第1张图片

显而易见,构建物联网项目由多个部分组成。 第一部分是带有PIR传感器的Arduino板,用于检测运动 Arduino运行一个Temboo代理 ,该代理将数据发送到Parse平台 当Arduino数字输入之一变高时触发此代理。 Temboo平台用于创建代理,而无需编写过多的代码行。 借助Temboo choreo ,Arduino可以将JSON数据直接发送到Parse.com,后者再将推送消息发送到我们的智能手机。

Arduino素描

第一步是设置使用PIR传感器的Arduino草图并对其进行测试。 此步骤非常简单,我们必须使用三根电线将传感器连接到Arduino板:电源,接地和信号。

传感器非常简单 ,检测到运动时输出就很高。 对于此示例,我们可以假设它连接在数字引脚8上

要检查我们的传感器是否正常工作,并以正确的方式将其连接到Arduino板,以便它检测到运动,请尝试将此代码加载到arduino中:

int stato = 0;void setup() {  // put your setup code here, to run once:  Serial.begin(9600);  pinMode(8, INPUT);}void loop() {  // put your main code here, to run repeatedly:  stato = digitalRead(8);  Serial.println(stato);    delay(500);  }

现在运行代码,将手移到传感器前面,看一下串行监视器以检查其是否有效!

现在,Arduino组件已准备就绪!

Temboo choreo

下一步是设置将Arduino开发板连接到Parse.com的代理。 在这种情况下,我们需要一个以太网屏蔽将Arduino连接到互联网 我用过Wiznet W5500 。 创建帐户后,就可以配置Temboo杂务了 我们想将Arduino连接到Parse,所以我们检查Parse-> Push Notification 解析杂项需要一些信息,然后再使用:

  • 申请编号
  • RestAPI密钥

这两个参数用于将代理连接到Parse.com。 您可以在Parse.com中找到以下信息:

IoT项目:Arduino使用Parse.com的Temboo向Android发送推送通知_第2张图片

您必须将所需的密钥复制到Temboo中:

IoT项目:Arduino使用Parse.com的Temboo向Android发送推送通知_第3张图片

好,我们准备好了。 如果您愿意,可以尝试从Temboo发送通知到Parse.com。

现在设置控制代理的触发器:

Schermata 2015-09-21 alle 22.03.45

最后, Temboo将创建可立即使用的Arduino代码 !! 最后将代码复制并粘贴到您的Arduino IDE中。

Temboo生成的代码如下所示:

#include #include #include #include #include #include #include "TembooAccount.h" // Contains Temboo account informationbyte ethernetMACAddress[] = ETHERNET_SHIELD_MAC;EthernetClient client;// The number of times to trigger the action if the condition is met// We limit this so you won't use all of your Temboo calls while testingint maxCalls = 10;// The number of times this Choreo has been run so far in this sketchint calls = 0;int inputPin = 8;IPAddress ip(192, 168, 1, 130); // Arduino IP Addvoid setup() {  Serial.begin(9600);    // For debugging, wait until the serial console is connected  delay(4000);  while(!Serial);  Ethernet.begin(ethernetMACAddress, ip) ;  Serial.println("OK");  delay(5000);  // Initialize pins  pinMode(inputPin, INPUT);  Serial.println("Setup complete.\n");}void loop() {  int sensorValue = digitalRead(inputPin);  Serial.println("Sensor: " + String(sensorValue));  if (sensorValue == HIGH) {    if (calls < maxCalls) {      Serial.println("\nTriggered! Calling SendNotification Choreo...");      runSendNotification(sensorValue);      calls++;    } else {      Serial.println("\nTriggered! Skipping to save Temboo calls. Adjust maxCalls as required.");    }  }  delay(250);}void runSendNotification(int sensorValue) {  TembooChoreo SendNotificationChoreo(client);  // Set Temboo account credentials  SendNotificationChoreo.setAccountName(TEMBOO_ACCOUNT);  SendNotificationChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);  SendNotificationChoreo.setAppKey(TEMBOO_APP_KEY);  // Set profile to use for execution  SendNotificationChoreo.setProfile("ParseAccount");  // Set Choreo inputs  String NotificationValue = "{\"channel\": \"temboo\", \"type\": \"android\", \"data\": {\"message\": \"This is a test alert!\"}}";  SendNotificationChoreo.addInput("Notification", NotificationValue);  // Identify the Choreo to run  SendNotificationChoreo.setChoreo("/Library/Parse/PushNotifications/SendNotification");  // Run the Choreo  unsigned int returnCode = SendNotificationChoreo.run();  // Read and print the error message  while (SendNotificationChoreo.available()) {    char c = SendNotificationChoreo.read();    Serial.print(c);  }  Serial.println();  SendNotificationChoreo.close();}

配置Parse.com频道并构建Android应用

Temboo要求我们使用“ 解析”通道发送通知 然后,我们必须修改我们的Android应用程序,以使用频道来监听传入的通知。 如果您不知道如何编写处理推送消息的android应用程序,则可以阅读我以前的文章,其中介绍了如何通过Parse.com发送android推送消息 。

以这种方式稍微修改ParseTutorialApplication.java

@Override    public void onCreate() {        super.onCreate();        System.out.println("Application");        Parse.initialize(this, "sfFzOxotpsdOHWJE3nMmD0erLgFoecttKvC9CzIc", "nwbMEy7l4STpyNrABdrQxpEjdKIynSbuec56QbEz");        ParseInstallation.getCurrentInstallation().saveInBackground();        ParsePush.subscribeInBackground("temboo");    }

其中temboo是通道。

我们准备好了!! 运行该应用程序并将您的手移到传感器附近, Arduino将向Android智能手机发送推送消息

最终结果如下所示:

IoT项目:Arduino使用Parse.com的Temboo向Android发送推送通知_第4张图片

在本文的最后,您将了解如何使用Arduino和Android构建IoT项目,以及如何通过Temboo和Parse.com整合这两个生态系统

翻译自: https://www.javacodegeeks.com/2015/09/iot-project-arduino-sends-push-notification-to-android-using-temboo-parse-com.html

更多相关文章

  1. android软件工程师实战开发零基础到高级开发项目视频
  2. [Android 分享]GitHub Android 最火开源项目Top20
  3. android 中一个项目工程引用另一个项目工程和jar
  4. 《ZigBee开发笔记》第六部分 项目篇 基于ZigBee和Openwrt的智能
  5. Android 精选项目简介(可参考)
  6. Android studio百度地图SDK开发 2020最新超详细的Android 百度地
  7. Android应用程序线程消息循环模型分析(4)
  8. Android 触摸消息处理

随机推荐

  1. Android新控件MotionLayout介绍(一)
  2. Android敏感词标红
  3. Android(安卓)Studio 将module打成jar包
  4. Android官方培训中文课程
  5. 【Android学习笔记】双屏开发 Presentati
  6. Android开发——SQLite数据库(二)android s
  7. Android(安卓)热修复 技术浅析
  8. Android添加权限AndroidManifes.xml
  9. android应用程序启动解决黑屏及全屏显示
  10. Android(安卓)设置EditText的DrawableRig