#include #include #include String message = "Close"; String timestamp = "1413175970"; String secret = "j344rfdas"; String temp; String pakett; String payload; byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress server(192,168,2,101); IPAddress ip(192,168,1,138); int client_id = 34; uint8_t *hash; void setup() { uint8_t* hash; uint32_t a; Serial.begin(9600); while (!Serial) { } } void loop() { Serial.println("Tere"); Serial.println(message); delay(3000); create_packet(43, "Tere", "Close"); create_hmac(pakett); compile_packet(pakett, temp); Serial.println(payload); delay(2000); eth_connect(payload); delay(15000); temp =""; create_packet(343, "Kolmas","Close"); create_hmac(pakett); compile_packet(pakett,temp); eth_connect(payload); delay (2000); temp=""; } void create_packet(int id, String event, String request) { Serial.println(id); Serial.println(event); Serial.println(request); pakett = String(id) + "." + event + "." + timestamp + "." + request; // Serial.println(pakett); } void create_hmac (String hmac_data) { Sha256.initHmac((uint8_t*)"j344rfdas",9); Sha256.print(hmac_data); printHash(Sha256.resultHmac()); } void printHash(uint8_t* hash) { int i; for (i=0; i<32; i++) { // Serial.print("0123456789abcdef"[hash[i]>>4]); // Serial.print("0123456789abcdef"[hash[i]&0xf]); temp = temp + ("0123456789abcdef"[hash[i]>>4]); temp = temp + ("0123456789abcdef"[hash[i]&0xf]); } Serial.println(); Serial.println(temp); } void compile_packet(String data_in, String hmac_in) { payload = data_in + "." + hmac_in; } void eth_connect(String kirjutada) { EthernetClient client; if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); // no point in carrying on, so do nothing forevermore: // try to congifure using IP address instead of DHCP: Ethernet.begin(mac, ip); } if (client.connect(server, 8888)) { Serial.println("connected"); // Make a HTTP request: int str_leng = kirjutada.length()+1; char ch_ary[str_leng]; kirjutada.toCharArray(ch_ary, str_leng); // Serial.println(kirjutada); // Serial.println(ch_ary); client.write(ch_ary); } else { // kf you didn't get a connection to the server: Serial.println("connection failed"); } }