davidce 发表于 2012-8-7 18:29:57

enc28j60 有时候要手动reset才能接通网络,不知楼主是怎么解决的?

Jerry 发表于 2012-8-8 11:51:01

davidce 发表于 2012-8-7 18:29 static/image/common/back.gif
enc28j60 有时候要手动reset才能接通网络,不知楼主是怎么解决的?

你用的是usb电源吧,你换个普通9v电源插那个电源口试试

davidce 发表于 2012-8-8 12:25:35

Jerry 发表于 2012-8-8 11:51 static/image/common/back.gif
你用的是usb电源吧,你换个普通9v电源插那个电源口试试

试了,应该和电源没有关系

Jerry 发表于 2012-8-8 15:14:32

davidce 发表于 2012-8-8 12:25 static/image/common/back.gif
试了,应该和电源没有关系

那是什么问题呢,谁能解答一下啊

davidce 发表于 2012-8-8 21:17:33

davidce 发表于 2012-8-7 18:29 static/image/common/back.gif
enc28j60 有时候要手动reset才能接通网络,不知楼主是怎么解决的?

reset的问题解决了,要给uno 的reset和GND之间接10uf 电容

zcbzjx 发表于 2012-8-9 18:08:12

本帖最后由 zcbzjx 于 2012-8-9 18:09 编辑

davidce 发表于 2012-8-8 21:17 static/image/common/back.gif
reset的问题解决了,要给uno 的reset和GND之间接10uf 电容

我的好似无这个问题,我的问题是mcu占用时间过长(长时间不调用ether.packetLoop(ether.packetReceive());的话),再发送数据就可以发送不出去,造成丢掉这个数据,现在解决就是mcu运行时间过长的代码,运行结束后就一直调用ether.packetLoop(ether.packetReceive());直到ether.packetReceive()=0。

甲壳虫老师 发表于 2012-8-10 17:14:18

真不错 ,早就想玩手机 pad 网络控制了,就是安卓开发这块不会啊

DFRobot 发表于 2012-8-11 13:22:07

使用W5100 制作的3种传感器 数据 上传yeelink成功,http://www.yeelink.net/devices/242

plantpark 发表于 2012-8-19 20:40:14

请楼主看下我代码出什么问题了么?向yeelink提交不成功,此外,如何将http response 打印到串口呢?/*
Yeelink sensor client
by zcb
2012.07.17
*/
#include <EtherCard.h>
int sensorPin = A0;
int sensorValue = 0;
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
char SensorID[] PROGMEM = "120"; // replace your sensor ID
const uint8_t MyMac = {
0x74,0x69,0x69,0x2D,0x32,0x06 };
const uint8_t MyIP = {
192,168,0,110 };
////////////////////////////////////////////////////////////

// for yeelink api
char APIKey[] PROGMEM = "########################"; // replace your yeelink api key here
char DeviceID[] PROGMEM = "111"; // replace your device ID


// assign a MAC IP gateway dns for the ethernet controller.

const uint8_t MyGateway = {
192,168,0,1 };
const uint8_t yeelinkIP = {
202,136,60,231};


const uint16_t PostingInterval = 15000;// delay between 2 datapoints, 30s

// Some global variables
char sensorData;
uint8_t dataLength;
uint8_t Ethernet::buffer;
uint32_t lastConnectionTime = 0;          // last time you connected to the server, in milliseconds

Stash stash;



void setup() {
Serial.begin(9600);
// start serial port:
// start the Ethernet connection:
ether.begin(sizeof Ethernet::buffer, MyMac);
//
ether.staticSetup(MyIP,MyGateway);

}

void loop() {
Serial.println(sensorValue);
sensorValue = analogRead(sensorPin);
ether.packetLoop(ether.packetReceive());

if(millis() - lastConnectionTime > PostingInterval){
    get_Send_String();   
    send_Data();
}

}

void send_Data() {
// Create a Post for yeelink server,
// and send request saving sessionID
Stash::prepare(PSTR("POST /v1.0/device/$F/sensor/$F/datapoints HTTP/1.1" "\r\n"
    "Host: api.yeelink.net" "\r\n"
    "U-ApiKey: $F" "\r\n"
    "Content-Length: $D" "\r\n"
    "Content-Type: application/x-www-form-urlencoded" "\r\n" "\r\n"                     
    "$S"),
DeviceID,SensorID,APIKey,dataLength,sensorData);
ether.copyIp(ether.hisip, yeelinkIP);
ether.tcpSend();
lastConnectionTime = millis();
}
///////////////////////////////////////////////////////////////////////////
// get data from temperature sensor
// you can replace this code for your sensor
void get_Send_String(){
uint16_t Tc_100 = sensorValue;
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);
}

zcbzjx 发表于 2012-8-20 10:17:30

正在 Ping api.yeelink.net 具有 32 字节的数据:
来自 202.136.56.203 的回复: 字节=32 时间=43ms TTL=52
来自 202.136.56.203 的回复: 字节=32 时间=42ms TTL=52
来自 202.136.56.203 的回复: 字节=32 时间=44ms TTL=52
来自 202.136.56.203 的回复: 字节=32 时间=42ms TTL=52ip地址变了。别的好似没问题

plantpark 发表于 2012-8-20 11:53:42

zcbzjx 发表于 2012-8-20 10:17 static/image/common/back.gif
ip地址变了。别的好似没问题

可否只添加域名,而不管IP呢?

zcbzjx 发表于 2012-8-21 07:21:07

可以啊,
#include <EtherCard.h>

static byte mymac[] = {
0x74,0x69,0x69,0x2D,0x30,0x31 };
// ethernet interface ip address
static byte myip[] = {
192,168,1,203 };
// gateway ip address
static byte gwip[] = {
192,168,1,1 };
//dns ip address
static byte dnsip[]={
192.168.1.1};
char yeelink_web[] PROGMEM = "api.yeelink.net";

void setup(){
ether.begin(sizeof Ethernet::buffer, mymac);
ether.staticSetup(myip, gwip,dnsip);
ether.dnsLookup(yeelink_web);
}

zcbzjx 发表于 2012-8-29 09:02:43

本帖最后由 zcbzjx 于 2012-8-29 09:22 编辑

有人没看见,我顶下哈,顺便补发一张原理图。

JUST_DO_IT 发表于 2012-8-31 16:27:42

static byte mymac[] = {
0x74,0x69,0x69,0x2D,0x30,0x31 };
// ethernet interface ip address
static byte myip[] = {
192,168,1,203 };
这两个要不要改啊,自己的IP和mac?
我的代码是:

/*
Yeelink sensor client
by zcb
2012.07.17
*/
#include <EtherCard.h>
#include <OneWire.h>

//
//18B20
#define ONEWIRE_PIN 7

OneWire ds(ONEWIRE_PIN);
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
char SensorID[] PROGMEM = "626"; // replace your sensor ID
const uint8_t MyMac = {
0xf0,0xdf,0xf1,0xc7,0x9f,0x61 };
const uint8_t MyIP = {
222,16,228,228 };
////////////////////////////////////////////////////////////

// for yeelink api
char APIKey[] PROGMEM = "5c137bc47b1fe0d3d7854509d7783c78"; // replace your yeelink api key here
char DeviceID[] PROGMEM = "500"; // replace your device ID


// assign a MAC IP gateway dns for the ethernet controller.

const uint8_t MyGateway = {
10,21,0,1 };
const uint8_t yeelinkIP = {
202,136,60,231};


const uint16_t PostingInterval = 15000;// delay between 2 datapoints, 30s

// Some global variables
char sensorData;
uint8_t dataLength;
uint8_t Ethernet::buffer;
uint32_t lastConnectionTime = 0;          // last time you connected to the server, in milliseconds

Stash stash;



void setup() {
Serial.begin(4800);
// start serial port:
// start the Ethernet connection:
ether.begin(sizeof Ethernet::buffer, MyMac);
//
ether.staticSetup(MyIP,MyGateway);

}

void loop() {
   Serial.print("yeelink:");
   Serial.println(get_Current_Temp());
   
ether.packetLoop(ether.packetReceive());

   
   
if(millis() - lastConnectionTime > PostingInterval){
    get_Send_String();   
    send_Data();
   
}

}

void send_Data() {
// Create a Post for yeelink server,
// and send request saving sessionID
Stash::prepare(PSTR("POST /v1.0/device/$F/sensor/$F/datapoints HTTP/1.1" "\r\n"
    "Host: api.yeelink.net" "\r\n"
    "U-ApiKey: $F" "\r\n"
    "Content-Length: $D" "\r\n"
    "Content-Type: application/x-www-form-urlencoded" "\r\n" "\r\n"                     
    "$S"),
DeviceID,SensorID,APIKey,dataLength,sensorData);
ether.copyIp(ether.hisip, yeelinkIP);
ether.tcpSend();
lastConnectionTime = millis();
}
///////////////////////////////////////////////////////////////////////////
// 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-8-31 17:13:55

const uint8_t yeelinkIP = {
202,136,60,231};
这个IP地址已经停用了,换用DNS的吧

char server[] = “api.yeelink.net”; // yeelink API的域名
页: 1 [2] 3 4 5 6
查看完整版本: 基于18B20+enc28j60+arduino+yeelink的远程温度监控