zcbzjx 发表于 2012-11-13 21:31:07

darkorigin 发表于 2012-11-13 17:33 static/image/common/back.gif
提问下语法方面
代码1的 40行 Stash stash;
按我理解应该是定义一个 Stash 型的变量(或实例)stash 但是 ...

stash是在库函数中声明的,主要用于构建数据包。建议不要用stash,用httppost比较好。我有个例子,你看看。不过最近没研究这个库了,好似又更新了不少。

erjiang 发表于 2012-11-19 15:40:39

JUST_DO_IT 发表于 2012-9-18 21:46 static/image/common/back.gif
那怎么获取上面的开关的数据来控制LED灯呢

使用HTTP GET的方式就可以了,教程可以参考 http://blog.yeelink.net/?p=94

xiake 发表于 2012-11-20 15:25:06

DFRobot 发表于 2012-8-11 13:22 static/image/common/back.gif
使用W5100 制作的3种传感器 数据 上传yeelink成功,http://www.yeelink.net/devices/242

困惑于enc28j0,w5100在手,新手求代码

erjiang 发表于 2012-11-20 18:02:36

代码密集分布在bbs.yeelink.net和blog.yeelink.net上,本坛子里面也有不少的

xiake 发表于 2012-11-20 19:50:48

yeelink.net的博客和论坛,都是基于enc28j60的,唯一一个5100还是测试光强的。我想先拿成熟的代码测试硬件,然后再慢慢学习和改进。

zcbzjx 发表于 2012-11-20 19:52:18

5100代码例程就有的吧。

xiake 发表于 2012-11-20 20:12:00

yeelink官方的,不是5100+BH1750光强传感器模块,就是enc28j60+18B20,唯独没有5100+18b20的代码,而且例程质量远不如cosm

zcbzjx 发表于 2012-11-20 21:13:15

明天我写个例程给你。还好俺饿了好几顿,花了100块买了个5100

xiake 发表于 2012-11-20 21:24:21

我是昏头呆脑,彻底迷茫在yeelink的例程,转投cosm已经小有斩获。
http://www.geek-workshop.com/thread-2563-1-1.html
至少说明,硬件是没有问题的,还是希望能回归yeelink.

我参照的是这个例程:http://arduino.cc/en/Tutorial/PachubeClient

其实更希望用下面这个例程,传输多个参数:http://arduino.cc/en/Tutorial/PachubeClientString
但是搞不明白读取18b20传感器部分,能不能援手点拨如何读取18b20。

yeelink这个官方例程,网络是通的,就是传感器部分不知道如何改写。
http://blog.yeelink.net/?p=34

DS18B20温度传感器的例程,两个都已经通过,可供参考
http://www.arduino.cn/thread-1345-1-1.html

xiake 发表于 2012-11-20 21:31:23

问题是,此贴的网卡怎么修改为5100?

或者,下面这个官方例程,怎么把传感器部分,修改为单个18b20或者多个

物联网跟我动手做系列教程—第三篇 实验二
如何用arduino+ethernet shield与yeelink结合5分钟实现传感器数据web上传
http://blog.yeelink.net/?p=34

///////////////////////////////////////////////////////////////////////////
// get data from light sensor
// you can replace this code for your sensor
int readLightSensor()
{
uint16_t val=0;
BH1750_Init(BH1750address);
delay(200);
if(2==BH1750_Read(BH1750address))
{
    val=((buff<<8)|buff)/1.2;
}

Serial.print("Sensor value is: ");
Serial.println((int)val);

return val;
}

int BH1750_Read(int address) //
{
int i=0;
Wire.beginTransmission(address);
Wire.requestFrom(address, 2);
while(Wire.available()) //
{
    buff = Wire.read();// receive one byte
    i++;
}
Wire.endTransmission();
return i;
}

void BH1750_Init(int address)
{
Wire.beginTransmission(address);
Wire.write(0x10);//1lx reolution 120ms
Wire.endTransmission();
}

zcbzjx 发表于 2012-11-20 21:54:56

家里没arduino,没法调试,明天我到办公室给你弄吧

zcbzjx 发表于 2012-11-21 10:27:46

本帖最后由 zcbzjx 于 2012-11-21 10:34 编辑

/*
Yeelink sensor client example
*/

#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>

#define ONEWIRE_PIN A0

OneWire ds(ONEWIRE_PIN);


byte buff;

// for yeelink api
#define APIKEY         "xxxxxxxxxxxxxxxxxxxxxxxxxxx" // replace your yeelink api key here
#define DEVICEID       xx // replace your device ID
#define SENSORID       xxx // replace your sensor ID

// assign a MAC address for the ethernet controller.
byte mac[] = {
0x00, 0x1D, 0x72, 0x82, 0x35, 0x9D};
IPAddress myip(10,21,0,195);
IPAddress mydns(10,11,5,25);
IPAddress mygateway(10,21,0,1);

// initialize the library instance:
EthernetClient client;
char server[] = "api.yeelink.net";   // name address for yeelink API

unsigned long lastConnectionTime = 0;          // last time you connected to the server, in milliseconds
boolean lastConnected = false;               // state of the connection last time through the main loop
const unsigned long postingInterval = 15*1000; // delay between 2 datapoints, 30s

// Some global variables
char sensorData;
uint8_t dataLength;

void setup() {
// Start up the dallas library

// start serial port:
Serial.begin(57600);
// start the Ethernet connection with DHCP:
Ethernet.begin(mac,myip,mydns,mygateway);
}

void loop() {
// if there's incoming data from the net connection.
// send it out the serial port.This is for debugging
// purposes only:
if (client.available()) {
    char c = client.read();
    Serial.print(c);
}

// if there's no net connection, but there was one last time
// through the loop, then stop the client:
if (!client.connected() && lastConnected) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
}

// if you're not connected, and ten seconds have passed since
// your last connection, then connect again and send data:
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
    // read sensor data, replace with your code
    get_Send_String();
    Serial.println(sensorData);
    //send data to server

    sendData(sensorData,dataLength);
}
// store the state of the connection for next time through
// the loop:
lastConnected = client.connected();
}

// this method makes a HTTP connection to the server:
void sendData(char* thisData,byte thisLength) {
// if there's a successful connection:
if (client.connect(server, 80)) {
    Serial.println("connecting...");
    // send the HTTP PUT request:
    client.print("POST /v1.0/device/");
    client.print(DEVICEID);
    client.print("/sensor/");
    client.print(SENSORID);
    client.print("/datapoints");
    client.println(" HTTP/1.1");
    client.println("Host: api.yeelink.net");
    client.print("Accept: *");
    client.print("/");
    client.println("*");
    client.print("U-ApiKey: ");
    client.println(APIKEY);
    client.print("Content-Length: ");


    client.println(thisLength);

    client.println("Content-Type: application/x-www-form-urlencoded");
    client.println("Connection: close");
    client.println();

    // here's the actual content of the PUT request:
    client.print(thisData);
}
else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
}
// note the time that the connection was made or attempted:
lastConnectionTime = millis();
}


///////////////////////////////////////////////////////////////////////////
// get data from light sensor
// you can replace this code for your sensor
///////////////////////////////////////////////////////////////////////////
// get data from temperature sensor
// you can replace this code for your sensor
void get_Send_String(){
uint16_t Tc_100 = get_Current_Temp();
uint8_t i,whole, fract;
whole = Tc_100/10 ;// separate off the whole and fractional portions
fract = Tc_100 % 10;
dataLength = sprintf(sensorData,"{\"value\":%d.%d}",whole,fract);
}

uint16_t get_Current_Temp(){ //0.1C
//returns the temperature from one DS18S20 in DEG Celsius
byte data;
byte addr;
if ( !ds.search(addr)) {
    //no more sensors on chain, reset search
    ds.reset_search();
    return 0;
}
if ( OneWire::crc8( addr, 7) != addr) {
    return 1000;
}
if ( addr != 0x28) {
    return 1000;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end
delay(1000);
ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad

for (int i = 0; i < 9; i++) { // we need 9 bytes
    data = ds.read();
}
ds.reset_search();
uint16_t tempRead = (data << 8) | data; //using two's compliment
return tempRead*10/16;
}

erjiang 发表于 2012-11-21 10:48:00

哥们,W5100的使用,远远比enc的那个简单多啦!

xiake 发表于 2012-11-21 11:14:24

收到,谢谢

回家就试,传感器A0,模拟输入么?

zcbzjx 发表于 2012-11-21 11:40:02

A0-A5也可以是数字,A6-A7是纯模拟
页: 1 2 3 [4] 5 6
查看完整版本: 基于18B20+enc28j60+arduino+yeelink的远程温度监控