Подключил датчик температуры к сайту
http://narodmon.ru/Всё просто. Ардуина Уно и плата сетевого шилда на en28j60. Датчик Dallas DS18B20.
Проблемой было найти нормальные библиотеки для них.
Ниже код, он работает - взял готовый с какого-то форума.
Перед этим перелопатил много всякого.
//все работает
#include
#include
#include
#define ONE_WIRE_BUS 2
String mac ="002B3420DEAD";
float tempC = 0.0;
// ethernet interface mac address, must be unique on the LAN
byte mymac[] = {
0x00,0x2b,0x34,0x20,0xde,0xad };
//char website[] PROGMEM = "narodmon.ru:8080";
static byte hisip[] = {
92,39,235,156,8283 };
#define REQUEST_RATE 300000 // milliseconds
byte Ethernet::buffer[700];
uint32_t timer;
Stash stash;
static char statusstr[10];
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
void setup () {
sensors.begin();
Serial.begin(57600);
Serial.println("\n[webClient]");
delay(1000);
if (ether.begin(sizeof Ethernet::buffer, mymac, SS) == 0)
Serial.println( "Failed to access Ethernet controller");
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
//overwrite DNS with google's if there are problems with DNS setup
static byte dnsip[] = {
8,8,8,8 };
ether.copyIp(ether.dnsip, dnsip);
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
ether.copyIp(ether.hisip, hisip);
ether.printIp("Server: ", ether.hisip);
while (ether.clientWaitingGw())
ether.packetLoop(ether.packetReceive());
Serial.println("Gateway found");
timer = - REQUEST_RATE; // start timing out right away
}
void loop () {
//word len = ether.packetReceive();
//word pos = ether.packetLoop(len);
ether.packetLoop(ether.packetReceive());
if (millis() > timer + REQUEST_RATE)
{
timer = millis();
sensors.begin();
sensors.requestTemperatures(); // Send the command to get temperatures
tempC = sensors.getTempCByIndex(0);
// we can determine the size of the generated message ahead of time
byte sd = stash.create();
stash.print("ID=");
stash.print(mac);
stash.print("&");
stash.print(mac);
stash.print("02");
stash.print("=");
stash.print(tempC);
stash.save();
Serial.print("ID=");
Serial.print(mac);
Serial.print("&");
Serial.print(mac);
Serial.print("02");
Serial.print("=");
Serial.println(tempC);
//tempC+=0.01
// generate the header with payload - note that the stash size is used,
// and that a "stash descriptor" is passed in as argument using "$H"
Stash::prepare(PSTR("POST http://narodmon.ru/post.php HTTP/1.0" "\r\n"
"Host: narodmon.ru" "\r\n"
"Content-Length: $D" "\r\n"
"\r\n"
"$H"),
stash.size(), sd);
// send the packet - this also releases all stash buffers once done
ether.tcpSend();
Serial.println("Done");
//Serial.println("Pause start");
//delay(10000);
//Serial.println("Pause end");
}
}
https://github.com/milesburton/Arduino-Temperature-Control-Libraryhttps://github.com/davidhbrown/RealTimeClockDS1307https://github.com/jcw/ethercard UPD: особенно плохая ситуация с библиотеками для RTC - каждый их лепит сам и их полно лежит недоделанных. Там всё достаточно просто, но использовать готовую всё равно быстрее, поэтому полно воплей на форумах: "ааа, помогите, поставил а оно не работает"; я сам с таким сталкивался, когда не понимая принципов работы ставишь чужой код, а он ведёт себя непредсказуемо. В результате, потеряв кучу времени, находишь причину - она оказывается смехотворной, вроде того, что не на тот пин коннектился, или не ту цифру поменял. Знание принципов всегда лучше, чем скорость. В итоге оно и быстрее выходит.
А для сетевых модулей - может быть проблемой - различия в железе. У моего модуля:
SS 10
MOSI 11
MISO 12
SCK 13
у других может быть по другому. Стандартная ethernet-библиотека ардуины работает с платой на чипе W5100, а не en28j60. Для последней платы - библиотеки появились в инете недавно, созданы энтузиастами. Серверную часть для неё находил уже давно, а теперь нашёл и клиентскую. Теперь можно не только запрашивать у ардуины данные, но и отправлять их сразу с ардуины по расписанию куда-либо в интернет.Или не сервер "умного дома".