极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

楼主: zcbzjx

基于18B20+enc28j60+arduino+yeelink的远程温度监控

[复制链接]
发表于 2012-8-7 18:29:57 | 显示全部楼层
enc28j60 有时候要手动reset才能接通网络,不知楼主是怎么解决的?
回复 支持 反对

使用道具 举报

发表于 2012-8-8 11:51:01 | 显示全部楼层
davidce 发表于 2012-8-7 18:29
enc28j60 有时候要手动reset才能接通网络,不知楼主是怎么解决的?

你用的是usb电源吧,你换个普通9v电源插那个电源口试试
回复 支持 反对

使用道具 举报

发表于 2012-8-8 12:25:35 | 显示全部楼层
Jerry 发表于 2012-8-8 11:51
你用的是usb电源吧,你换个普通9v电源插那个电源口试试

试了,应该和电源没有关系
回复 支持 反对

使用道具 举报

发表于 2012-8-8 15:14:32 | 显示全部楼层
davidce 发表于 2012-8-8 12:25
试了,应该和电源没有关系

那是什么问题呢,谁能解答一下啊
回复 支持 反对

使用道具 举报

发表于 2012-8-8 21:17:33 | 显示全部楼层
davidce 发表于 2012-8-7 18:29
enc28j60 有时候要手动reset才能接通网络,不知楼主是怎么解决的?

reset的问题解决了,要给uno 的reset和GND之间接10uf 电容
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-8-9 18:08:12 | 显示全部楼层
本帖最后由 zcbzjx 于 2012-8-9 18:09 编辑
davidce 发表于 2012-8-8 21:17
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 网络控制了,就是安卓开发这块不会啊
回复 支持 反对

使用道具 举报

发表于 2012-8-11 13:22:07 | 显示全部楼层
使用W5100 制作的3种传感器 数据 上传yeelink成功,http://www.yeelink.net/devices/242
回复 支持 反对

使用道具 举报

发表于 2012-8-19 20:40:14 | 显示全部楼层
请楼主看下我代码出什么问题了么?向yeelink提交不成功,此外,如何将http response 打印到串口呢?
  1. /*
  2. Yeelink sensor client
  3. by zcb
  4. 2012.07.17
  5. */
  6. #include <EtherCard.h>
  7. int sensorPin = A0;
  8. int sensorValue = 0;
  9. ///////////////////////////////////////////////////////////
  10. ///////////////////////////////////////////////////////////
  11. char SensorID[] PROGMEM = "120"; // replace your sensor ID
  12. const uint8_t MyMac[6] = {
  13.   0x74,0x69,0x69,0x2D,0x32,0x06 };
  14. const uint8_t MyIP[4] = {
  15.   192,168,0,110 };
  16. ////////////////////////////////////////////////////////////

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


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

  21. const uint8_t MyGateway[4] = {
  22.   192,168,0,1 };
  23. const uint8_t yeelinkIP[4] = {
  24.   202,136,60,231};


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

  26. // Some global variables
  27. char sensorData[20];
  28. uint8_t dataLength;
  29. uint8_t Ethernet::buffer[300];
  30. uint32_t lastConnectionTime = 0;          // last time you connected to the server, in milliseconds

  31. Stash stash;



  32. void setup() {
  33.   Serial.begin(9600);
  34.   // start serial port:
  35.   // start the Ethernet connection:
  36.   ether.begin(sizeof Ethernet::buffer, MyMac);
  37.   //
  38.   ether.staticSetup(MyIP,MyGateway);

  39. }

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

  44.   if(millis() - lastConnectionTime > PostingInterval){
  45.     get_Send_String();   
  46.     send_Data();
  47.   }

  48. }

  49. void send_Data() {
  50.   // Create a Post for yeelink server,
  51.   // and send request saving sessionID
  52.   Stash::prepare(PSTR("POST /v1.0/device/$F/sensor/$F/datapoints HTTP/1.1" "\r\n"
  53.     "Host: api.yeelink.net" "\r\n"
  54.     "U-ApiKey: $F" "\r\n"
  55.     "Content-Length: $D" "\r\n"
  56.     "Content-Type: application/x-www-form-urlencoded" "\r\n" "\r\n"                       
  57.     "$S"),
  58.   DeviceID,SensorID,APIKey,dataLength,sensorData);
  59.   ether.copyIp(ether.hisip, yeelinkIP);
  60.   ether.tcpSend();
  61.   lastConnectionTime = millis();
  62. }
  63. ///////////////////////////////////////////////////////////////////////////
  64. // get data from temperature sensor
  65. // you can replace this code for your sensor
  66. void get_Send_String(){
  67.   uint16_t Tc_100 = sensorValue;
  68.   uint8_t i,whole, fract;
  69.   whole = Tc_100/10 ;  // separate off the whole and fractional portions
  70.   fract = Tc_100 % 10;
  71.   dataLength = sprintf(sensorData,"{"value":%d.%d}",whole,fract);  
  72. }
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-8-20 10:17:30 | 显示全部楼层
  1. 正在 Ping api.yeelink.net [202.136.56.203] 具有 32 字节的数据:
  2. 来自 202.136.56.203 的回复: 字节=32 时间=43ms TTL=52
  3. 来自 202.136.56.203 的回复: 字节=32 时间=42ms TTL=52
  4. 来自 202.136.56.203 的回复: 字节=32 时间=44ms TTL=52
  5. 来自 202.136.56.203 的回复: 字节=32 时间=42ms TTL=52
复制代码
ip地址变了。别的好似没问题
回复 支持 反对

使用道具 举报

发表于 2012-8-20 11:53:42 | 显示全部楼层
zcbzjx 发表于 2012-8-20 10:17
ip地址变了。别的好似没问题

可否只添加域名,而不管IP呢?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-8-21 07:21:07 | 显示全部楼层
可以啊,

  1. #include <EtherCard.h>

  2. static byte mymac[] = {
  3.   0x74,0x69,0x69,0x2D,0x30,0x31 };
  4. // ethernet interface ip address
  5. static byte myip[] = {
  6.   192,168,1,203 };
  7. // gateway ip address
  8. static byte gwip[] = {
  9.   192,168,1,1 };
  10. //dns ip address
  11. static byte dnsip[]={
  12.   192.168.1.1};
  13. char yeelink_web[] PROGMEM = "api.yeelink.net";

  14. void setup(){
  15.   ether.begin(sizeof Ethernet::buffer, mymac);
  16.   ether.staticSetup(myip, gwip,dnsip);
  17.   ether.dnsLookup(yeelink_web);
  18. }
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-8-29 09:02:43 | 显示全部楼层
本帖最后由 zcbzjx 于 2012-8-29 09:22 编辑

有人没看见,我顶下哈,顺便补发一张原理图。
回复 支持 反对

使用道具 举报

发表于 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[6] = {
  0xf0,0xdf,0xf1,0xc7,0x9f,0x61 };
const uint8_t MyIP[4] = {
  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[4] = {
  10,21,0,1 };
const uint8_t yeelinkIP[4] = {
  202,136,60,231};


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

// Some global variables
char sensorData[20];
uint8_t dataLength;
uint8_t Ethernet::buffer[300];
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[12];
  byte addr[8];
  if ( !ds.search(addr)) {
    //no more sensors on chain, reset search
    ds.reset_search();
    return 0;
  }
  if ( OneWire::crc8( addr, 7) != addr[7]) {
    return 1000;
  }
  if ( addr[0] != 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[i] = ds.read();
  }
  ds.reset_search();
  uint16_t tempRead = (data[1] << 8) | data[0]; //using two's compliment
  return tempRead*10/16;
}
回复 支持 反对

使用道具 举报

发表于 2012-8-31 17:13:55 | 显示全部楼层
const uint8_t yeelinkIP[4] = {
  202,136,60,231};
这个IP地址已经停用了,换用DNS的吧

char server[] = “api.yeelink.net”; // yeelink API的域名
回复 支持 反对

使用道具 举报

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

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-5-8 08:51 , Processed in 0.041767 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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