před nedávnem jsem se spustil do vyroby ridici desky pro ovladani domu, predevsim bojleru a topeni (pro zacatek). Pri navrhu desky jsem se rozhodl pouzi arduino nano a ENC28J60 ethernet (coz nyni vim ze nebyla dobra volba pro usetreni mista na pcb). Pri zapojeni prvnich cidel a rele vse fungovalo bez problemu (prozatim teplotni cidla ds18b20, ktera jsou pripojena kazde zvlast na vlastni port a vytvarim z nich multibus). Bohuzel jakmile jsem prekrocil 5te teplotni cidlo tak retezeni cidel nejak prestalo fungovat, i kdyz vyuziti pameti se nijak nezmenilo. Pri vyprintovani vysledku na serial vzdy dostanu pouze prazdnou hodnotu. Vytvarim vetsi retezec pro GET metodu, atributy jsou pripraveny pro budouci cidla. Proto bych Vas chtel pozadat o radu v cem muze byt problem. Jestli vyuzit jiny datovy typ nez string?
Dekuji
retezeni hodnot z cidel pro get String
Kód: Vybrat vše
for (int i = 0; i < oneWireCount; i++) {
sensor[i].requestTemperatures();
postData = postData + "Zarizeni_ID_" + i + "=" + i + "&Atribut_" + i + "=1 & Hodnota_" + i + "=" + sensor[i].getTempCByIndex(0);
}
ovladaci deska
![Obrázek](http://antrac1t.cz/IMG_20190908_122326.jpg)
kod
Kód: Vybrat vše
//Ethernet
#include <UIPEthernet.h>
byte mac[] = { 0x94, 0xE7, 0xF2, 0xF1, 0x44, 0x0A };
EthernetClient client;
char server[] = "server";
IPAddress ip(10, 0, 0, 19);
IPAddress dns2(10, 0, 0, 138);
IPAddress gateway(10, 0, 0, 138);
IPAddress subnet(255, 255, 255, 0);
//temperatures
//------------------------------------------------------
#include <OneWire.h>
#include <DallasTemperature.h>
//bojler vrsek, bojler spodek, aku nadrz,obyvak termostat,
OneWire ds18x20[] = { 7, 8, 6, 5, 9 };
const int oneWireCount = sizeof(ds18x20) / sizeof(OneWire);
DallasTemperature sensor[oneWireCount];
int Getinterval = 3000;
unsigned long GetMethodTime;
String postData;
String tempData;
//PCF
//------------------------------------------------------
#include "PCF8574.h"
#include <Wire.h>
PCF8574 pcf(0x20);
PCF8574 pcf2(0x21);
PCF8574 pcf3(0x22);
PCF8574 pcf4(0x23);
int DeviceString[10];
int DeviceIncrement;
int StatusString[10];
uint8_t ValveString[10];
//------------------------------------------------------
//topeni kohouty
//RadiatoryON,AkuNadryON,AkuNadryON,KuchyneON
//RadiatoryOFF,AkuNadryOFF,KoupelnaON,KuchyneOFF
const byte EndSwitchON[4] = {0, 2, 4, 6};
const byte EndSwitchOFF[4] = {1, 3, 5, 7};
void setup() {
Serial.begin(9600);
//ethernet
Ethernet.begin(mac, ip, dns2, gateway, subnet);
Serial.println(Ethernet.localIP());
Serial.println(Ethernet.subnetMask());
Serial.println(Ethernet.gatewayIP());
Serial.println(Ethernet.dnsServerIP());
//dallas teplomery
DeviceAddress deviceAddress;
for (int i = 0; i < oneWireCount; i++) {
sensor[i].setOneWire(&ds18x20[i]);
sensor[i].begin();
if (sensor[i].getAddress(deviceAddress, 0)) sensor[i].setResolution(deviceAddress, 12);
}
//pcf
pcf.begin();
pcf2.begin();
pcf3.begin();
pcf4.begin();
}
void loop() {
if (millis() > GetMethodTime + Getinterval) {
getTemps();
sendGET();
GetMethodTime = millis();
}
//Valve();
}
void getTemps() {
postData = "";
for (int i = 0; i < oneWireCount; i++) {
sensor[i].requestTemperatures();
postData = postData + "Zarizeni_ID_" + i + "=" + i + "&Atribut_" + i + "=1 & Hodnota_" + i + "=" + sensor[i].getTempCByIndex(0);
}
Serial.println(postData);
}
void Valve() {
for (int i = 0; i < 10; i++) {
if (ValveString[i] != 0) {
switch (StatusString[i]) {
case 0:
if (pcf4.readButton(EndSwitchOFF[ValveString[i - 1]]) == true ) {
pcf.write(ValveString[i], 1);
}
else
{
pcf.write(ValveString[i], 0);
}
break;
case 1:
if (pcf4.readButton(EndSwitchON[ValveString[i - 1] ]) == true ) {
pcf.write(ValveString[i], 1);
}
else
{
pcf.write(ValveString[i], 0);
}
break;
}
}
}
}
void sendGET() {
if (client.connect(server, 80)) { //starts client connection, checks for connection
Serial.println(F("connected"));
client.print(F("GET adresa));
client.println(F(" HTTP / 1.1")); //download text
client.println(F("Content - Type: application / x - www - form - urlencoded"));
client.println(F("Host: server"));
client.println(F("Connection: close")); //close 1.1 persistent connection
client.print(F("Content - Length: "));
client.println(postData.length());
client.println();
client.print(postData);
delay(10);
}
else {
Serial.println(F("connection failed"));
return;
}
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
//Serial.println(F(" >>> Client Timeout !"));
client.stop();
return;
}
}
DeviceIncrement = 0;
while (client.connected() && !client.available()) delay(50); //waits for data
while (client.connected() || client.available()) { //connected or data available
char m = client.read(); //gets byte from ethernet buffer
// d - device
// v - valve device
// s - status
if (m == '#') {
char n = client.read();
if (n == 'd') {
DeviceString[DeviceIncrement] = client.readStringUntil('*').toInt();
DeviceIncrement = DeviceIncrement + 1;
}
// if (n == 'v') {
// ValveString[DeviceIncrement - 1] = client.readStringUntil('*').toInt();
// DeviceIncrement = DeviceIncrement + 1;
// }
if (n == 's') {
StatusString[DeviceIncrement - 1] = client.readStringUntil('*').toInt();
if (StatusString[DeviceIncrement - 1] == 0) {
if (DeviceString[DeviceIncrement - 1] <= 7) {
pcf.write(DeviceString[DeviceIncrement - 1], 1);
}
else
{
pcf2.write(DeviceString[DeviceIncrement - 8], 1);
}
}
else {
if (DeviceString[DeviceIncrement - 1] <= 7) {
pcf.write(DeviceString[DeviceIncrement - 1], 0);
}
else {
pcf2.write(DeviceString[DeviceIncrement - 8], 0);
}
}
}
}
}
client.stop();
}