# Creating a node to activate the web server in NodeMCU 8266

**URL:** <https://forum.xod.io/t/creating-a-node-to-activate-the-web-server-in-nodemcu-8266/3702>\
**Category:** XOD Programming Questions\
**Created:** [March 30, 2020, 2:18pm UTC](https://forum.xod.io/t/creating-a-node-to-activate-the-web-server-in-nodemcu-8266/3702 "2020-03-30T14:18:22Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahmadsuki](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/ahmadsuki/32/2212_2.png) [@ahmadsuki](https://forum.xod.io/u/ahmadsuki)\
**Post date:** [March 30, 2020, 2:18pm UTC](https://forum.xod.io/t/creating-a-node-to-activate-the-web-server-in-nodemcu-8266/3702/1 "2020-03-30T14:18:22Z")

</div>

I’m in a learning process to create a node for the above purpose. In case anyone can help us to create a node that can handle a way to activate the web server in the board, it will be very great, we can manipulate our sensors through web service (browser). I’m thinking of converting/modifying the following C++ code to become a XOD node:

![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/b/b426de344258817a26df1dd987c7ac0e875ba966.png)

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/0/07ed35c8b3ab5edacb10aa3545fce7c113dbd66d.png)

My skill is not strong enough to do this. I really appreaciate any help.

---

<div class="post-metadata">

**Author:** ![ahmadsuki](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/ahmadsuki/32/2212_2.png) [@ahmadsuki](https://forum.xod.io/u/ahmadsuki)\
**Post date:** [March 31, 2020, 9:15am UTC](https://forum.xod.io/t/creating-a-node-to-activate-the-web-server-in-nodemcu-8266/3702/2 "2020-03-31T09:15:10Z")

</div>

I was trying to write something based on another example… it is not working yet… in case someone can help me to understand it better…

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/e/ef9a14cac9211bfe51388fc70ad17426d524cd6d.png)

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [March 31, 2020, 6:52pm UTC](https://forum.xod.io/t/creating-a-node-to-activate-the-web-server-in-nodemcu-8266/3702/3 "2020-03-31T18:52:57Z")

</div>

To make it more reusable, you probably want to make the SSID & password input pins rather than hard-coding them. Same for IP info (but those are future fixes when debug is done).

Some possible reasons for failure:

- If you didn’t delete SSID & password to post your code, it probably can’t connect to wifi…
- That is not standard way to represent IP/gateway/subnet (but could be correct for this code). If it is correct for this code, it might making passing info by input pin more difficult…
- Gateway & local\_ip can’t be the same. Local\_ip needs to be an IP that is not already in use on your network.

Generally the code looks OK, but I don’t use these specific calls, so I can’t verify that they are indeed correct.

---

<div class="post-metadata">

**Author:** ![ahmadsuki](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/ahmadsuki/32/2212_2.png) [@ahmadsuki](https://forum.xod.io/u/ahmadsuki)\
**Post date:** [April 1, 2020, 2:52am UTC](https://forum.xod.io/t/creating-a-node-to-activate-the-web-server-in-nodemcu-8266/3702/5 "2020-04-01T02:52:41Z")

</div>

For now I just want to make the device can perform as an AP webserver.

I’m not sure your first point of deleting SSID & password, since my intention is just to activate the AP mode (standalone WiFi mode).

I changed as follow, but the errors are still there:

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/b/bad56ea70845c4e9d816cc7f06d9732e941ea22e.png)

![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/3/381ed4523bfed175fc3b75b1c7b24f21255b4dd3.png)

The compiler indicate the error/bugs are at line 36 & 43:

C:\Users\uum\AppData\Local\Temp\xod\_temp\_sketchbookifGV7o\xod\_1585707516962\_sketch\xod\_1585707516962\_sketch.ino:1193:13: error: ‘output\_AP’ was not declared in this scope  
emitValue\<output\_AP\>(ctx, str1);

C:\Users\uum\AppData\Local\Temp\xod\_temp\_sketchbookifGV7o\xod\_1585707516962\_sketch\xod\_1585707516962\_sketch.ino:1193:33: error: no matching function for call to ‘emitValue(xod::\_\_\_\_webserver\_apwifi2::ContextObject\*&, const char\*&)’ emitValue\<output\_AP\>(ctx, str1);

C:\Users\uum\AppData\Local\Temp\xod\_temp\_sketchbookifGV7o\xod\_1585707516962\_sketch\xod\_1585707516962\_sketch.ino:1137:33: note: template argument deduction/substitution failed:

C:\Users\uum\AppData\Local\Temp\xod\_temp\_sketchbookifGV7o\xod\_1585707516962\_sketch\xod\_1585707516962\_sketch.ino:1193:33: error: template argument 1 is invalid  
emitValue\<output\_AP\>(ctx, str1);  
^  
I really appreciate any help.

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [April 1, 2020, 1:06pm UTC](https://forum.xod.io/t/creating-a-node-to-activate-the-web-server-in-nodemcu-8266/3702/6 "2020-04-01T13:06:52Z")

</div>

> [@ahmadsuki](#):
>
> error: ‘output\_AP’ was not declared in this scope  
> emitValue\<output\_AP\>(ctx, str1)

Is because you have `emitValue<output_AP>(ctx, str1);`, but you don’t have an output pin named AP. One of the output pins below not-implemented-in-xod node needs to be named “AP”

The other errors may just be a result of this error confusing the compiler.

---

<div class="post-metadata">

**Author:** ![ahmadsuki](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/ahmadsuki/32/2212_2.png) [@ahmadsuki](https://forum.xod.io/u/ahmadsuki)\
**Post date:** [April 1, 2020, 4:13pm UTC](https://forum.xod.io/t/creating-a-node-to-activate-the-web-server-in-nodemcu-8266/3702/7 "2020-04-01T16:13:45Z")

</div>

It seems the compiler also pointed the error to the string handling. Second parameter of the emitValue is not matching with Lines 31 & 36. It indicates something like char\*. I tried change to XString, it does not help.

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [April 1, 2020, 10:47pm UTC](https://forum.xod.io/t/creating-a-node-to-activate-the-web-server-in-nodemcu-8266/3702/8 "2020-04-01T22:47:40Z")

</div>

I don’t know if XOD looks at future use for auto declaration. You may need to specify variable type when storing output data instead of using auto.

---

<div class="post-metadata">

**Author:** ![ahmadsuki](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/ahmadsuki/32/2212_2.png) [@ahmadsuki](https://forum.xod.io/u/ahmadsuki)\
**Post date:** [April 2, 2020, 4:00pm UTC](https://forum.xod.io/t/creating-a-node-to-activate-the-web-server-in-nodemcu-8266/3702/9 "2020-04-02T16:00:50Z")

</div>

Pls guide me further:

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/c/c9a6179fdfc97fb6a6c0f614b2d6f5d047d28020.png)

The error is at line 32 method/function length is seems requires another datatype:  
error: no matching function for call to ‘length(char\*&)’  
Number myIPLength = length(myIP);

C:\Users\uum\AppData\Local\Temp\xod\_temp\_sketchbookENPAFN\xod\_1585842887744\_sketch\xod\_1585842887744\_sketch.ino:585:29: note: template size\_t xod::length(xod::List)  
template size\_t length(List xs) {  
^  
C:\Users\uum\AppData\Local\Temp\xod\_temp\_sketchbookENPAFN\xod\_1585842887744\_sketch\xod\_1585842887744\_sketch.ino:585:29: note: template argument deduction/substitution failed:

C:\Users\uum\AppData\Local\Temp\xod\_temp\_sketchbookENPAFN\xod\_1585842887744\_sketch\xod\_1585842887744\_sketch.ino:1170:34: note: mismatched types ‘xod::List’ and ‘char\*’  
Number myIPLength = length(myIP);

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [April 2, 2020, 4:11pm UTC](https://forum.xod.io/t/creating-a-node-to-activate-the-web-server-in-nodemcu-8266/3702/10 "2020-04-02T16:11:33Z")

</div>

Sorry…I’m weak on handling of strings in C++ myself. All I can tell you is the 1st error is complaining that there is no length() function that knows how to find length from a pointer to a character. You can probably use “int” instead of “Number” for myIPLength. Not sure how to help you beyond that…

---

<div class="post-metadata">

**Author:** ![petert](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/petert/32/2096_2.png) [@petert](https://forum.xod.io/u/petert)\
**Post date:** [April 2, 2020, 8:27pm UTC](https://forum.xod.io/t/creating-a-node-to-activate-the-web-server-in-nodemcu-8266/3702/11 "2020-04-02T20:27:31Z")

</div>

Ask Mitch to help, he’s C++ and a XOD newbie too

---

<div class="post-metadata">

**Author:** ![ahmadsuki](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/ahmadsuki/32/2212_2.png) [@ahmadsuki](https://forum.xod.io/u/ahmadsuki)\
**Post date:** [April 3, 2020, 1:08am UTC](https://forum.xod.io/t/creating-a-node-to-activate-the-web-server-in-nodemcu-8266/3702/12 "2020-04-03T01:08:16Z")

</div>

My only problem now is how to convert traditional C++ string to XOD XString (or List\<char\>) thus emitValue can accept my string to be displayed. I’ve tried many ways but yet to get any solution:

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/0/09e95e42bbd195c9ae5fccd7c655111cc378ba18.png)

The only error is at line 30:  
_error: conversion from ‘String’ to non-scalar type ‘xod::XString {aka xod::List}’ requested_  
XString myIP = WiFi.softAPIP().toString(); //Get IP address

pls help.

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [April 3, 2020, 1:17am UTC](https://forum.xod.io/t/creating-a-node-to-activate-the-web-server-in-nodemcu-8266/3702/13 "2020-04-03T01:17:38Z")

</div>

Probably the best help is to look at existing nodes to see how they deal with it. format-number is a node that stores an array of char and emits a string. My guess would be WiFi…toString is returning an array of char (or a pointer to char, which might need copied to your array of char). Like I said…strings in C++ are not my strong point.

---

<div class="post-metadata">

**Author:** ![ahmadsuki](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/ahmadsuki/32/2212_2.png) [@ahmadsuki](https://forum.xod.io/u/ahmadsuki)\
**Post date:** [April 3, 2020, 3:51am UTC](https://forum.xod.io/t/creating-a-node-to-activate-the-web-server-in-nodemcu-8266/3702/14 "2020-04-03T03:51:15Z")

</div>

I “resolved” the problem of string conversion by outputting/emitValue as an IPAddress datatype (and link it to output-ip-address node) [Lines 47 & 48]. However the IP address is not displayed yet, the bug has gone for the time being.

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/5/54dc3d3a5891482131527e1c8f8c8be1fbcb1e62.png)

![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/c/cc039463dd5dfa61b239f950344a129c266a4deb.png)

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/e/e8e4634bb0482c965a0bed638a4b1cf3f5632d13.png)

---

<div class="post-metadata">

**Author:** ![ahmadsuki](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/ahmadsuki/32/2212_2.png) [@ahmadsuki](https://forum.xod.io/u/ahmadsuki)\
**Post date:** [April 4, 2020, 4:39pm UTC](https://forum.xod.io/t/creating-a-node-to-activate-the-web-server-in-nodemcu-8266/3702/15 "2020-04-04T16:39:05Z")

</div>

Now, I’m trying to create a node to activate the webserver in nodemcu 8266 with Wifi mode. I will use connect node from _xod-dev/esp8266-mcu/connect_. The following code is the ref C++ I intend to use:

```auto
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

ESP8266WebServer server(80);

const char* ssid = "WiFi_SSID"; //Enter Wi-Fi SSID
const char* password = "WiFi_Password"; //Enter Wi-Fi Password
 
void setup() {
  Serial.begin(115200); //Begin Serial at 115200 Baud
  WiFi.begin(ssid, password); //Connect to the WiFi network
  
  while (WiFi.status() != WL_CONNECTED) { //Wait for connection
      delay(500);
      Serial.println("Waiting to connect...");
  }
  
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP()); //Print the local IP
  
  server.on("/", handle_index); //Handle Index page
  
  server.begin(); //Start the server
  Serial.println("Server listening");
}

void loop() {
  server.handleClient(); //Handling of incoming client requests
}

void handle_index() {
  //Print Hello at opening homepage
  server.send(200, "text/plain", "Hello! This is an index page.");
}

```

I plan to do something like this:

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/c/c29c21b10330faf9266cfa0da2103a24dc2e0f01.png)

and this is my converted code:

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/a/af413effe0d3a7f1a7f43f34549680f0ea552a7e.png)

My C++ nodes will look like this:  
 ![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/5/5662a109397ccdc9c7345a8555db2e08d3bd011e.png)

a) Currently the serial println is not displayed :

```auto
void evaluate(Context ctx) {
  Serial.println("Entering webserver node... ");  

```

b) What is the correct way to implement the following c++ arduino ide & webserver function/method in XOD:

```auto
void loop() {
  server.handleClient(); //Handling of incoming client requests
}

```

This is due to this loop is meant for c++ arduino ide implementation.

Any suggestion?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/1X/eb7348baa04192c2ef932d1db54d44f09f8a7888.png) [@system](https://forum.xod.io/u/system)\
**Post date:** [May 4, 2020, 4:39pm UTC](https://forum.xod.io/t/creating-a-node-to-activate-the-web-server-in-nodemcu-8266/3702/16 "2020-05-04T16:39:11Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
