B4R Question Convert to string

AndroidMadhu

Active Member
Licensed User
I am sending data from arduino to Esp as below
B4X:
Private Sub Timer1_Tick
    'Dim FixedValue As String=80
    Dim humid(),temp() As Byte
    humid="33.39"
    temp="77.99"
    Astrem.Write(ser.ConvertArrayToBytes(Array(humid,temp)))
Log("Send to Esp8266 Successfully!!")
End Sub

At Esp Side Receiving the data:
B4X:
Private Sub Arduino_Received_Data(buffer() As Byte)
ser.ConvertBytesToArray(buffer,BE)
Log("Humid from Ardiono :",BE(0))  <---- I am able to see the value recd from Arduino
Log("Temp from Arduino :",BE(1))   <---- I am able to see the value recd from Arduino

But now I want to convert BE(0) and BE(1) to String.
How Do I do that?
B4X:
dim humiditytosend,temperaturetosend As byte
dim bc as byteconverter
<Next I am lost....>
 

Cableguy

Expert
Licensed User
Longtime User
BC.bytestostring(....)
 
Upvote 0

AndroidMadhu

Active Member
Licensed User
BC.bytestostring(....)
bytetostring no option is present .... .
I have used "bc.StringFromBytes", which is working as expected... But with one issue...
when I am declaring the variable humidtosend as global variable and trying to assign the value to humidtosend , then I am getting error as
B4X:
"Cannot modify Global (non-primitive) Variable
This is not true for float or int.
But when I am declare it locally within the sub it is working fine.
My confusion is if I cannot declare the variable Globally then how other sub can access the value (specifically Inline C/C++)
 
Upvote 0

AndroidMadhu

Active Member
Licensed User
This has already been I have incorporated...
B4X:
Private ser As B4RSerializator
    Private BE(20) As Object
    Dim humiditytosend(),temperaturetosend() As Byte
    Private bc As ByteConverter
Private Sub Arduino_Received_Data(buffer() As Byte)
ser.ConvertBytesToArray(buffer,BE)
Log("Humid from Ardiono :",BE(0))
Log("Temp from Arduino :",BE(1))
'bc.ArrayCopy(BE(0),humiditytosend)
GlobalStore.Put(0,BE(0))   'For Humid
Log("Humid is:",GlobalStore.Slot0)
But how to copy the GlobalStore.Slot0 to a variable?
 
Upvote 0

bdunkleysmith

Active Member
Licensed User
Longtime User
In the absence of any other information I would say:

B4X:
Dim s As String = bc.StringFromBytes(GlobalStore.Slot0)

however in all my uses of GlobalStore I've never had to copy it to a local variable.

But AndroidMadhu based on my experience of receiving GREAT assistance from this community in resolving problems, you will get the best assistance if you provide a complete "picture" of what you are trying to achieve by including all of your current code. I have followed the various posts regarding your current project with interest and even tried to help, but I'm now unsure what parts of the code you have published are still being used or what parts have been discarded to take on board suggestions of other users. Often answers will depend very much on the context and so to get help we must provide that context.

Also as someone who began using an Arduino (UNO) connected to an ESP8266 to do a data collection and send it via WiFI, the solution may be simpler by using just the ESP8266 alone (ESP8266 WiFi shield on UNO). Just food for thought . . .
 
Last edited:
Upvote 0

AndroidMadhu

Active Member
Licensed User
I need to copy the GlobalStore.Slot0 value to global variable as because, it is required to feed the value o the variables in inline C/C++ code.
Below is the inline C code for ESP to send the value [Both temp and Humid to webpage]. I need to put the value received from Arduino to Esp8266 at inline C variables [temperature and humidity ]

B4X:
#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 getData, Link ;

  //GET Data
  getData = "?temperature=" + temperature + "&humidity=" + humidity ;
  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
 
Upvote 0

bdunkleysmith

Active Member
Licensed User
Longtime User
I do not understand C and so avoid such inline code whenever I can. I assumed taking the advice of Erel and others in this post How to Send Data to webpage using NodeMCU and using the HttpJob module would avoid the need to use that inline code.

I'm getting out of my depth now and so hope someone else can help. All the best with your project . . .
 
Upvote 0

AndroidMadhu

Active Member
Licensed User
It is just from my interest.. to know in depth...
Is is possible to copy/assign "GlobalStore.Slot0" data to a variable in inline C/C++?
Like from the previous post
B4X:
#if C
String temperature, humidity;  <--- Can assign any value from GlobalStore
#End if
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…