Budík
Moderátori: psichac, Moderátori
Re: Budík
Paráda, teraz je to moderné, takéto hybridy zo stariny, už tam chýba iba to kladívko,to si mal doriešiť mechanicky a bolo by to super.
/dal by som tam vibračný motorček z mobilu a prevod na kladivko.../
/dal by som tam vibračný motorček z mobilu a prevod na kladivko.../
0
Lenivosť je matka pokroku.Lenivý človek rozmýšla,ako by si robotu uľahčil a tak niečo vynájde.
Ku každému čínskemu výrobku by mali pribaliť jedného číňana, aby som ho mohol nakopať do ....,ked sa to pokazí.
Ku každému čínskemu výrobku by mali pribaliť jedného číňana, aby som ho mohol nakopať do ....,ked sa to pokazí.
- KaRaQ94
- Zaslúžilý člen
- Príspevky: 1071
- Dátum registrácie: 14 Feb 2010, 00:00
- Bydlisko: Bratislava
- Vek: 29
Re: Budík
žeby niečo takéto ?? https://www.ebay.com/itm/4-Bits-Digital ... SwMxJb8VaV
a ako "pozadie" by som použil plošák z grafickej alebo z televízora, proste čo má "nahusto" súčiastky aby to dobre vyzeralo, presne tak ako to chalanisko spravil
a ako "pozadie" by som použil plošák z grafickej alebo z televízora, proste čo má "nahusto" súčiastky aby to dobre vyzeralo, presne tak ako to chalanisko spravil
0
Lepšie je byť aktívny ako rádioaktívny.
V silnoprúde sa chyba toleruje iba raz...
http://lmgtfy.com/
Inak volám sa Tomáš ...
V silnoprúde sa chyba toleruje iba raz...
http://lmgtfy.com/
Inak volám sa Tomáš ...
-
- Ultimate člen
- Príspevky: 6236
- Dátum registrácie: 20 Júl 2007, 00:00
- Vek: 41
-
- Ultimate člen
- Príspevky: 6236
- Dátum registrácie: 20 Júl 2007, 00:00
- Vek: 41
Re: Budík
mozem, ale je narychlo zbuchany a priznavam, ze nic noc kvalita. V principe sa pripojim na wifi, a vysle na ntp udp dotaz, spracuje odpoved - zosynchronizuje cas na arduine. a to robi raz za niekolko hodin.
+ mam tam vychytavky, ako jednoducha stranka s configom, ak sa nepodari pripojit na wifi, tak sa prepne na AP a caka na nastavenie a ciastocne prepojenie s mojim inteligentnym systemom. A teraz pozeram, ze tam mam aj ak najde wifi bez hesla, tak sa tam pripoji
na ovladanie displeja pouzivam kniznicu TM1637Display (inspiracia aj na tento stranke
+ mam tam vychytavky, ako jednoducha stranka s configom, ak sa nepodari pripojit na wifi, tak sa prepne na AP a caka na nastavenie a ciastocne prepojenie s mojim inteligentnym systemom. A teraz pozeram, ze tam mam aj ak najde wifi bez hesla, tak sa tam pripoji
na ovladanie displeja pouzivam kniznicu TM1637Display (inspiracia aj na tento stranke
Kód: Vybrať všetko
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <TM1637Display.h>
#include <Ticker.h>
#include <TimeLib.h>
#include <ESP8266WebServer.h>
#include <EEPROM.h>
const int NTP_PACKET_SIZE = 64;
const uint8_t INIT[] = { SEG_A, SEG_A, SEG_A , SEG_A };
const uint8_t DONE[] = { SEG_D, SEG_D, SEG_D , SEG_D };
const uint8_t SCAN[] = { SEG_G, SEG_G, SEG_G , SEG_G };
const uint8_t SCAN2[] = { SEG_A | SEG_B | SEG_F, SEG_A | SEG_B | SEG_F, SEG_A | SEG_B | SEG_F, SEG_A | SEG_B | SEG_F };
const uint8_t DONE2[] = { SEG_C | SEG_D | SEG_E, SEG_C | SEG_D | SEG_E, SEG_C | SEG_D | SEG_E, SEG_C | SEG_D | SEG_E };
const uint8_t AP[] = { SEG_G, SEG_A | SEG_B | SEG_C | SEG_E | SEG_F | SEG_G, SEG_A | SEG_B | SEG_E | SEG_F | SEG_G, SEG_G };
char hname[]="wificlock";
struct eConfig {
char validConf[1];
char ntpServer[50];
char ssid[20];
char pass[20];
char ssid2[20];
char rpass[20];
int timeZone;
bool dayLight;
int brightness;
int timeout;
int syncInt;
};
eConfig Config;
WiFiUDP udp;
time_t lastSync=0;
String es="";
bool isAP;
bool sync=false;
int cnt=0;
String webPage="";
String webPageSave="";
TM1637Display disp(2, 0);
ESP8266WebServer server(80);
String AddLeadZero(int inp) {
return ((inp<10)?"0":"")+(String)inp;
}
String formatDT(time_t dt) {
return AddLeadZero(day(dt))+"."+AddLeadZero(month(dt))+"."+AddLeadZero(year(dt))+" "+AddLeadZero(hour(dt))+":"+AddLeadZero(minute(dt))+":"+AddLeadZero(second(dt));
}
void EEPROMdata(int act) {
if (act==0) { //read from eeprom
EEPROM.begin(512);
EEPROM.get(0,Config);
if (!Config.validConf=='X') {
strcpy(Config.ntpServer,"0.europe.pool.ntp.org");
strcpy(Config.ssid,"");
strcpy(Config.pass,"");
strcpy(Config.rpass,"");
Config.timeZone=1;
Config.dayLight=0;
Config.brightness=15;
Config.timeout=15;
Config.syncInt=6;
EEPROMdata(1);
}
} else if (act==1) { //save to eeprom
EEPROM.begin(512);
Config.validConf[0]='X';
EEPROM.put(0,Config);
EEPROM.commit();
delay(100);
}
}
unsigned long sendNTPpacket()
{
byte data[NTP_PACKET_SIZE];
IPAddress ntpServerIP;
data[0] = 0b11100011; // LI, Version, Mode
data[1] = 0; // Stratum, or type of clock
data[2] = 6; // Polling Interval
data[3] = 0xEC; // Peer Clock Precision
data[12] = 49;
data[13] = 0x4E;
data[14] = 49;
data[15] = 52;
WiFi.hostByName(Config.ntpServer, ntpServerIP);
udp.beginPacket(ntpServerIP, 123); //NTP requests are to port 123
udp.write(data,NTP_PACKET_SIZE);
udp.endPacket();
delay(100);
}
bool connectWifi(char apname[20],char appass[20],int tm) {
int cnt=0;
WiFi.mode(WIFI_STA);
WiFi.begin(apname, appass);
while ((WiFi.status() != WL_CONNECTED)and(cnt<(10*tm))) { delay(100); cnt++; }
return WiFi.status() == WL_CONNECTED;
}
bool wifiConnect(bool apmode) {
bool ret=false;
if (apmode==false) {
disp.setSegments(SCAN);
ret=connectWifi(Config.ssid, Config.pass,Config.timeout);
if (ret==false) {
delay(50);
disp.setSegments(SCAN2);
int n = WiFi.scanNetworks();
int i=0;
while (i<n) {
if (WiFi.encryptionType(i) == ENC_TYPE_NONE) {
char ssidcha[20];
char passcha[20];
WiFi.SSID(i).toCharArray(ssidcha,WiFi.SSID(i).length()+1);
ret=connectWifi(ssidcha,passcha,Config.timeout);
if (ret==true) { break;}
}
i++;
}
disp.setSegments(DONE2);
} else { disp.setSegments(DONE); }
}
if ((ret==false || apmode==true)) {
disp.setSegments(AP);
WiFi.softAP(hname,Config.rpass);
ret=true;
} else {
udp.begin(2048);
sync=false;
ret=false;
}
return ret;
delay(100);
}
void setup() {
isAP=true;
Serial.begin(9600);
EEPROMdata(0);
disp.setBrightness(Config.brightness);
disp.setSegments(INIT);
MDNS.begin(hname);
MDNS.addService("http", "tcp", 80);
isAP=wifiConnect(!Config.validConf=='X');
delay(1000); //lebo inak to nejde
server.on("/", [](){
webPage ="<!DOCTYPE html><html><head><meta charset='utf-8' /><title>Wifi Clock ver. 1.0</title>";
webPage+="<style>table { border: 0px solid black;} th,td { border: 0px; padding: 0px;} th {text-align: right; } .title {text-align: left; color: green; padding: 15px;} input {border: 1px solid black; width: 200px;} .err {color: red; }</style>";
webPage+="<script> var items = ['ct',1,60,'si',1,24,'br',8,16,'tz',-12,12]; function validate() {var res=true; var inputs = document.getElementsByTagName('input'); for (i=0;i<inputs.length;++i) {var p=items.indexOf(inputs[i].name); if (p>-1) { var e=document.getElementById(inputs[i].name+'v'); e.innerHTML=''; var v=parseInt(inputs[i].value); if (!((v>=items[p+1])&&(v<=items[p+2]))) { res=false; e.innerHTML='Only number from interval '+items[p+1].toString()+'..'+items[p+2].toString();} } } return res;}</script>";
webPage+="</head><body><form action='/save' method='POST' onsubmit='return validate();'><table><tr><th colspan='3' class='title'>Wifi Client settings</th></tr>";
webPage+="<tr><th>SSID: </th><td><input type='text' name='cssid' value='"+(String)Config.ssid+"' maxlength='20'></td></tr>";
webPage+="<tr><th>Password: </th><td><input type='password' name='cpass' value='"+(String)Config.pass+"' maxlength='20'></td></tr>";
webPage+="<tr><th>Password recovery: </th><td><input type='password' name='rpass' value='"+(String)Config.rpass+"' maxlength='20'></td></tr>";
webPage+="<tr><th colspan='3' class='title'>General settings</th></tr>";
webPage+="<tr><th>NTP server:</th><td><input type='text' name='ntp' value='"+(String)Config.ntpServer+"' maxlength='50'></td></tr>";
webPage+="<tr><th>Connect timeout [second]: </th><td><input type='text' name='ct' value='"+(String)Config.timeout+"' maxlength='3'></td><td class='err' id='ctv'></td></tr>";
webPage+="<tr><th>Sync interval [hour]: </th><td><input type='text' name='si' value='"+(String)Config.syncInt+"' maxlength='3'></td><td class='err' id='siv'></td></tr>";
webPage+="<tr><th>TimeZone: </th><td><input type='text' name='tz' value='"+(String)Config.timeZone+"' maxlength='3'></td><td class='err' id='tzv'></td></tr>";
webPage+="<tr><th>DayLight: </th><td><input type='checkbox' name='dl' value='1' "+(String)(Config.dayLight==1?"checked='checked'":"")+"></td></tr>";
webPage+="<tr><th>Brightness [1..15]: </th><td><input type='text' name='br' value='"+(String)Config.brightness+"' maxlength='3'></td></tr>";
webPage+="<tr><th>Last sync: </th><td>"+formatDT(lastSync)+"</td></tr>";
webPage+="<tr><td></td><td><br><input type='submit' name='go' value='Save'></td></tr>";
webPage+="</table></form></body></html>";
server.send(200, "text/html", webPage);
delay(100);
});
server.on("/save", [](){
webPageSave = "<!DOCTYPE html><html><head><meta charset='utf-8' /><meta http-equiv='refresh' content='4; url=/'></head><body><h1>Saved... redirecting</h1></body></html>";
server.send(200, "text/html", webPageSave);
Config.dayLight=0;
for (int i=0; i<server.args(); i++) {
if (server.argName(i)=="cssid") { server.arg(i).toCharArray(Config.ssid,server.arg(i).length()+1); }
else if (server.argName(i)=="cpass") { server.arg(i).toCharArray(Config.pass,server.arg(i).length()+1); }
else if (server.argName(i)=="rpass") { server.arg(i).toCharArray(Config.rpass,server.arg(i).length()+1); }
else if (server.argName(i)=="ntp") { server.arg(i).toCharArray(Config.ntpServer,server.arg(i).length()+1); }
else if (server.argName(i)=="ct") { Config.timeout=server.arg(i).toInt(); }
else if (server.argName(i)=="si") { Config.syncInt=server.arg(i).toInt(); }
else if (server.argName(i)=="tz") { Config.timeZone=server.arg(i).toInt(); }
else if (server.argName(i)=="dl") { Config.dayLight=server.arg(i).toInt(); }
else if (server.argName(i)=="br") { Config.brightness=server.arg(i).toInt(); }
delay(100);
}
EEPROMdata(1);
disp.setBrightness(0);
delay(100);
ESP.restart();
});
server.begin();
delay(100);
}
void loop() {
server.handleClient();
int noBytes = udp.parsePacket();
if (noBytes>0) {
byte data[NTP_PACKET_SIZE];
time_t datetime;
unsigned long secsSince1900;
udp.read(data,noBytes);
secsSince1900 = (unsigned long)data[40] << 24;
secsSince1900 |= (unsigned long)data[41] << 16;
secsSince1900 |= (unsigned long)data[42] << 8;
secsSince1900 |= (unsigned long)data[43];
datetime=secsSince1900 - 2208988800UL + ((Config.timeZone+Config.dayLight) * SECS_PER_HOUR);
setTime(hour(datetime),minute(datetime),second(datetime),day(datetime),month(datetime),year(datetime));
lastSync=now();
sync=true;
}
if (isAP==false) {
if ((lastSync+(3600*Config.syncInt)<(now()))||sync==false) {
sendNTPpacket();
}
if (sync==true) {
disp.setSegments( new byte[4] {disp.encodeDigit(hour()/10),disp.encodeDigit(hour()%10)+(second()%2==0?(WiFi.status()==WL_CONNECTED?128:0):0),disp.encodeDigit(minute()/10),disp.encodeDigit(minute()%10) } );
}
}
delay(500);
}
0
Jedním z největších projevů nedůvěry v Boha je hromosvod na kostele.
-
- Ultimate člen
- Príspevky: 6236
- Dátum registrácie: 20 Júl 2007, 00:00
- Vek: 41