Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Ethernet.h>
- //Network setup, you should adapt this of course
- byte mac[] = {
- 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF};
- byte ip[] = {
- 89,106,215,66};
- byte gateway[] = {
- 89,106,215,95};
- byte subnet[] = {
- 255,255,255,0 };
- byte server[] = {
- 62,58,108,215};
- // initialize the library instance:
- Client client(server, 30223);
- //clock and tik JSON strings - change name, longitude, latitude, elevation to your data
- String clock =
- String("{\"idClock\":1,\"name\":\"ESC\",\"longitude\":47.3,\"latitude\":15.26,\"elevation\":347.0}");
- String tik = String("{}"); // NO MORE CLOCK ID'S !!!
- //TIK test value
- int tikReady = 1;
- void setup()
- {
- pinMode(8,INPUT);
- pinMode(13,OUTPUT);
- //boot serial and Ethernet, serial is just to debug
- Serial.begin(9600);
- Ethernet.begin(mac, ip, gateway, subnet); //watch out for these settings!
- delay(1000); // give ethernet shield time to boot
- //make the connection
- client.connect();
- if(client.connected())
- {
- Serial.println("connected!");
- client.print(clock); //first connection sends clockId to register with
- }
- randomSeed(analogRead(6));
- }
- int c;
- boolean input, state;
- void loop()
- {
- if(client.connected())
- {
- input = digitalRead(8);
- if (input != state){
- c++;
- Serial.print(c);
- Serial.println(": TIK");
- client.print(tik);
- }
- state = input;
- }
- //wait 5 seconds and reconnect
- else
- {
- Serial.println("no connection");
- delay(5000);
- client.connect();
- client.print(clock);
- }
- //delay(500);
- }
Add Comment
Please, Sign In to add comment