Re: Arduino Mega Server (AMS) - погодная станция
Добавлено: Вс окт 29, 2017 12:26 am
....Даа...Не любит безумный робот цифровых художников ! Alex, снимите два бана! Картинки интересные!
Код: Выделить всё
#include <SD.h>
#include <OneWire.h>
#include <SPI.h>
#include <Ethernet.h>
/*********** SD Stuff ****************/
// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 4;
/*********** ETHERNET STUFF ***********/
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 177 };
EthernetServer server(80);
#define BUFSIZ 100
/********** OneWire Stuff ************/
OneWire ds(9); // OneWire bus on pin 9
float celsius[10], fahrenheit[10];
int cnt=0, maxCnt;
/********** Radial Stuff ************/
char *bcname[]={"HLT","MLT","RIMS","BOIL","TBD"};
char *bcrfn[]={"bcr100.htm","bcr150.htm","bcr200.htm","bcr250.htm","bcr300.htm","bcr350.htm"};
int bcrsize[]={100,150,200,250,300,350};
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
// Serial.print("Initializingard...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(10, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println(F("Card failed, or not present"));
// don't do anything more:
return;
}
// Serial.println(F("SD card initialized."));
// set up bcradial.htm
void writeBCRfile(char *filename, int size)
{
int cntz;
File bcrWriteFile = SD.open(filename, FILE_WRITE);
if (bcrWriteFile)
{
bcrWriteFile.println(F("<!DOCTYPE html>"));
bcrWriteFile.println(F("<html lang=\"en\">"));
bcrWriteFile.println(F("<head>"));
bcrWriteFile.println(F(" <meta charset=\"utf-8\" />"));
bcrWriteFile.println(F(" <title>ButtCrack Brewery</title>"));
bcrWriteFile.println(F(" <script type='text/javascript' src='http://www.buttcrackbrewery.com/js/Arduino/tween.js'></script bcrWriteFile.println(F(" <script type='text/javascript' src='http://www.buttcrackbrewery.com/js/Arduino/sslib1.js'></script bcrWriteFile.println(F(""));
bcrWriteFile.println(F(" <script type=\"application/javascript\">"));
bcrWriteFile.println(F(""));
bcrWriteFile.println(F("// Ajax request for xml data generated by Arduino"));
bcrWriteFile.println(F(" function ajaxUpdateValues()"));
bcrWriteFile.println(F(" {"));
bcrWriteFile.println(F(""));
bcrWriteFile.println(F(" var httpRequest;"));
bcrWriteFile.println(F(" var xmlDoc;"));
bcrWriteFile.println(F(""));
bcrWriteFile.println(F("// get the xml document via Ajax/http"));
bcrWriteFile.println(F(" httpRequest = new XMLHttpRequest();"));
bcrWriteFile.println(F(" httpRequest.onreadystatechange=function() {"));
bcrWriteFile.println(F(" if(httpRequest.readyState == 4) {"));
bcrWriteFile.println(F(" steamPress = Number(httpRequest.responseText);"));
bcrWriteFile.println(F(" }"));
bcrWriteFile.println(F(" }"));
bcrWriteFile.println(F(" httpRequest.open(\"GET\",\"http://192.168.1.177/butcrack.xml\",falseeFile.println(F(" httpRequest.send(null);"));
bcrWriteFile.println(F(" xmlDoc=httpRequest.responseXML;"));
bcrWriteFile.println(F("\n// update the global variables by parsing the xml document"));
for(cntz = 0; cntz < maxCnt; cntz++)
{
bcrWriteFile.print(F(" Temp"));
bcrWriteFile.print(cntz);
bcrWriteFile.print(F("=Number(xmlDoc.getElementsByTagName(\"Temp bcrWriteFile.print(cntz);
bcrWriteFile.println(F("\")[0].childNodes[0].nodeValue);"));
}
bcrWriteFile.println(F(""));
bcrWriteFile.println(F(" }"));
bcrWriteFile.println(F(""));
bcrWriteFile.println(F(" function init()"));
bcrWriteFile.println(F(" {"));
bcrWriteFile.println(F(""));
bcrWriteFile.println(F("// Define section(s)"));
bcrWriteFile.print(F(" sections = Array(steelseries.Section(68, 80,\"rgba(0, 0, 254, 0.9)\"),\n\t steelseries.Section(140, 160,\"rgba(0, 254, 0, 0.9)\"),\n\t steelseries.Section(160, 180,\"rgba(254, 254, 0, 0.9)\"),\n\t steelseries.Section(180, 220, \"rgba(254, 0, 0, 0.9)\"));\n"));
bcrWriteFile.println(F(""));
bcrWriteFile.println(F("// Define area(s)"));
bcrWriteFile.print(F(" areas = Array(steelseries.Section(68, 80,\"rgba(0, 0, 254, 0.9)\"),\n\tsteelseries.Section(140, 160,\"rgba(0, 254, 0, 0.9)\"),\n\tsteelseries.Section(160, 180,\"rgba(254, 254, 0, 0.9)\"),\n\tsteelseries.Section(180, 220, \"rgba(254, 0, 0, 0.9)\"));\n"));
bcrWriteFile.println(F(""));
bcrWriteFile.println(F("// Initialize gauge"));
for(cntz = 0; cntz < maxCnt; cntz++)
{
bcrWriteFile.print(F(" radial"));
bcrWriteFile.print(cntz);
bcrWriteFile.print(F(" = new steelseries.Radial(\"Temp"));
bcrWriteFile.print(cntz);
bcrWriteFile.println(F("\", "));
bcrWriteFile.println(F(" {"));
// bcrWriteFile.println(F("// gaugeType: steelseries.GaugeType.TYPE3,"));
bcrWriteFile.print(F("\tsize"));
bcrWriteFile.print(size);
bcrWriteFile.print(F(",\n\tminValuen\tmaxValue: 220,\n\tthreshold: 152,\n\tsection: sections,\n\tarea: areas,\n\ttitleString: \""));
bcrWriteFile.print(bcname[cntz]);
bcrWriteFile.println(F("\",\n\tunitString: \"°F\",\n\tpointerType: steelseries.PointerType.TYPE2,\n\tframeDesign: steelseries.FrameDesign.BLACK_METAL,\n\tforegroundType: steelseries.ForegroundType.TYPE3,\n\tbackgroundColor: steelseries.BackgroundColor.CARBON,\n\tledVisible: true"));
bcrWriteFile.println(F(" });"));
bcrWriteFile.println(F(""));
}
bcrWriteFile.println(F(""));
bcrWriteFile.println(F("// Start the random update"));
bcrWriteFile.println(F(" setInterval(function(){ ajaxUpdateValues(); }, 5000); "));
for(cntz = 0; cntz < maxCnt; cntz++)
{
bcrWriteFile.print(F(" setInterval(function(){ setValue(radial"));
bcrWriteFile.print(cntz);
bcrWriteFile.print(F(", Temp"));
bcrWriteFile.print(cntz);
bcrWriteFile.println(F("); }, 10000);"));
}
// bcrWriteFile.println(F(""));
bcrWriteFile.println(F("\n }"));
bcrWriteFile.println(F(""));
bcrWriteFile.println(F(" function setValue(gauge, range)"));
bcrWriteFile.println(F(" {"));
bcrWriteFile.println(F(" gauge.setValueAnimated(range);"));
bcrWriteFile.println(F(" }"));
bcrWriteFile.println(F(""));
bcrWriteFile.println(F(""));
bcrWriteFile.println(F("</script>"));
// bcrWriteFile.println(F("<style>body {background: url(\"http://www.buttcrackbrewery.com/images/Arduino/bc.png\");}</style bcrWriteFile.println(F("</head>"));
bcrWriteFile.println(F("<body onload=\"init()\"> "));
for(cntz = 0; cntz < maxCnt; cntz++)
{
bcrWriteFile.print(F("\t<canvasmp"));
bcrWriteFile.print(cntz);
bcrWriteFile.println(F("\">\n\tNo canvas in your browser...sorry...\n\t</canvas>"));
}
bcrWriteFile.println(F("</body>"));
bcrWriteFile.println(F("</html>"));
bcrWriteFile.close();
Serial.print(filename);
Serial.println(F(" written"));
} else {
// if the file didn't open, print an error:
Serial.println(F("error opening bcradial.htm"));
}
}
Код: Выделить всё
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiClient.h>
#include <ArduinoJson.h>
#include <DNSServer.h>
Код: Выделить всё
void homepage(){
append_page_header();
webpage += F("<hr>");
webpage += F("<table class='style7'>");
webpage += F(" <tr>");
webpage += " <th>"+DWDay1+"</th>";
webpage += " <th>"+DWDay2+"</th>";
webpage += " <th>"+DWDay3+"</th>";
webpage += " <th>"+DWDay4+"</th>";
webpage += F(" </tr>");
webpage += F(" <tr>");
webpage += F(" <td>");
webpage += " "+DDateDa1+"-"+DMon1+"-"+DDateYr1;
webpage += F(" </td>");
webpage += F(" <td>");
webpage += " "+DDateDa2+"-"+DMon2+"-"+DDateYr2;
webpage += F(" </td>");
webpage += F(" <td>");
webpage += " "+DDateDa3+"-"+DMon2+"-"+DDateYr3;
webpage += F(" </td>");
webpage += F(" <td>");
webpage += " "+DDateDa4+"-"+DMon3+"-"+DDateYr4;
webpage += F(" </td>");
webpage += F(" </tr>");
webpage += F(" <tr>");
webpage += " <td> <img class='imgdisplay' alt='wx' height='70' src='"+Dicon_url1+"' width='70'/></td>";
webpage += " <td> <img class='imgdisplay' alt='wx' height='70' src='"+Dicon_url2+"' width='70'/></td>";
webpage += " <td> <img class='imgdisplay' alt='wx' height='70' src='"+Dicon_url3+"' width='70'/></td>";
webpage += " <td> <img class='imgdisplay' alt='wx' height='70' src='"+Dicon_url4+"' width='70'/></td>";
webpage += F(" </tr>");
webpage += F(" <tr>");
webpage += F(" <td class='style8'>Max - Min - Hum</td>");
webpage += F(" <td class='style8'>Max - Min - Hum</td>");
webpage += F(" <td class='style8'>Max - Min - Hum</td>");
webpage += F(" <td class='style8'>Max - Min - Hum</td>");
webpage += F(" </tr>");
webpage += F(" <tr>");
webpage += F(" <td class='style9'>");
webpage += "  "+DHtemp1+"°  "+DLtemp1+"°  "+DHumi1+"%</td>";
webpage += F(" </td>");
webpage += F(" <td class='style9'>");
webpage += "  "+DHtemp2+"°  "+DLtemp2+"°  "+DHumi2+"%</td>";
webpage += F(" </td>");
webpage += F(" <td class='style9'>");
webpage += "  "+DHtemp3+"°  "+DLtemp3+"°  "+DHumi3+"%</td>";
webpage += F(" </td>");
webpage += F(" <td class='style9'>");
webpage += "  "+DHtemp4+"°  "+DLtemp4+"°  "+DHumi4+"%</td>";
webpage += F(" </td>");
webpage += F(" </tr>");
webpage += F(" <tr>");
webpage += F(" <td class='style9'>");
webpage += " "+winddirsymbol(&DW_dir1) + " @ " + DW_mph1;
webpage += F(" </td>");
webpage += F(" <td class='style9'>");
webpage += " "+winddirsymbol(&DW_dir2) + " @ " + DW_mph2;
webpage += F(" </td>");
webpage += F(" <td class='style9'>");
webpage += " "+winddirsymbol(&DW_dir3) + " @ " + DW_mph3;
webpage += F(" </td>");
webpage += F(" <td class='style9'>");
webpage += " "+winddirsymbol(&DW_dir4) + " @ " + DW_mph4;
webpage += F(" </td>");
webpage += F(" </tr>");
webpage += F(" <tr>");
webpage += F(" <td class='style8'>");
webpage += " "+DPop1+"% chance of "+((DRain1=="0mm"||DRain1=="0in")?"rain":DRain1+" rain");
webpage += F(" </td>");
webpage += F(" <td class='style8'>");
webpage += " "+DPop2+"% chance of "+((DRain2=="0mm"||DRain2=="0in")?"rain":DRain2+" rain");
webpage += F(" </td>");
webpage += F(" <td class='style8'>");
webpage += " "+DPop3+"% chance of "+((DRain3=="0mm"||DRain3=="0in")?"rain":DRain3+" rain");
webpage += F(" </td>");
webpage += F(" <td class='style8'>");
webpage += " "+DPop4+"% chance of "+((DRain4=="0mm"||DRain4=="0in")?"rain":DRain4+" rain");
webpage += F(" </td>");
webpage += F(" </tr>");
webpage += F(" </table>");
webpage += F("<br>");
append_page_footer();
server.send(200, "text/html", webpage);
}
Код: Выделить всё
<tr>
<td><img class='imgdisplay' alt='wx' height='70' src='http://icons.wxug.com/i/c/k/chancerain.gif' width='70'/></td>
<!--<td><span id="dicon_url1"></span></td>--> // так не работает
<td><img class='imgdisplay' alt='wx' height='70' src='http://icons.wxug.com/i/c/k/chancerain.gif' width='70'/></td>
<td><img class='imgdisplay' alt='wx' height='70' src='http://icons.wxug.com/i/c/k/rain.gif' width='70'/></td>
<td><img class='imgdisplay' alt='wx' height='70' src='http://icons.wxug.com/i/c/k/partlycloudy.gif' width='70'/></td>
</tr>
Код: Выделить всё
<td>
<img class='imgdisplay' alt='wx' height='70' src='http://icons.wxug.com/i/c/k/chancerain.gif' width='70'/>
</td>
В продолжение темы. Первоисточник я уже не найду , но все это удалось воткнуть в AMS , залезть на сайт, получить ответ в JSON и вывести кое что на страницу. В оригинале код страниц похоже сидит в памяти 8266 и выводится в браузер на 5000 порту. Полный код вкладки Тогда собственно остался один вопрос. В XML таблице выводятся 4 ссылки на иконки " тучек"Что-то делать на втором сервере вообще не очень хорошая идея
Код: Выделить всё
function weekday(day) {
switch (day) {
case "1": return "Воскресенье"; break;
case "2": return "Понедельник"; break;
case "3": return "Вторник"; break;
case "4": return "Среда"; break;
case "5": return "Четверг"; break;
case "6": return "Пятница"; break;
case "7": return "Суббота"; break;
default: return ""; break;
}
}
Код: Выделить всё
<Dicon_url1>http://icons.wxug.com/i/c/k/clear.gif</Dicon_url1> // Как её вытащить на страницу ??
Код: Выделить всё
<tr>
<td><img class='imgdisplay' alt='wx' height='70' src='http://icons.wxug.com/i/c/k/chancerain.gif' width='70'/></td>
<!--<td><span id="dicon_url1"></span></td>--> // так не работает
<td><img class='imgdisplay' alt='wx' height='70' src='http://icons.wxug.com/i/c/k/chancerain.gif' width='70'/></td>
<td><img class='imgdisplay' alt='wx' height='70' src='http://icons.wxug.com/i/c/k/rain.gif' width='70'/></td>
<td><img class='imgdisplay' alt='wx' height='70' src='http://icons.wxug.com/i/c/k/partlycloudy.gif' width='70'/></td>
</tr>