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:
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.
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:1193:33: error: template argument 1 is invalid
emitValue<output_AP>(ctx, str1);
^
I really appreciate any help.
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.
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.
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);
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…
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:
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
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.
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.
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:
#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.");
}