极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9665|回复: 32

麻瓜项目:家庭能源管理(COSM物联网版本/乐联网测试版更新)

[复制链接]
发表于 2013-1-17 06:32:45 | 显示全部楼层 |阅读模式
本帖最后由 muggle 于 2013-6-30 23:09 编辑

基于物联网的能源管理,筹备许久,终于动手了。过程之中,遇到很多困难,在朋友的帮助下顺利解决。

交流电量管理模块+Arduino Uno+W5100+485模块+2004LCD

程序参考:
https://sites.google.com/site/jp ... duino-modbus-master
http://www.geek-workshop.com/thread-544-1-1.html


测试链接:
https://cosm.com/feeds/97970



破烂的程序,还没有优化整理,先贴出来,接受批评


  1. /*                

  2. History:
  3. 2013.01.16 First success with AC Meter Module & 485 MODUBUS
  4. modebus_zxy_testAC_20130116ethernetCOSM

  5. Modbus over serial line - RTU Master Arduino Sketch

  6. By Juan Pablo Zometa : [email]jpmzometa@gmail.com[/email]
  7. [url]http://sites.google.com/site/jpmzometa/[/url]

  8. These functions implement functions 3 and 16 (read holding registers
  9. and preset multiple registers) of the Modbus RTU Protocol, to be used
  10. over the Arduino serial connection.

  11. This implementation DOES NOT fully comply with the Modbus specifications.

  12. This Arduino adaptation is derived from the work
  13. By P.Costigan email: [email]phil@pcscada.com.au[/email] [url]http://pcscada.com.au[/url]

  14. These library of functions are designed to enable a program send and
  15. receive data from a device that communicates using the Modbus protocol.

  16. Copyright (C) 2000 Philip Costigan  P.C. SCADA LINK PTY. LTD.

  17. This program is free software; you can redistribute it and/or modify
  18. it under the terms of the GNU General Public License as published by
  19. the Free Software Foundation; either version 2 of the License, or
  20. (at your option) any later version.

  21. This program is distributed in the hope that it will be useful,
  22. but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  24. GNU General Public License for more details.

  25. You should have received a copy of the GNU General Public License
  26. along with this program; if not, write to the Free Software
  27. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

  28. The functions included here have been derived from the
  29. Modicon Modbus Protocol Reference Guide
  30. which can be obtained from Schneider at [url]www.schneiderautomation.com.[/url]

  31. This code has its origins with
  32. [email]paul@pmcrae.freeserve.co.uk[/email] ([url]http://www.pmcrae.freeserve.co.uk[/url])
  33. who wrote a small program to read 100 registers from a modbus slave.

  34. I have used his code as a catalist to produce this more functional set
  35. of functions. Thanks paul.

  36. */
  37. /* FIXME: not yet being used */
  38. unsigned long interframe_delay = 2;  /* Modbus t3.5 = 2 ms */

  39. /*
  40. * preset_multiple_registers: Modbus function 16. Write the data from an
  41. * array into the holding registers of a slave.
  42. * INPUTS
  43. * slave: modbus slave id number
  44. * start_addr: address of the slave's first register (+1)
  45. * reg_count: number of consecutive registers to preset
  46. * data: array of words (ints) with the data to write into the slave
  47. * RETURNS: the number of bytes received as response on success, or
  48. *         0 if no bytes received (i.e. response timeout)
  49. *        -1 to -4 (modbus exception code)
  50. *        -5 for other errors (port error, etc.).
  51. */

  52. int preset_multiple_registers(int slave, int start_addr,
  53. int reg_count, int *data);

  54. /*
  55. * read_holding_registers: Modbus function 3. Read the holding registers
  56. * in a slave and put the data into an array
  57. * INPUTS
  58. * slave: modbus slave id number
  59. * start_addr: address of the slave's first register (+1)
  60. * count: number of consecutive registers to read
  61. * dest: array of words (ints) on which the read data is to be stored
  62. * dest_size: size of the array, which should be at least 'count'
  63. * RETURNS: the number of bytes received as response on success, or
  64. *         0 if no valid response received (i.e. response timeout, bad crc)
  65. *        -1 to -4 (modbus exception code)
  66. *        -5 for other errors (port error, etc.).
  67. */

  68. int read_holding_registers(int slave, int start_addr, int count,
  69. int *dest, int dest_size);

  70. // include the library code:
  71. #include <LiquidCrystal.h>
  72. // initialize the library with the numbers of the interface pins
  73. LiquidCrystal lcd( 8, 7, 6, 5, 3, 2);

  74. //Ethernet & COSM
  75. #include <ERxPachube.h>
  76. #include <SPI.h>
  77. #include <Ethernet.h>

  78. // Enter a MAC address and IP address for your controller below.
  79. // The IP address will be dependent on your local network:
  80. byte mac[] = {
  81.   0xDE, 0xAD, 0xBE, 0xEE, 0xFF, 0xED };
  82. IPAddress ip(192,168,2, 120);

  83. #define PACHUBE_API_KEY "xxxxxxxxxxxx" // your Cosm API key
  84. #define PACHUBE_FEED_ID "97970" // your Cosm feed ID

  85. ERxPachubeDataOut dataout(PACHUBE_API_KEY, PACHUBE_FEED_ID);

  86. void PrintDataStream(const ERxPachube& pachube);

  87. void setup()
  88. {
  89.         const int baudrate = 4800;
  90.         if (baudrate <= 19200)
  91.                 interframe_delay = (unsigned long)(3.5 * 11 / baudrate);  /* Modbus t3.5 */
  92.         Serial.begin(baudrate);         /* format 8N1, DOES NOT comply with Modbus spec. */

  93.   // set up the LCD's number of columns and rows:
  94.   lcd.begin(20, 4);
  95.   // Print a message to the LCD.
  96.   lcd.setCursor(0, 0);
  97.   lcd.print("AC 485 Module");
  98.   delay(10000);               

  99.   // start the Ethernet connection and the server:
  100.   Ethernet.begin(mac, ip);

  101.         dataout.addData(0);
  102.         dataout.addData(1);
  103.         dataout.addData(2);
  104.         dataout.addData(3);
  105.         dataout.addData(4);
  106.         dataout.addData(5);

  107. }

  108. /* example data */
  109. int retval;
  110. int data[10];
  111. int tt[30];

  112. void loop()
  113. {
  114. int i;      
  115.   /* example, this will write some data in the first 10 registers of slave 1  */
  116. //                retval = preset_multiple_registers(1,1,10, data);

  117. //                data[0] = retval;
  118. //                data[1]++;
  119. //                data[8]=0xdead;
  120. //                data[9] = 0xbeaf;
  121. //                delay(500);
  122. //int read_holding_registers(int slave, int start_addr, int count,int *dest, int dest_size);               
  123. //                retval = read_holding_registers(2,1, 1,tt,6);        
  124.                 retval = read_holding_registers(1, 0x49, 6, tt, 1); // 1:5,2:7,3:9
  125. //                delay(1000);
  126. //                Serial.print("receve flag=");               
  127. //                Serial.println(retval);

  128. // print the number of return byte:
  129.   lcd.setCursor(17, 0);
  130.   lcd.print("R");
  131.   lcd.print(retval);

  132. // print the number of seconds since reset:
  133.   lcd.setCursor(0, 2);
  134.   lcd.print("                    ");
  135.   lcd.setCursor(0, 3);
  136.   lcd.print("                    ");

  137. //  lcd.println(tt[1];
  138. //                for (i = 0; i < (retval-0); i++) {lcd.print(":"); lcd.print(tt[i]);}                       //only test
  139. //                for (i = 0; i <retval; i++) {Serial.print("---"); Serial.println(tt[i]);}                       //only test

  140.     int Voltage  = tt[0]; Voltage = Voltage / 100;
  141.     float Amp      = tt[1]; Amp = Amp / 1000;
  142.     int Watt     = tt[2];
  143. //long y=x0*65536+x1;
  144.     int Kwhh = tt[3];
  145.     int Kwhl = tt[4];
  146.     unsigned  long kwhA = Kwhh *65536 + Kwhl;
  147. //    unsigned  long kwhA = Kwhh <<16 + Kwhl;
  148.     float Kwh = kwhA; Kwh = Kwh / 3200;
  149. //    double Kwh  = kwhA / 3200; //Kwh  = kwh / 32;
  150. //    int Kwh     = tt[4];
  151.     float Pf     = tt[5]; Pf = Pf / 1000;
  152.     float C     = tt[5]; C = C / 1000;


  153.   lcd.setCursor(0, 1);
  154.   lcd.print("V=");
  155.   lcd.print(Voltage);

  156.   lcd.setCursor(11, 1);
  157.   lcd.print("A=");
  158.   lcd.print(Amp);

  159.   lcd.setCursor(0, 2);
  160.   lcd.print("W=");
  161.   lcd.print(Watt);

  162.   lcd.setCursor(9, 2);
  163.   lcd.print("Kwh=");
  164.   lcd.print(Kwh);

  165.   lcd.setCursor(0, 3);
  166.   lcd.print("C=");
  167.   lcd.print(C);


  168.   lcd.setCursor(10, 3);
  169.   lcd.print("Pf=");
  170.   lcd.print(Pf);

  171. // print the number of seconds since reset:
  172. //  lcd.setCursor(0, 3);
  173. //  lcd.print(millis()/1000);

  174.         dataout.updateData(0, Voltage);
  175.         dataout.updateData(1, Amp);
  176.         dataout.updateData(2, Watt);
  177.         dataout.updateData(3, Kwh);
  178.         dataout.updateData(4, Pf);
  179.         dataout.updateData(5, C);

  180.         int status = dataout.updatePachube();

  181. //        Serial.print("sync status code <OK == 200> => ");
  182. //        Serial.println(status);

  183. //        PrintDataStream(dataout);


  184.   delay(20000);               


  185. }

  186. void PrintDataStream(const ERxPachube& pachube)
  187. {
  188.         unsigned int count = pachube.countDatastreams();
  189.         Serial.print("data count=> ");
  190.         Serial.println(count);

  191.         Serial.println("<id>,<value>");
  192.         for(unsigned int i = 0; i < count; i++)
  193.         {
  194.                 Serial.print(pachube.getIdByIndex(i));
  195.                 Serial.print(",");
  196.                 Serial.print(pachube.getValueByIndex(i));
  197.                 Serial.println();
  198.         }
  199. }

  200. /****************************************************************************
  201. * BEGIN MODBUS RTU MASTER FUNCTIONS
  202. ****************************************************************************/

  203. //#define TIMEOUT 1000                /* 1 second */
  204. #define TIMEOUT 10000                /* 10 second */
  205. #define MAX_READ_REGS 125
  206. #define MAX_WRITE_REGS 125
  207. #define MAX_RESPONSE_LENGTH 256
  208. #define PRESET_QUERY_SIZE 256
  209. /* errors */
  210. #define PORT_ERROR -5

  211. /*
  212. CRC

  213. INPUTS:
  214.         buf   ->  Array containing message to be sent to controller.            
  215.         start ->  Start of loop in crc counter, usually 0.
  216.         cnt   ->  Amount of bytes in message being sent to controller/
  217. OUTPUTS:
  218.         temp  ->  Returns crc byte for message.
  219. COMMENTS:
  220.         This routine calculates the crc high and low byte of a message.
  221.         Note that this crc is only used for Modbus, not Modbus+ etc.
  222. ****************************************************************************/

  223. unsigned int crc(unsigned char *buf, int start, int cnt)
  224. {
  225.         int i, j;
  226.         unsigned temp, temp2, flag;

  227.         temp = 0xFFFF;

  228.         for (i = start; i < cnt; i++) {
  229.                 temp = temp ^ buf[i];

  230.                 for (j = 1; j <= 8; j++) {
  231.                         flag = temp & 0x0001;
  232.                         temp = temp >> 1;
  233.                         if (flag)
  234.                                 temp = temp ^ 0xA001;
  235.                 }
  236.         }

  237.         /* Reverse byte order. */

  238.         temp2 = temp >> 8;
  239.         temp = (temp << 8) | temp2;
  240.         temp &= 0xFFFF;

  241.         return (temp);
  242. }


  243. /***********************************************************************
  244. *
  245. *         The following functions construct the required query into
  246. *         a modbus query packet.
  247. *
  248. ***********************************************************************/

  249. #define REQUEST_QUERY_SIZE 6        /* the following packets require          */
  250. #define CHECKSUM_SIZE 2                /* 6 unsigned chars for the packet plus   */
  251. /* 2 for the checksum.                    */

  252. void build_request_packet(int slave, int function, int start_addr,
  253. int count, unsigned char *packet)
  254. {
  255.         packet[0] = slave;
  256.         packet[1] = function;
  257.         start_addr -= 1;
  258.         packet[2] = start_addr >> 8;
  259.         packet[3] = start_addr & 0x00ff;
  260.         packet[4] = count >> 8;
  261.         packet[5] = count & 0x00ff;
  262.         
  263.                 //below test only
  264. //        packet[0] =0x01;
  265. //        packet[1] = 0x03;
  266. //        packet[2] = 0;
  267. //        packet[3] = 0x48;
  268. //        packet[4] = 0;
  269. //        packet[5] = 0x02;
  270. }

  271. /*************************************************************************
  272. *
  273. * modbus_query( packet, length)
  274. *
  275. * Function to add a checksum to the end of a packet.
  276. * Please note that the packet array must be at least 2 fields longer than
  277. * string_length.
  278. **************************************************************************/

  279. void modbus_query(unsigned char *packet, size_t string_length)
  280. {
  281.         int temp_crc;

  282.         temp_crc = crc(packet, 0, string_length);

  283.         packet[string_length++] = temp_crc >> 8;
  284.         packet[string_length++] = temp_crc & 0x00FF;
  285.         packet[string_length] = 0;
  286. }



  287. /***********************************************************************
  288. *
  289. * send_query(query_string, query_length )
  290. *
  291. * Function to send a query out to a modbus slave.
  292. ************************************************************************/

  293. int send_query(unsigned char *query, size_t string_length)
  294. {

  295.         int i;

  296.         modbus_query(query, string_length);
  297.         string_length += 2;

  298.         for (i = 0; i < string_length; i++) {
  299. //                Serial.print(query[i], HEX); //Orginal
  300.                 Serial.write(query[i]); //JingLi
  301.         
  302.         }
  303.         /* without the following delay, the reading of the response might be wrong
  304.         * apparently, */
  305.         delay(200);            /* FIXME: value to use? */

  306.         return i;                 /* it does not mean that the write was succesful, though */
  307. }


  308. /***********************************************************************
  309. *
  310. *         receive_response( array_for_data )
  311. *
  312. * Function to monitor for the reply from the modbus slave.
  313. * This function blocks for timeout seconds if there is no reply.
  314. *
  315. * Returns:        Total number of characters received.
  316. ***********************************************************************/

  317. int receive_response(unsigned char *received_string)
  318. {

  319.         int bytes_received = 0;
  320.         int i = 0;
  321.         /* wait for a response; this will block! */
  322.         while(Serial.available() == 0) {
  323.                 delay(1);
  324.                 if (i++ > TIMEOUT)
  325.                         return bytes_received;
  326.         }
  327.         delay(200);
  328.         /* FIXME: does Serial.available wait 1.5T or 3.5T before exiting the loop? */
  329.         while(Serial.available()) {
  330.                 received_string[bytes_received] = Serial.read();
  331. //                Serial.print(bytes_received);                       //only test
  332. //                Serial.print("-");                                //only test
  333. //                Serial.println(received_string[bytes_received]);  //only test
  334.                 bytes_received++;
  335.                 if (bytes_received >= MAX_RESPONSE_LENGTH)
  336.                         return PORT_ERROR;
  337.         }   
  338. //Serial.print("bytes_received=");
  339. //Serial.println(bytes_received);
  340.         return (bytes_received);
  341. }


  342. /*********************************************************************
  343. *
  344. *         modbus_response( response_data_array, query_array )
  345. *
  346. * Function to the correct response is returned and that the checksum
  347. * is correct.
  348. *
  349. * Returns:        string_length if OK
  350. *                 0 if failed
  351. *                 Less than 0 for exception errors
  352. *
  353. *         Note: All functions used for sending or receiving data via
  354. *               modbus return these return values.
  355. *
  356. **********************************************************************/

  357. int modbus_response(unsigned char *data, unsigned char *query)
  358. {
  359.         int response_length;
  360.         int i;
  361.         unsigned int crc_calc = 0;
  362.         unsigned int crc_received = 0;
  363.         unsigned char recv_crc_hi;
  364.         unsigned char recv_crc_lo;

  365.       do {        // repeat if unexpected slave replied
  366.                 response_length = receive_response(data);
  367.       } while ((response_length > 0) && (data[0] != query[0]));
  368. //      for (i = 0; i <response_length; i++) {           Serial.print(data[i]);Serial.print("---");   Serial.println(query[i]);}                       //only test

  369.         if (response_length) {


  370.                 crc_calc = crc(data, 0, response_length - 2);

  371.                 recv_crc_hi = (unsigned) data[response_length - 2];
  372.                 recv_crc_lo = (unsigned) data[response_length - 1];

  373.                 crc_received = data[response_length - 2];
  374.                 crc_received = (unsigned) crc_received << 8;
  375.                 crc_received =
  376.                         crc_received | (unsigned) data[response_length - 1];


  377.                 /*********** check CRC of response ************/

  378.                 if (crc_calc != crc_received) {
  379.                         response_length = 0;
  380. //                       Serial.println("CRC erro");                       //only test
  381.                 }



  382.                 /********** check for exception response *****/

  383.                 if (response_length && data[1] != query[1]) {
  384.                         response_length = 0 - data[2];
  385.                 }
  386.         }
  387.         return (response_length);
  388. }


  389. /************************************************************************
  390. *
  391. *         read_reg_response
  392. *
  393. *         reads the response data from a slave and puts the data into an
  394. *         array.
  395. *
  396. ************************************************************************/

  397. int read_reg_response(int *dest, int dest_size, unsigned char *query)
  398. {

  399.         unsigned char data[MAX_RESPONSE_LENGTH];
  400.         int raw_response_length;
  401.         int temp, i;

  402.         raw_response_length = modbus_response(data, query);
  403.         if (raw_response_length > 0)
  404.                 raw_response_length -= 2;

  405.         if (raw_response_length > 0) {
  406.                 /* FIXME: data[2] * 2 ???!!! data[2] isn't already the byte count (number of registers * 2)?! */
  407.                 for (i = 0;
  408.                      i < (data[2] * 2) && i < (raw_response_length / 2);
  409.                      i++) {

  410.                         /* shift reg hi_byte to temp */
  411.                         temp = data[3 + i * 2] << 8;
  412.                         /* OR with lo_byte           */
  413.                         temp = temp | data[4 + i * 2];

  414.                         dest[i] = temp;
  415.                 }
  416.         }
  417.         return (raw_response_length);
  418. }


  419. /***********************************************************************
  420. *
  421. *         preset_response
  422. *
  423. *         Gets the raw data from the input stream.
  424. *
  425. ***********************************************************************/

  426. int preset_response(unsigned char *query)
  427. {
  428.         unsigned char data[MAX_RESPONSE_LENGTH];
  429.         int raw_response_length;

  430.         raw_response_length = modbus_response(data, query);

  431.         return (raw_response_length);
  432. }


  433. /************************************************************************
  434. *
  435. *         read_holding_registers
  436. *
  437. *         Read the holding registers in a slave and put the data into
  438. *         an array.
  439. *
  440. *************************************************************************/

  441. int read_holding_registers(int slave, int start_addr, int count,
  442. int *dest, int dest_size)
  443. {
  444.         int function = 0x03;         /* Function: Read Holding Registers */
  445.         int ret;

  446.         unsigned char packet[REQUEST_QUERY_SIZE + CHECKSUM_SIZE];

  447.         if (count > MAX_READ_REGS) {
  448.                 count = MAX_READ_REGS;
  449.         }

  450.         build_request_packet(slave, function, start_addr, count, packet);

  451.         if (send_query(packet, REQUEST_QUERY_SIZE) > -1) {
  452.                 ret = read_reg_response(dest, dest_size, packet);
  453.         }
  454.         else {

  455.                 ret = -1;
  456.         }

  457.         return (ret);
  458. }


  459. /************************************************************************
  460. *
  461. *         preset_multiple_registers
  462. *
  463. *         Write the data from an array into the holding registers of a
  464. *         slave.
  465. *
  466. *************************************************************************/

  467. int preset_multiple_registers(int slave, int start_addr,
  468. int reg_count, int *data)
  469. {
  470.         int function = 0x10;         /* Function 16: Write Multiple Registers */
  471.         int byte_count, i, packet_size = 6;
  472.         int ret;

  473.         unsigned char packet[PRESET_QUERY_SIZE];

  474.         if (reg_count > MAX_WRITE_REGS) {
  475.                 reg_count = MAX_WRITE_REGS;
  476.         }

  477.         build_request_packet(slave, function, start_addr, reg_count, packet);
  478.         byte_count = reg_count * 2;
  479.         packet[6] = (unsigned char)byte_count;

  480.         for (i = 0; i < reg_count; i++) {
  481.                 packet_size++;
  482.                 packet[packet_size] = data[i] >> 8;
  483.                 packet_size++;
  484.                 packet[packet_size] = data[i] & 0x00FF;
  485.         }

  486.         packet_size++;
  487.         if (send_query(packet, packet_size) > -1) {
  488.                 ret = preset_response(packet);
  489.         }
  490.         else {
  491.                 ret = -1;
  492.         }

  493.         return (ret);
  494. }

复制代码



程序和硬件,慢慢整理以后,与大家分享。
COSM97970.jpg

乐扣饭盒版电量管理

乐扣饭盒版电量管理
回复

使用道具 举报

发表于 2013-1-17 08:46:29 | 显示全部楼层
这个值得赞一个!
回复 支持 反对

使用道具 举报

发表于 2013-1-17 09:27:37 | 显示全部楼层
哈哈 我也是把插座拆了 线接的继电器
回复 支持 反对

使用道具 举报

发表于 2013-1-17 09:30:55 | 显示全部楼层
交流电量管理模块哪买的?求地址
回复 支持 反对

使用道具 举报

发表于 2013-1-17 10:06:41 | 显示全部楼层
非常不错!应用到生活中来了!
回复 支持 反对

使用道具 举报

发表于 2013-1-17 10:54:15 | 显示全部楼层
好东西呀,是怎么做的?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-1-17 11:30:23 | 显示全部楼层
本帖最后由 muggle 于 2013-1-17 12:11 编辑
ttyp 发表于 2013-1-17 09:30
交流电量管理模块哪买的?求地址


淘宝的立天电子工作室,北京的一个卖家。
回复 支持 反对

使用道具 举报

发表于 2013-1-17 12:58:48 | 显示全部楼层
muggle 发表于 2013-1-17 11:30
淘宝的立天电子工作室,北京的一个卖家。

LZ你是买的30A的么?夏天空调够用么?你为什么不用TTL而用485接口啊,arduino不是天生支持ttl的啊
回复 支持 反对

使用道具 举报

发表于 2013-1-17 17:32:52 | 显示全部楼层
建议直接把控制器弄到盒子中。用网线或者无线把数据传输出来。hoho
回复 支持 反对

使用道具 举报

发表于 2013-1-17 18:00:12 | 显示全部楼层
呵呵,这个在微博上见过。这回对上人了。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-1-17 19:29:46 | 显示全部楼层
laoliu1982 发表于 2013-1-17 18:00
呵呵,这个在微博上见过。这回对上人了。

我会试验一下,把数据上传到lewei,也希望得到你们的帮助。我现在使用ERxPachube.h,很简单的推送数据到COSM,也就是“沧海笑1122”的例子“Arduino学习笔记:2560+W5100试验实时室温对Pachubbe.com推送”。

我刚想问怎么推送多个数据到lewei,看到了“Arduino+W5100 通过LeweiClient上传数据,不用再理解http了-乐联网应用”。这就太好了,可以轻松试验数据上传。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-1-17 19:35:07 | 显示全部楼层
ttyp 发表于 2013-1-17 12:58
LZ你是买的30A的么?夏天空调够用么?你为什么不用TTL而用485接口啊,arduino不是天生支持ttl的啊

卖家的指标“最大电流可以达到16A”,空调包括柜机都够。我会接到热水器上面,也是同样的功率级别。

这个属于一次接入,需要改动线路,建议只用在独立电器,也就是插座之前,不建议用到入户总表一段。卖家有一款电流互感器,属于二次接入,适宜安置在入户总表或者总空开之间,因为不需要变动线路,卡紧电流传感器,随便接电即可。

电力线路,改造有风险,无经验勿入!!!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-1-17 19:36:14 | 显示全部楼层
zcbzjx 发表于 2013-1-17 17:32
建议直接把控制器弄到盒子中。用网线或者无线把数据传输出来。hoho

我是准备用nRF桥接,把数据传过来,成本低廉而且相对隔离,安全有保证。
回复 支持 反对

使用道具 举报

发表于 2013-1-17 20:04:55 | 显示全部楼层
muggle 发表于 2013-1-17 19:29
我会试验一下,把数据上传到lewei,也希望得到你们的帮助。我现在使用ERxPachube.h,很简单的推送数据到C ...

必须的,有问题随时联系
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-1-17 20:09:40 | 显示全部楼层
ttyp 发表于 2013-1-17 12:58
LZ你是买的30A的么?夏天空调够用么?你为什么不用TTL而用485接口啊,arduino不是天生支持ttl的啊

我不是专家,不过,懂行的朋友如是说:

485是差分的方式,不需要公共地。电平为正负0.2负。

TTL电平为0-5V,通讯时,需要一个公共地。
回复 支持 反对

使用道具 举报

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

本版积分规则

Archiver|联系我们|极客工坊 ( 浙ICP备09023225号 )

GMT+8, 2019-1-22 09:06 , Processed in 0.064203 second(s), 27 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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