B4R Question How to assign a value inline c/c++

Discussion in 'B4R Questions' started by AndroidMadhu, Jun 9, 2019.

  1. AndroidMadhu

    AndroidMadhu Member Licensed User

    Hello,
    I am sending data to cloud server by using esp8266. For sending data to cloud server I am using inline c. It is sending the data successsfully.

    Code:
    #if C
    #include <ESP8266WiFi.h>
    #include <WiFiClient.h>
    #include <ESP8266WebServer.h>
    #include <ESP8266HTTPClient.h>
    void setup(B4R::Object* o){
    const char *host = "http://mypage.com";
    }
    void read (B4R::Object* o) {
        HTTPClient http;    //Declare object of class HTTPClient
        String temperature, humidity, getData, Link;
        //String getData, Link;
        temperature="77.77";   <--- Here I hardcoded the value
        humidity="99.99";  <----Here I hardcoded the value

      //GET Data
      getData = "?temperature=" + temperature + "&humidity=" + humidity ;  //Note "?" added at front
      Link = "http://mypage.com/addTemperature.php" + getData;
      http.begin(Link);     //Specify request destination
     
      int httpCode = http.GET();            //Send the request
      String payload = http.getString();    //Get the response payload

      Serial.println(httpCode);   //Print HTTP return code
      Serial.println(payload);    //Print request response payload

      http.end();  //Close connection
    }
    #End if
    How to assign the value at the variable Temperature and humidity in inline C/C++???, I received from AsyncStream from Arduino.

    Below I am receiving data from Arduino to ESP8266 end....
    Code:
    Public Astream As AsyncStreams
    Private ser As B4RSerializator
    Private BE(20As Object

    Private Sub Arduino_Received_Data(buffer() As Byte)
    ser.ConvertBytesToArray(buffer,BE)
    Log("Humid from Ardiono :",BE(0))
    Log("Temp from Arduino :",BE(1))
    Log("Length of Buffer Array : ", buffer.Length)
    End Sub
     
  2. MathiasM

    MathiasM Member Licensed User

  3. AndroidMadhu

    AndroidMadhu Member Licensed User

    @MathiasM
    I checked your answer and will implement it asap as I feel the httpjob will more easy to implement.

    Meantime this is a different approach I followed, and I facing issue on that. Please advice how to fix the same...
    I facing the error like below
    Code:
    b4r_main.cpp:40: error: 'temperaturetosend' was not declared in this scope
       getData = "?temperature=" + temperaturetosend + "&humidity=" + humiditytosend ; 
                                   ^
    b4r_main.cpp:
    40: error: 'humiditytosend' was not declared in this scope
       getData = "?temperature=" + temperaturetosend + "&humidity=" + humiditytosend ; 
                                                                      ^
    exit status 1
     
  4. AndroidMadhu

    AndroidMadhu Member Licensed User

    I have fixed some of the issues. But only thing is float conversion is not happening...

    Code:
    b4r_main.cpp:42: error: invalid operands of types 'const char [14]' and 'float' to binary 'operator+'
       getData = "?temperature=" + temperature + "&humidity=" + humidity;
                                   ^
    Here I have declared variables at B4R
    Code:
    Public humiditytosend,temperaturetosend As Float
    Private Sub Arduino_Received_Data(buffer() As Byte)
    ser.ConvertBytesToArray(buffer,BE)
    humiditytosend=BE(
    0)
    temperaturetosend=BE(
    1)
    End Sub

    #if C
    #include <ESP8266WiFi.h>
    #include <WiFiClient.h>
    #include <ESP8266WebServer.h>
    #include <ESP8266HTTPClient.h>
    float temperature=b4r_main::_temperaturetosend;
    float humidity=b4r_main::_humiditytosend;
    Am I doing any mistake?please advice
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice