undead2003 发表于 2014-6-8 00:12:42

W5200如何连接入YEELINK啊?

小白一枚,不懂W5200的设置,UNO板和LM35,求大侠帮忙

undead2003 发表于 2014-6-8 09:54:07

:(技术人员不在吗??都休息了?

Rockets 发表于 2014-6-8 09:57:13

请看下产品资料库,里面有相关介绍的啊。

Ricky 发表于 2014-6-8 20:11:05

和普通ethernet 一样用 ,换个库文件就好, 有样例的。

具体哪个地方有问题呢?

undead2003 发表于 2014-6-9 00:35:33

我用测试教程里面的w5200 web server重新定义为一个server,板子正常,6路数据都可以内网显示,过一段时间将yeelink用w5100+uno的代码刷uno,可以连上jeelink,数据也有,但是过不了多久,就没有了,这是怎么回事??w5200不能用w5100的代码库的吗?重新写的话,怎么写啊,太复杂了,我用的是LM35+UNO+W5200,本人小白一枚,大侠多多包容,感激不尽。

Grey 发表于 2014-6-9 10:16:52

undead2003 发表于 2014-6-9 00:35
我用测试教程里面的w5200 web server重新定义为一个server,板子正常,6路数据都可以内网显示,过一段时间 ...

W5200的库和W5100是不一样的,只能向下兼容,产品页面或者wiki上都有下载的。
把圆来的给删了,换上新的就可以了

undead2003 发表于 2014-6-11 00:14:06

00000---基础小白求救,折腾好久了,没办法,基础不是差的问题,是空白,请求Grey大侠帮忙编写一下,红色部分LM35的代码:我根本就不懂呀,
/*
Yeelink sensor client example
*/

#include <SPI.h>
#include <Ethernet.h>
#include <Wire.h>
#include <math.h>

int LM35address = 0x23;
byte buff;

// for yeelink api
#define APIKEY         "bf6497a31fabf2a574f6b52f5a32b2e8" // replace your yeelink api key here
#define DEVICEID10965 // replace your device ID
#define SENSORID18180 // replace your sensor ID

// assign a MAC address for the ethernet controller.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xAA};
// 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 = 30*1000; // delay between 2 datapoints, 30s

void setup() {
Wire.begin();
// start serial port:
Serial.begin(115200);
// start the Ethernet connection with DHCP:
if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    for(;;)
      ;
}
else {
    Serial.println("Ethernet configuration OK");
}
}

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
    int sensorReading = readLightSensor();
    //send data to server
    sendData(sensorReading);
}
// 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(int thisData) {
// 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: ");

    // calculate the length of the sensor reading in bytes:
    // 8 bytes for {"value":} + number of digits of the data:
    int thisLength = 10 + getLength(thisData);
    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("{\"value\":");
    client.print(thisData);
    client.println("}");
}
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();
}

// This method calculates the number of digits in the
// sensor reading.Since each digit of the ASCII decimal
// representation is a byte, the number of digits equals
// the number of bytes:
int getLength(int someValue) {
// there's at least one byte:
int digits = 1;
// continually divide the value by ten,
// adding one to the digit count for each
// time you divide, until you're at 0:
int dividend = someValue /10;
while (dividend > 0) {
    dividend = dividend /10;
    digits++;
}
// return the number of digits:
return digits;
}

///////////////////////////////////////////////////////////////////////////
<font color="Red">// get data from LM35 sensor
// you can replace this code for your sensor
int readLightSensor()
{
uint16_t val=0;
LM35_Init(LM35address);
delay(200);
if(2==LM35_Read(BH1750address))
{
    val=((buff<<8)|buff)/1.2;
}

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

return val;
}

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

void LM35_Init(int address)
{
Wire.beginTransmission(address);
Wire.write(0x10);//1lx reolution 120ms
Wire.endTransmission();
}</i></font>

lauren 发表于 2014-6-11 13:41:16

Yeelink官方应该就有w5100和yeelink链接的样例程序和教程的吧?你试试直接用官方的资料。据我所知,对于w5200和w5100的差异其实主要是socket接口性能更强一些。所以arduino的库更新下,其他所有函数和功能都是完全兼容的!

1.建议先不要自己修改功能,使用官方样例
2.跑通后添加功能

undead2003 发表于 2014-6-11 22:25:27

lauren 发表于 2014-6-11 13:41
Yeelink官方应该就有w5100和yeelink链接的样例程序和教程的吧?你试试直接用官方的资料。据我所知,对于w52 ...

真的很奇怪,你的方法我也用过,不行,但是用官方的WEBSERVER来刷一次之后,再用YEELINK的样例程序就可以了,现在在测试能顶多久??

undead2003 发表于 2014-6-11 22:39:24

顶了10分钟,开始出现乱码,重新刷yeelink的样例程序,就恢复正常,还在看……

undead2003 发表于 2014-6-11 23:03:01

奇怪了,为什么一定要刷一次这个webserver,然后Yeelink的样例也可以,自己写的代码也都可以了??有技术人员吗?告知一二?

undead2003 发表于 2014-6-12 20:48:49

反复尝试,发现DFrobot这块板子很有特点,一定要按照test程序里面的重新定义一下针脚才行,然后结合yeelink的上传程序就可以正常工作了,废话不说,代码如下:
#include <Ethernet.h>
#include <WiFi.h>
#include <SPI.h>
#include <yl_data_point.h>
#include <yl_device.h>
#include <yl_w5100_client.h>
#include <yl_wifi_client.h>
#include <yl_messenger.h>
#include <yl_sensor.h>
#include <yl_value_data_point.h>
#include <yl_sensor.h>

//this example reads data from a lm35dz sensor, convert value to degree Celsius
//and then post it to yeelink.net

//注意!官网的SPI接口使用的是 D10作为 SS接口,这里需要根据实际SS接线情况定义一次SS管脚
////端口定义Dreamer MEGAX1 PORT
//#define SS53   //Gadgeteer PIN 6
//#define nRST46//Gadgeteer PIN 4
//#define nPWDN 45//Gadgeteer PIN 5
//#define nINT 2//Gadgeteer PIN 3

//端口定义Dreamer MEGA X2 PORT
#define SS    10   //Gadgeteer PIN 6
#define nRST8//Gadgeteer PIN 4
#define nPWDN 9//Gadgeteer PIN 5
#define nINT 3//Gadgeteer PIN 3
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
// assign a MAC address for the ethernet controller.
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,101);
// initialize the library instance:


//replace 2633 3539 with ur device id and sensor id
yl_device ardu(10965);//此处替换为你的设备编号
yl_sensor therm(18180, &ardu);//此处替换为你的传感器编号
//replace first param value with ur u-apikey
yl_w5100_client client;
yl_messenger messenger(&client, "bf6497a31fabf2a574f6b52f5a32b2e8", "api.yeelink.net");   //此处替换为你自己的API KEY


const int THERM_PIN= A0;


float lm35_convertor(int analog_num)
{
        return analog_num * (5.0 / 1024.0 * 100);
}


void setup()
{
    ////下面是非常重要的设置,如果没有可靠的复位设置,W5200可能不工作 !!!! /////////
pinMode(SS,OUTPUT);//端口定义Dreamer MEGA X2 PORTGadgeteer PIN 6 use SS
pinMode(nRST,OUTPUT);
pinMode(nPWDN,OUTPUT);
pinMode(nINT,INPUT);
digitalWrite(nPWDN,LOW);//enable power
digitalWrite(nRST,LOW);//Reset W5200
delay(10);
digitalWrite(nRST,HIGH);
delay(200);       // wait W5200 work
Serial.begin(9600);        //for output information
        byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xAA};
        Ethernet.begin(mac);
}


void loop()
{
        int v = analogRead(THERM_PIN);
      Serial.println(lm35_convertor(v));
                yl_value_data_point dp(lm35_convertor(v));
                therm.single_post(messenger, dp);
                delay(1000);
}

lauren 发表于 2014-6-16 14:42:39

undead2003 发表于 2014-6-12 20:48
反复尝试,发现DFrobot这块板子很有特点,一定要按照test程序里面的重新定义一下针脚才行,然后结合yeelink ...

?.哦?需要重新定义引脚?难道是nRST/nPWDN/nINT引脚和官方引脚不匹配?

Grey 发表于 2014-6-20 10:27:14

lauren 发表于 2014-6-16 14:42
?.哦?需要重新定义引脚?难道是nRST/nPWDN/nINT引脚和官方引脚不匹配?

有这种可能性,WIKI里面就是需要重新定义引脚,但库里面大部分样例程序都没有定义引脚,这有点奇怪。

Anyway,感谢楼主分享经验!

unoing 发表于 2014-11-15 11:28:02

undead2003 发表于 2014-6-12 20:48
反复尝试,发现DFrobot这块板子很有特点,一定要按照test程序里面的重新定义一下针脚才行,然后结合yeelink ...

我也有相同的困惑,请问可以加个QQ相互一下呗。949309391
页: [1]
查看完整版本: W5200如何连接入YEELINK啊?