B4R Question Question about ESP8266 Wifi.hostname

daveinhull

Active Member
Licensed User
Longtime User
Hi and sorry to raise an old quesiton again, but was advised to raise a new question.

I've seen an old thread about setting the hostname of an ESP8266 and Erel posted some code to asnwer to OP.

B4X:
Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    Dim bb() As Byte = "abc"
    RunNative("SetHostName", bb)
End Sub

#if C
  void SetHostName(B4R::Object* o) {
   B4R::Array* b = (B4R::Array*)B4R::Object::toPointer(o);
   char* c = (char*)b->data;
   WiFi.hostname(c);
  }
#end if

I've done this, but I keep getting an error saying 'wifi' was not declared in this scope.
It's probably something very silly I've done, but could someone advise.

Many thanks
Dave
 

RJB

Active Member
Licensed User
Longtime User
Hi,
try:

B4X:
#if C

#include <ESP8266WiFi.h>

void SetHostName(..........

or

#if C

#ifdef ESP32
#include <WiFi.h>
#endif
#ifndef ESP32
#include <ESP8266WiFi.h>
#endif

void SetHostName(..........
 
Upvote 0

daveinhull

Active Member
Licensed User
Longtime User
Hi RJB,

Thanks for your quick reply and suggestion. Just after posting, I thought to try that, but it still comes back with the same error.

Any other thoughts?

Thanks
Dave
 
Upvote 0

RJB

Active Member
Licensed User
Longtime User
Is your code as written above? i.e. WiFi.hostname not wifi.hostname?
If so then perhaps worth a quick try using: wifi instead of WiFi?
 
Upvote 0

daveinhull

Active Member
Licensed User
Longtime User
Hi RJB,

The code example was just copied from the old thread, I'm actually using wifi.hostname, but thanks for the thought.

I'm just not sure what I'm don't wrong as the code example was from Erel and the original OP replied saying that it was working.

Thoughts anyone?

Thanks
Dave
 
Upvote 0

daveinhull

Active Member
Licensed User
Longtime User
Hi RJb,

You got it, but in reverse :D, thanks.
I actually had wifi.hostname, but it should have been as in the example WiFi.hostname.
šŸ‘
Dave
 
Upvote 0

RJB

Active Member
Licensed User
Longtime User
Yes, that's actually what I found but wasn't sure as you had WiFi in the question.
Always worth trying the casing anyway - I often find it's wrong when I copy code from on-line sources!!
 
Upvote 0

daveinhull

Active Member
Licensed User
Longtime User
Hi,

So I've just got my first chance at testing the SetHostName and it crashes, the ESP just reboots over and over again.
I haven't added the crash text, but can do, but first I just wanted to ask if anyone had got the SetHostName working as per Erel's original code snippet?

Thanks in advance for any help, suggestions, guidance etc.
Dave
 
Upvote 0
Top