Announcement

Collapse
No announcement yet.

Need help with using a json request to HS4 via arduino sketch

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Need help with using a json request to HS4 via arduino sketch

    I have the following (arduinosketch, I am trying to change the value of a device based on the adc conversion to voltage. The voltage component works fine, When I make the call to the server I get a response of 200 and the HS device value remains unchanged. I realize I will eventually have to change the set value of 4 to the voltage integer, but I am trying to just get the request to work. Any help would be appreciated.


    #include "WiFi.h"
    #include "Arduino_JSON.h"
    #include "HTTPClient.h"
    const char* ssid = "xxxxxxi";
    const char* password = "xxxxxx";


    const char* serverName="http://192.168.86.49/";
    const int Analog_channel_pin= 36 ;
    int ADC_VALUE = 0;
    int voltage_value = 0;

    IPAddress ip;
    void setup() {

    Serial.begin(115200);

    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Connecting to WiFi..");
    }

    Serial.println("Connected to the WiFi network");
    ip = WiFi.localIP();
    Serial.print("ESP Board IP Address: ");
    Serial.println(ip);
    Serial.print("ESP Board MAC Address: ");
    Serial.println(WiFi.macAddress());

    }

    void loop()


    {
    ADC_VALUE = analogRead(Analog_channel_pin);
    Serial.print("ADC VALUE = ");
    Serial.println(ADC_VALUE);
    delay(1000);
    voltage_value = (ADC_VALUE * 3.3 ) / (615);
    Serial.print("Voltage = ");
    Serial.print(voltage_value);
    Serial.print("volts");

    HTTPClient http;

    // Your Domain name with URL path or IP address with path
    http.begin(serverName);

    // Specify content-type header
    http.addHeader("Content-Type", "application/json");
    // Data to send with HTTP POST


    String httpRequestData = "json?request=controldevicebyvalue&ref=2755&value=4";


    // Send HTTP POST request
    int httpResponseCode = http.POST(httpRequestData);



    Serial.print("HTTP Response code: ");
    Serial.println(httpResponseCode);


    http.end();

    delay(60000);
    }






    Thanks

    #2
    wkrasner,

    Greetings,

    When the sketch in ran, what is the exact string that gets sent?

    Thanks,

    Roger D

    Comment


      #3
      Roger,

      Thanks for replying. I was able to get it working. I was using a post , I needed to use a get. Now I am trying to figure out how to have it auto restart the sketch after a power down.

      Will

      Comment

      Working...
      X