Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Ethernet.h>
- #include "DHT.h"
- #define DHTPIN1 8
- #define DHTTYPE1 DHT22
- DHT dht1(DHTPIN1, DHTTYPE1);
- float humidity1, temperature1;
- byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
- char server[] = "www.etfos.unios.hr";
- //IPAddress ip(192,168,0,177);
- EthernetClient client;
- int networkCall(){
- if (client.connect(server, 80)) {
- String data="url=https://<page>";
- Serial.println("connected");
- client.println("POST /~<name>/my.php HTTP/1.1");
- client.println("Host: www.etfos.unios.hr");
- client.println("User-Agent: Arduino/1.0");
- client.println("Connection: close");
- client.println("Content-Type: application/x-www-form-urlencoded");
- client.print("Content-Length: ");
- client.println(data.length());
- client.println();
- client.println(data);
- client.println();
- delay(1000);
- //nakon ovog moras imati json
- char char_array[500], result[500];
- int i = 0;
- while (client.available()) {
- char c = client.read();
- char_array[i] = c;
- i++;
- }
- char_array[i] = '\0';
- String str(char_array);
- Serial.println(str);
- // if the server's disconnected, stop the client:
- if (!client.connected()) {
- Serial.println();
- Serial.println("disconnecting.");
- client.stop();
- }
- }
- else{
- Serial.println("connection failed");
- }
- }
- void setup() {
- Serial.begin(9600);
- Serial.println("connecting...");
- 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);
- }
- dht1.begin();
- }
- void loop() {
- // put your main code here, to run repeatedly:
- Serial.println("Network call");
- networkCall();
- Serial.println("Network call end");
- temperature1 = dht1.readTemperature();
- humidity1 = dht1.readHumidity();
- Serial.print("Temperature: ");
- Serial.println(temperature1);
- Serial.print("Humidity: ");
- Serial.println(humidity1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement