TXT and CivetWeb

Alles rund um TX(T) und RoboPro, mit ft-Hard- und Software
Computing using original ft hard- and software
Forumsregeln
Bitte beachte die Forumsregeln!
Antworten
vleeuwen
Beiträge: 1560
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

TXT and CivetWeb

Beitrag von vleeuwen » 19 Dez 2019, 13:02

On the TXT is since firmware 4.4.3 a CivetWeb web server part of the firmware and present.
Nice challenge for users of the fischertechnik TXT firmware.

The last couple of weeks I have study the CivetWeb carefully and perform also a lot of tests.
It’s a nice thing that can offers a lot of feature :
CGI, Websocket, server site scripting with LUA or ECMA-script (Jscript), SQLite3.
I works as well as standalone server or as embedded part in an TXT-application.
It was not too difficult to add the source into Eclipse C/C++ TXT projects. So I am able now to compile suitable versions for my own need or develop SLI’s or standalone applications in combination with direct TA access and for example Websocket(direct, SOAP, or REST) or CGI based communication.
The actual Civetweb version on the TXT support only CGI but this version can easy be replace by a version with additional functionality.
The CGI can be create with C/C++ or Python. So the CGI can also be used in combination with FtRoboPy.
The optional SQLite engine is offering some data base functionality which could be useful to store data.

Recompiling the CivetWeb source is with Eclipse is not so difficult, you don't need to study all the code for this. The only difficulty is to fit in the CivetWeb sources in to Eclipse projects.
Although the actual document-root is under root-permissions, it is possible to change the location and work with ROBOPro-permissions only. The Civetweb can also run from the Program-C map.
Eclipse is also the cross compiler program development environment for the fischertechnik SLI’s and off-line application
For my experiments I have also a version of CivetWeb running on Windows (MS-Visual Studio 2017/2019).
The CivetWeb with Websocket is offering a lot of possibilities for controlling a TXT-application over the internet. Less overhead then with MQTT (Mosquitto MQTT) so it can be faster.
TXT application developers who are interested, are welcome to contact me privately about this subject «TXT and Civetweb».

vleeuwen
Beiträge: 1560
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: TXT and CivetWeb

Beitrag von vleeuwen » 27 Dez 2019, 08:25

Yesterday I made some progress with the use of the civetweb embedded server.

I created a set of Eclipse projects for the embedded Civetweb and recompiled it.
The creation of the Eclipse project was needed to integrate the Civetweb software into the structure that is used in the fischertechnik GitHub pages.

I also create two fischertechnik related projects, one is a TXT download program and an other as TXT SLI.
In both case the websocket can be use as interface for a TXT application
a) The TXT civetweb program can also be run from the map /opt/Knobloch/C-program under the ROBOPro account.(with the TXT webinterface)
b) The SLI works as extension for RoboPro, so a local RoboPro program can work with a web interfaceas as controller.
c) I put the document root and websocket root is the map /opt/Knobloch/Data. (with the TXT webinterface)
My embedded civetweb is using a different port then the already existing civetweb server on the TXT.
So I don't need to update, modify or replace the original civetweb with the root account.

Conclusion:
The POC (proof of concept) is working fine.
To create application with this structure the next skills are needed or need to be develop:
General knowledge about sequential programming and reading and finding documentation and example on the internet,
Basic C/C++, (see also W3School)
HTML 5, (see also W3School)
Jscript, (looks like a little bit on C/C++) (see also W3School)
Basic knowledge of HTTP (websockets, AJAX, client-server communication)

With elementary knowledge, the example could be helpful to guide you through the learning process and to develop these skills.

vleeuwen
Beiträge: 1560
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: TXT and CivetWeb

Beitrag von vleeuwen » 07 Jan 2020, 16:57

The embedded part of the CivetWeb can be integrated in a SLI RoboPro extension and start/stop with RoboPro elements.
Civetweb is offering WebSocket, CGI access to the IOMotor of the TXT.
It also let the TXT act as normal Webserver with server side LUA, ECMAScript programming,
My POC ( proof of concept) is working now.

vleeuwen
Beiträge: 1560
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: TXT and CivetWeb

Beitrag von vleeuwen » 10 Jan 2020, 10:58

Example code of a RoboPro SLI for sending data to the web socket client:
(Eclipse C/C++ dialect level 11

Code: Alles auswählen

/**
 * POC (proof of concept)
 * RoboPro SLI element for sending (push) information about the joysticks and 2 motors
 * over a web socket to the connected clients.
 * This example is Json based, however for more speed binary is also possible.
 * This SLI is using the embedded c++ version of CivetWeb. 
 * For the POC: because the focus in this example is about the use of the web socket, 
 * so reading the actual value from the TA has been left out,
 * instead it is using dummy values.
 * @return Error = -1, otherwise the number of byte which has been sent
 * [url=https://github.com/fischertechnik/txt_demo_ROBOPro_SLI]for SLI basics [/url]
 */
 int setSendShort(short v) {
	int res = -1;
	int joyStickLeftRL = 0, joyStickLeftUD = 0, joystickID = 1; /* 1== off, off*/
	Json::Value root, joystick, motor1, motor2, input, counter;
	char const *c = "error";	//NULL;
	Json::StreamWriterBuilder builder;
	try {  //creating the JSON string structure
		joyStickLeftRL = 0;
		joyStickLeftUD = 0;
		motor1["id"] = 1;
		motor1["power1"] = 256;
		motor1["power2"] = 0;
		motor2["id"] = 2;
		motor2["power1"] = 0;
		motor2["power2"] = 158;
		joystick["id"] = joystickID;
		joystick["leftUD"] = joyStickLeftRL;
		joystick["leftRL"] = joyStickLeftUD;
		root["TXT"] = joystick;
		root["TXT"] = motor1;
		root["TXT"] = motor2;
		const std::string json_file = Json::writeString(builder, root);
		std::cout << json_file << std::endl;//for testing only
		c = json_file.c_str();
	} catch (const std::exception &e) {
		printf("######### setSendShort: error=%s\n", e.what());//for testing only
		std::cout << "######### setSendShort: Json exception" << e.what() << std::endl;//for testing only
	}
	if (c == NULL) {
		c = "error";
	};
	res = ft_h_websocket.pushMessage01(c, (unsigned int) strlen(c));//handover to the CivetWeb web socket connection handler
	return res;//-1:error, otherwise number of transmitted bytes
}

vleeuwen
Beiträge: 1560
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: TXT and CivetWeb

Beitrag von vleeuwen » 25 Jan 2020, 15:57

Today I have finished the last part of my prototype.
I made my SLI-websocket functional.
FtWebSocket01.JPG
An SLI is an extension element for the RoboPro visual programming environment.
Now I can control a FT-bot (two wheel drive) with a local RoboPro program over the WIFI (internet) with a virtual joystick.
The control page is HTML/JScript/JQuery based and is provide by the web server which runs on the TXT too.
I also I can see status information of my model.
General speaking, this template makes it for me possible:
  • to communicate with a model that runs a RoboPro program in the local mode.
  • to have communicate between a RoboPro program and an external application.
FtWebSocket02.JPG
Characteristic:
  • On the TXT runs an embedded full Civetweb server: websocket, HTML pages, server side scripting (LUA, ECMAscript), LSQL, CGI (C/C++ or Python).
  • The Civetweb server is modulair and can also be compiled without LUA and/or ECMAscript support, which will reduce the binary size.
    The Jscript, JQuery and image for the client web page are also coming from the TXT.
  • The SLI-websocket is more a template that chose where to put the Json creation and how to have the communication between the TA (transfer area) and the websocket.
  • This SLI runs under the normal RoboPro account, the wwwroot could be place in the data area.
    Management of these file can be done by the already present fischertechnik web interface for managing the users files.


Remarks:
  • The web socket client could also be a normal client application (app)
  • The SLI-websocket runs in both local as well on-line mode. This is nice when the TXT is working in the WLAN access pint mode, it is self-supporting.
  • Less overhead in compare with MQTT. The SLI-websocket template serves different objectives.
Education:
Very usable in educational project, as illustration or for (partial) assignments :
  • RoboPro: for workflow oriented programming of mechatronic problems.
  • Basic for HTML, Jscript, Jquery, CSS programming.
  • Use of Json and/or XML technology.
  • Basic C/C++ programming.
  • Basic network issues.
I will take this model with me to the FT Nord-Convention

Antworten