dsyleixa123
Posts: 628
Joined: Mon Jun 11, 2018 11:22 am

C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Thu Dec 26, 2019 3:14 pm

are there C++ Wifi and Webserver libs for the Pi similar to those available for Arduino (MKR1010, esp8266, ESP32)?

Heater
Posts: 14757
Joined: Tue Jul 17, 2012 3:02 pm

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Thu Dec 26, 2019 5:34 pm

dsyleixa123,
are there C++ Wifi and Webserver libs for the Pi similar to those available for Arduino (MKR1010, esp8266, ESP32)?
I'm not sure what you are asking there exactly. Libraries for what language?

If you want a web server on your Pi there are many ready made ones available. For example:

Apache https://httpd.apache.org/
nginx https://www.nginx.com/
lighthttpd https://www.lighttpd.net/

Typically one adds ones own code to these written as so called "CGI scripts" or some kind of module system. People use languages like PHP to create applications with these.

Or you can add web server capability to your own programs. Almost all programming languages have libraries or modules to do this:

Javascript/node.js has HTTP functionality built into it's standard library. But you can use the express.js module to make life even easier.

The Rust language has the Rocket, Actix and other web server libraries.

Python has Flask and no doubt others.

Now what about WiFi? Why are you needing a library for that. WiFi just creates a network interface that your machine uses like ethernet or whatever. Nothing there for you application to know about. Unless you are doing something special like creating a WiFi configuration tool.
Memory in C++ is a leaky abstraction .

dsyleixa123
Posts: 628
Joined: Mon Jun 11, 2018 11:22 am

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Thu Dec 26, 2019 6:09 pm

I mean especially the libs like those ones:

https://github.com/espressif/arduino-es ... ries/WiFi/
https://github.com/espressif/arduino-es ... /WebServer

just for the Pi then, with a comparable range of functions by (very) similar syntax

Heater
Posts: 14757
Joined: Tue Jul 17, 2012 3:02 pm

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Sat Dec 28, 2019 6:08 pm

I'm sure those libs are great and all if one has an arduino and/or esp32.

Please don't expect us to read all that code to see what they do.

On the Pi any normal program you write does not need to worry about WiFi. Programs talk through networking, networking is provide bu the operating system, networking may end up going over ethernet or WiFi or serial port, etc. Depends how you set things up.

Web server is as I described above.

Point is, this is not a micro-controller with no operating system like an arduino or esp32. A Pi is a full up computer running a multi-user operating system. Stuff that you might thing you need to write, or use from libraries, is part of the operating system.
Memory in C++ is a leaky abstraction .

dsyleixa123
Posts: 628
Joined: Mon Jun 11, 2018 11:22 am

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Sat Dec 28, 2019 6:37 pm

about simply connecting to a WiFi router: yes.
But having a Pi WiFi server in the intra-net (to be connected from another Pi or even from Arduino WiFi clients) and exchaning messages there and back for IoT smart home control,
or having a WebServer, building a website by html, showing a webcam video or sensor values from remote WifiClients, with buttons and labels or grids and receiving user messages from the website via GET or PUT is another thing, and that's what my question is about. For Arduino these functions and examples already all are existing ( no Apaches or Mosquitos needed - just C++ and html ;) ).
Even if a Pi is a full up computer running a Linux OS does finally not make those things availble by just pressing a GPIO switch.

e.g.:
https://smarthome-blogger.de/tutorial/n ... nfuehrung/
https://www.roboremo.com/esp8266-wifi-rc-car.html

(PS, edit:
ESP8266 and ESP32 are run by an RTOS 8) )

Heater
Posts: 14757
Joined: Tue Jul 17, 2012 3:02 pm

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Sat Dec 28, 2019 8:38 pm

It might help if you said exactly what it was you want to do.

Making a Pi into a WiFi client or access point is documented all over the net.

As I think I mentioned above making a web server as part oof whatever application you like, in almost any language is easy, and documented all over the net. See links above.

What am I missing here?

You mention "having a Pi WiFi server in the intra-net (to be connected from another Pi or even from Arduino WiFi clients) and exchaning messages"

Again no problem using RESTfull API requests over HTTP(s) to your home made server on the Pi. Or using MQTT, or NATS or websockets, or whatever.
Memory in C++ is a leaky abstraction .

dsyleixa123
Posts: 628
Joined: Mon Jun 11, 2018 11:22 am

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Sun Dec 29, 2019 11:02 am

my question was:
doing that by similar libs, syntax, and programs like those C++ Sketches made for Arduinos, e.g. WiFi shields or ESP boards,so easiliy to be ported from Aduino C++ Sketches to Raspi C++ code.

User avatar
DougieLawson
Posts: 37719
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Sun Dec 29, 2019 2:19 pm

No. Porting Arduino stuff is non-trivial.

Show us what the Arduino sketch does (rather than fussing over the libraries used to do it) and folks may have half a chance to help you.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

dsyleixa123
Posts: 628
Joined: Mon Jun 11, 2018 11:22 am

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Sun Dec 29, 2019 6:43 pm

there are lots of source codes which I already have or I want to use in future (like both simple examples I linked to above), partially of 2000 lines and even more, but developing all and everything from the scratch is too cumbersome, that's why I asked for Arduino-compatible Pi code.

User avatar
DougieLawson
Posts: 37719
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Sun Dec 29, 2019 11:45 pm

Look at the function being done not the implementation of that function. Or you will spend the rest of your life chasing your tail.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

dsyleixa123
Posts: 628
Joined: Mon Jun 11, 2018 11:22 am

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Mon Dec 30, 2019 8:46 am

my question is about C++ libs for the Pi, like stated above, ready to use, which provide almost the same API functions like the Arduino API does for Wifi server+clients and Web servers+clients etc., so that Arduino (wifishield, MKR1010, ESP8266/32) programs can easily be ported to the Pi, too.

Heater
Posts: 14757
Joined: Tue Jul 17, 2012 3:02 pm

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Mon Dec 30, 2019 9:04 am

I think dsyleixa123 has a valid question there Dougie. If one has thousands of lines of code and want to use it on a different platform one might be looking for a similar API to make use of so as to avoid too much rewriting work.

That is why we have standard libraries and Hardware Abstraction Layers (HAL) and so on. To aid portability.

Sadly this is not often the case when developing code on micro-controllers. One is often very close to the metal, performance is an issue, one just writes whatever code is needed to get something to work on that particular device.

@dsyleixa123

I think you only have a couple of options:

1) If you want to keep your existing code unchanged as much as possible then you can write your own abstraction layer between it and the functionality of the Pi API's. For every function your application calls that does not exist on the Pi you can write a replacement function that gets what ever is required done using Pi facilities.

2) Bite the bullet and write your applications over again. 2000 lines of code is not so much.

I'm inclined to side with Dougie and suggest that option 2 is the way to go.

The good news here is that you can learn a great lesson for the future.... modularize your programs.

That is to say, try and split you application up into modules. In C that would be different files. In C++ that might be different files and classes. Other languages have actual modules.

The idea is to identify coherent lumps of functionality and put them in their own module. Importantly try to keep the interactions/connections/dependencies between modules as few as possible. Modules should be independent things that can be reused in other programs.

A simple case might be to put all the logic of your program into a module. Call it "MyApplication" for example. Now, MyApplication requires things like LEDs and Switches and serial ports. Don't put all that GPIO and other stuff into the MyApplication module. Rather create a LEDModule, a SwitchModule, a SerialModule. Have them interface to the right GPIO and serial ports as required and provide functions for MyModule to call.

Now you can move MyModule to a totally different machine or operating system unchanged. All you have to do is create the LED, Switch and Serial modules for it to use on those new platforms.
Memory in C++ is a leaky abstraction .

Heater
Posts: 14757
Joined: Tue Jul 17, 2012 3:02 pm

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Mon Dec 30, 2019 9:11 am

dsyleixa123,
...for Wifi server+clients and Web servers+clients etc., so that Arduino (wifishield, MKR1010, ESP8266/32) programs
Thing is you are talking about at least two very different things here.

1) Web servers and clients and such like are high level application code.

2) Arduino (wifishield, MKR1010, ESP8266/32) is about low level drivers of specific hardware devices.

I know that in Arduino/micro controller word this might all be glommed together in a big ball of code so perhaps yo don't discern the difference yet. Did I mention modularization above.

It's not clear to me why one would need wifishield or ESP drivers for a Pi when it already has WiFi. If you really want to use them I understand it's only a matter of communicating over a serial port.
Memory in C++ is a leaky abstraction .

dsyleixa123
Posts: 628
Joined: Mon Jun 11, 2018 11:22 am

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Mon Dec 30, 2019 9:26 am

as you don't seem to understand my question, again, in simple words:
I am looking for Pi C++ libs to simply port Arduino C++ Sketches for Wifi/Web programs
(like I linked to above:
https://www.raspberrypi.org/forums/view ... 5#p1586768
https://www.raspberrypi.org/forums/view ... 5#p1585892 )
to C++ programs for the Pi, to substitute Arduino hardware (e.g., ESPs) by Raspis (e.g., providing multiple API function wrappers).
How they work internally is absolutely unimportant - they may keep being just black boxes.

Eventually it may be perhaps roughly comparable to wiringPi (C), which mimics Arduino Wiring (C++) functions.

(edited, typos)
Last edited by dsyleixa123 on Mon Dec 30, 2019 9:35 am, edited 2 times in total.

User avatar
DougieLawson
Posts: 37719
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Mon Dec 30, 2019 9:31 am

Since you insist on ignoring everyone's advice your only hope may be the Raspberry stuff at https://create.arduino.cc/

I'm outta here.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Heater
Posts: 14757
Joined: Tue Jul 17, 2012 3:02 pm

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Mon Dec 30, 2019 10:03 am

dsyleixa123 ,
as you don't seem to understand my question, again, in simple words:...
I think we understand you very well. In simple words:

You want to take an Arduino sketch and run it on a Pi without having to change it.

If that is not what you mean then no, we don't understand and you will have to try to be clearer.
...I am looking for Pi C++ libs to simply port Arduino C++ Sketches for Wifi/Web programs...
Ah yes, we did understand you. Good.
...(like I linked to above:
Sorry but I don't have time to start following and reading a bunch of links.

Bottom line is:

I don't know of any such library or libraries.

I don't believe they would work particularly well if they existed.

I don't even think it a good idea to move an Arduino program to a Pi. Not unless it has some significant non-hardware dependent module that can be extracted and reused in a different environment. See "modularization" above.

By the sounds of it you only have a few thousand lines of code there. You could have rewritten it for the Pi in the time it takes discussing ways to avoid doing that here :)
Memory in C++ is a leaky abstraction .

dsyleixa123
Posts: 628
Joined: Mon Jun 11, 2018 11:22 am

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Mon Dec 30, 2019 10:30 am

@Heater,
yes, thank you, I understood that you don't know of such libs.

User avatar
PeterO
Posts: 5623
Joined: Sun Jul 22, 2012 4:14 pm

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Mon Dec 30, 2019 12:38 pm

This might be of interest
https://gist.github.com/laobubu/d6d0e9b ... 2d03e1409e

"Pico HTTP Server in C

This is a very simple HTTP server for Unix, using fork(). It's very easy to use"

It's not a library but a complete application, but the code is small and will show you how to implement something similar to the arduino httpd library.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12667
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Mon Dec 30, 2019 12:44 pm

A RPI isn't similar to an Arduino at all, so for such libs to exist a raspberry PI should be downgraded and be used as a microcontroller, throwing away its Linux software base, and use it "bare metal".
but bare metal programming on an RPI is normally done in assembler, not C++

there is a bare metal section in this forum, possibly someone there can help you!

User avatar
PeterO
Posts: 5623
Joined: Sun Jul 22, 2012 4:14 pm

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Mon Dec 30, 2019 12:54 pm

mahjongg wrote:
Mon Dec 30, 2019 12:44 pm
A RPI isn't similar to an Arduino at all, so for such libs to exist a raspberry PI should be downgraded and be used as a microcontroller, throwing away its Linux software base, and use it "bare metal".
It all depends on what the OP is using the web server for on the Arduino... Often the web server just serves one or two very simple pages with readings from sensors connected to the Arduino. In such cases it is perfectly possible to do something similar on a PI using linux.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

dsyleixa123
Posts: 628
Joined: Mon Jun 11, 2018 11:22 am

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Mon Dec 30, 2019 12:56 pm

as stated, also the ESPs are not "bare-metal", but driven by an RTOS (freeRTOS, specifically).
Of course there may be different libs for the Pi to WiFi and Webserver/clients, but I do not want (and simply am not able) to rewrite all and everything (thanks @PeterO, anyway!), and finally it does not interest me what the functions actually do internally:
the point is, that the example programs like those I had linked to above will run with just very few porting adjustments.
E.g., also wiringPi's digitalWrite(pin, state) works by usage the same on the Pi as on Arduinos, even if internally it's completely different, same about similar i2c or UART functions.
So it wouldn't help to get links to completely different libs, the Aduino/ESP API syntax is what's crucial.

edit, quoted from an extremely simple LED control example I had linked already to:
https://smarthome-blogger.de/tutorial/n ... nfuehrung/

Code: Select all

#include <ESP8266WiFi.h>
  
const char* SSID = "NETZWERKNAME";
const char* PSK = "PASSWORT";
  
WiFiServer server(80);

void initWiFi(){
  WiFi.begin(SSID, PSK);
  
  while(WiFi.status() != WL_CONNECTED){
    delay(500);
  }
  
  server.begin();
}
  
void setup() {
  pinMode(13, OUTPUT);
  
  initWiFi();
}
   
void loop() {
  WiFiClient client = server.available();
  if(!client){
    return;
  }
  
  if(WiFi.status() != WL_CONNECTED){
    initWiFi();
  }
  
  String request = client.readStringUntil('\r');
  client.flush();
  
  if(request==""){
    client.stop();
    return;
  }
  
  //GPIOS schalten
  if(request.indexOf("mode=1")>=0){
    digitalWrite(13, 1);
  }
  else if(request.indexOf("mode=0")>=0){
    digitalWrite(13, 0);
  }
  
  //Ausgabe erzeugen
  String output;
  output += "http/1.x 200 OK\n";
  output += "Content-Type: text/html; charset=UTF-8\n\n";
  output += "<!DOCTYPE HTML>";
  output += "<html>";
  output += "<h1>LED schalten</h1>";
  output += "<form action=\"\" method=\"GET\">";
  output += "<button name=\"mode\" value=\"1\">AN</button>";
  output += "<br><br>";
  output += "<button name=\"mode\" value=\"0\">AUS</button>";
  output += "</form>";
  output += "</html>";
  
  client.print(output);
    
  client.stop();
}
  

edited: c+p error
Last edited by dsyleixa123 on Mon Dec 30, 2019 1:16 pm, edited 3 times in total.

User avatar
PeterO
Posts: 5623
Joined: Sun Jul 22, 2012 4:14 pm

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Mon Dec 30, 2019 1:03 pm

dsyleixa123 wrote:
Mon Dec 30, 2019 12:56 pm
as stated, also the ESPs are not "bare-metal", but driven by an RTOS (freeRTOS, specifically).
Of course there may be different libs for the Pi to WiFi and Webserver/clients, but I do not want to rewrite all and everything (thanks @PeterO, anyway!),
FreeRTOS has a network socket API so translating the web server I linked to should be straight forward and not much effort.

PeterO.

Scratch that, seems the FreeRTOS socket API only supports UDP :(

PeterO

Scratch that it seems FreeRTOS DOES support TCP !

https://www.freertos.org/FreeRTOS-Plus/ ... orial.html

PeterO
Last edited by PeterO on Mon Dec 30, 2019 1:07 pm, edited 2 times in total.
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

dsyleixa123
Posts: 628
Joined: Mon Jun 11, 2018 11:22 am

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Mon Dec 30, 2019 1:04 pm

PeterO wrote:
Mon Dec 30, 2019 1:03 pm
dsyleixa123 wrote:
Mon Dec 30, 2019 12:56 pm
as stated, also the ESPs are not "bare-metal", but driven by an RTOS (freeRTOS, specifically).
Of course there may be different libs for the Pi to WiFi and Webserver/clients, but I do not want to rewrite all and everything (thanks @PeterO, anyway!),
FreeRTOS has a network socket API so translating the web server I linked to should be straight forward and not much effort.

PeterO.
perhaps for experts and pros not much effort, to me it's rocket science though :roll:

Heater
Posts: 14757
Joined: Tue Jul 17, 2012 3:02 pm

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Mon Dec 30, 2019 1:05 pm

dsyleixa123,
as stated, also the ESPs are not "bare-metal", but driven by an RTOS (freeRTOS, specifically).
As not stated. RTOS/freeRTOS is a whole different world from Arduino. We cannot guess at things that are not stated.

Perhaps it would help to ask specifically about one of those platforms at a time.
Memory in C++ is a leaky abstraction .

dsyleixa123
Posts: 628
Joined: Mon Jun 11, 2018 11:22 am

Re: C++ Wifi and Webserver libs for the Pi similar to those available for Arduino?

Mon Dec 30, 2019 1:08 pm

Heater wrote:
Mon Dec 30, 2019 1:05 pm
dsyleixa123,
as stated, also the ESPs are not "bare-metal", but driven by an RTOS (freeRTOS, specifically).
As not stated. RTOS/freeRTOS is a whole different world from Arduino. We cannot guess at things that are not stated.

Perhaps it would help to ask specifically about one of those platforms at a time.

the API function wrappers are (almost) identical for Arduino Wifi shield and for ESP8266/32, and the wrappers are what it's all about.
But this discussion wouldn't help anyway, if no one didn't know Arduino-/ESP-compatible Wifi-/Web API libs for the Pi (as already stated).
The functions I am talking about have also already linked by me (as also stated), you just need to take the efforts to read the examples (opposite to what you stated). :roll:

Return to “C/C++”