极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10950|回复: 1

machtalk.net 声音传感器数据采集案例

[复制链接]
发表于 2014-4-14 16:02:23 | 显示全部楼层 |阅读模式
本帖最后由 weijinhe 于 2014-4-15 11:33 编辑

machtal.net登录注册
1、硬件准备
Arduino uno
模拟声音传感器模块
Arduino Ethernet W5100 网络扩展板模块
网线一根

2、硬件连接
Arduino Ethernet W5100 网络扩展板模块与Arduino uno连接。
Arduino Ethernet W5100 网络扩展板模块插上网线
模拟声音传感VC GND out 分别与Arduino uno 5V GND A(0)连接
3、烧写代码
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192,168,0,12);
EthernetClient client;
IPAddress server(60,211,253,162);      
unsigned long lastConnectionTime = 0;      // last time you connected to the server
boolean lastConnected = false; // state of the connection last time through the main loop
const unsigned long postingInterval = 10*1000; //delay between updates
void setup() {
  Serial.begin(9600);
   while (!Serial) {
  ;
  }
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    Ethernet.begin(mac, ip);
  }
}
void loop() {
  int sensorReading = analogRead(A0);   
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
  if (!client.connected() && lastConnected) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
  }
  if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
    sendData(sensorReading);
  }
  lastConnected = client.connected();
}
void sendData(int thisData) {
  if (client.connect(server, 10086)) {
    Serial.println("connecting...");
  client.println("POST /v1.0/device/7bc8abb1b3cb434499e66ba39c206aba/1/1/datapoints/add HTTP/1.1");
  client.println("Host: api.machtalk.net");
  client.println("APIKey:7a19bd7874a541a6b4c50a831ea0b3b2");
  client.print("Accept: *");
  client.print("/");   
  client.println("*");
  client.print("Content-Length: ");
  int thislength=17+getLength(thisData);
  client.println(thislength);
  client.println("Content-Type: application/x-www-form-urlencoded");
  client.println("Connection: close");   
  client.println();
  client.print("params={\"value\":");
  client.print(thisData);
  client.println("}");
  }
  else {
    Serial.println("connection failed");
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
  }
  lastConnectionTime = millis();
}
int getLength(int someValue) {
  int digits = 1;
  int dividend = someValue /10;
  while (dividend > 0) {
    dividend = dividend /10;
    digits++;
  }
  return digits;
}
4、Machtalk物联网平台配置
    Machtalk物联网平台配置、动作设置、触发器设置如例一所示,不再累述。案例:
machtalk.net物联网平台温度传感器采集
http://www.geek-workshop.com/thread-9318-1-1.html
www.machtalk技术交流群:300250166
  

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

 楼主| 发表于 2014-4-15 11:36:46 | 显示全部楼层
不错的DIY 顶一下
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-15 01:00 , Processed in 0.093501 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表