How to make esp8266 receive commands from another esp8266 webserver? - webserver

Hello could someone show me what changes need to be made to the following github code so that I can connect another esp8266 to it so that it can receive commands from the webserver?
Things that I know so far is that changing the [Server] esp8266 to AP mode so that it makes it much more convenient to connect the [Client] esp8266 to it has already been done in my code, this was straightforward to do but I've never experienced having to retrieve data from one esp8266 to another.
This link provides the original code that I have been working from, if my [server] and [client] code is needed then I can post it but they're essentially the same with exception for one being access point mode and the other coding to the access point.
https://github.com/jasoncoon/esp8266-fastled-webserver

Related

How to send a GET/POST request with Forth

I want to write a Forth program for my Raspberry Pi. This program shall read some sensor data from an existing file and send it to a website where the data gets stored.
Searching the web there was plenty of documentation about how easy and fast Forth is and how to calculate Fibonacci numbers. But how can I request a URL? How can I send data to a website and process the result?
If there's no socket support: is it possible to start an external program like curl/wget to do the request?
It is not obvious from the question what the Forth implementation is used.
For example, Gforth (that is available on Raspberry Pi)
has some support of the sockets and also it allows to start an external program using system word. See my answer on the similar question: How do I read raw code from a website in Gforth?
Example of creating curl child process in Gforth:
S" curl https://example.com/" system
In any case,
it seems that the most promising approach for the given problem is to develop a binding to libcurl (if it doesn't exist yet for the used Forth implementation).

nodemcu _ esp8266 server recieved data from android app and forward to esp8266 client

I am new programmer esp8266 with lua. I have 2 esp8266 and 1 android phone. One esp8266 is my server and another esp8266 is client. I want to send data from android app to server and server forward this data to esp8266 client. I programed server and client but i think it's wrong, the server received data from phone but not forward it to client.
The server listen on port 9000 and when received data forward it on the port 9999.and esp8266 client listen port 9999.
it is my esp8266 server code:
Can anyone help me?
wifi.setmode(wifi.SOFTAP)
wifi.ap.config({ssid="novin",pwd="12345678"})
print(wifi.ap.getip())
if sv~=nil then
sv:close()
end
function creat_server()
sv = net.createServer(net.TCP)
sv:listen(8080, function(c)
c:on("receive", function(c, pl)
if(pl~=nil) then
print(pl)
data=pl
pl=nil
end
end)
end)
if(data~=nil) then
sck(data)
data=nil
end
end
function sck(data)
sv:listen(9000,function(cc)
cc:send(data)
cc:on("receive", function(cc, dt)
print(dt)
data1=dt
end)
cc:on("sent",function(cc)
print("data send!!!!!!!!!!")
end)
end)
end
creat_server()
I saw your other question which was put on hold, your idea has a little bit problem. The esp which is server can't "Forward" data as you mean it, what I mean is that it can't be server and client at the same time, let it be server all the time. So let's review and recreate the scenario again:
You have android application which acts as a client and it will send some data to server node via POST method, there you get it and store it. you can then get the data on client node via GET method from previous server node. this is one way.
About the way you mentioned, first of all the ports in the code you have provided are different from what you have said in your question, other than that you need to first init node as SOFTAP and get the data and after that config it as STATION and send data via http module.
To simply put it, the code you have provided is too imperfect.
EDIT:
You can get all the docs and mini-examples you need from this site,
and in case you need http module, check out this part of that site.
Here's the doc indicating how to configure your wifi correctly according to your needs.
P.S. Http module has been added recently to the firmware, in case you want to use it and your IDE won't recognize it's syntax, use build cloud to build your own firmware, it will take only 5 minutes.
Also it was much easier for me to move forward with documents rather than example codes in the websites, it's up to you to chose which ever you want.

Openwrt library for REST both client and server

I'm developing an application on openwrt where I need to be able to send HTTP POST's and also receive them. This means I need to be both client and server simultaneously.
The ideia is to support the modes bellow in real time
-> poll mode - where send a POST to a server and process the answer
-> push mode - where I receive a POST from a client and have to send an answer
So far I only found libraries that implement the server or client side but never both. I could use two different libraries to achieve the result I want but it seems a bit "dirty". Here is what I found so far:
-> libcurl - Implements the client side
-> libmicrohttpd - Implements the server side
-> libwebsockets - Implements websockets but I'm not really sure is suited for what I want and needs some further testing
Someone knows a any better suited library? I'm kinda stuck at the moment :)
Not knowing any details of your application I suggest the following. Make a basic and simple solution using:
wget for poll mode
uhttpd for push mode
Write an ash script that glues these two building blocks together. Use cgi-bin to run the script in poll mode.

Send data to socket on iPhone

I don't know very much about sockets at all. What I am wondering is how the sockets work.
1) Firewalls often block ports. Is it plausible that if I request a socket and it is behind a blocked port anything that is sent or received will get intercepted and destroyed? Is this an issue?
2) On the server side how do you keep the connection alive to send data back through, like if I was building a chat app is it possible to start a connection through a socket and keep that alive and have the server basically push new data through the stream. Instead of the apps having to query every so often.
3) If the app goes into the background apple says they will keep the socket as long its not needed (if it is voip). Does that mean that I could still send data through to the app and have it handled? If my app is registered for location updates and executing in the background already will the socket stay open?
Are there any server languages that make it simple? I am currently using python and Django for a simple http server. Are any tutorials on setting up a server that can keep connections alive. I really don't know much about this so what i'm asking may not make any sense but some direction would be greatly appreciated.
1) I haven't found an issue with firewalls at all.
2) I used a twisted server along side my web server to implement a event driven socket server and it works great.
3) the sockets will stay open as long as you are executing in the background and the delegate methods are called to handle stream events.
There is an excellent tutorial here:
http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server
that goes over the twisted framework and how to create a chat app with sockets. I found that immensely helpful.

See what website the user is visiting in a browser independent way

I am trying to build an application that can inform a user about website specific information whenever they are visiting a website that is present in my database. This must be done in a browser independent way so the user will always see the information when visiting a website (no matter what browser or other tool he or she is using to visit the website).
My first (partially successful) approach was by looking at the data packets using the System.Net.Sockets.Socket class etc. Unfortunately I discoverd that this approach only works when the user has administrator rights. And of course, that is not what I want. My goal is that the user can install one relatively simple program that can be used right away.
After this I went looking for alternatives and found a lot about WinPcap and some of it's .NET wrappers (did I tell you I am programming c# .NET already?). But with WinPcap I found out that this must be installed on the user's pc and there is nog way to just reference some dll files and code away. I already looked at including WinPcap as a prerequisite in my installer but that is also to cumbersome.
Well, long story short. I want to know in my application what website my user is visiting at the moment it is happening. I think it must be done by looking at the data packets of the network but can't find a good solution for this. My application is build in C# .NET (4.0).
You could use Fiddler to monitor Internet traffic.
It is
a Web Debugging Proxy which logs all HTTP(S) traffic between your computer and the Internet. Fiddler allows you to inspect traffic, set breakpoints, and "fiddle" with incoming or outgoing data. Fiddler includes a powerful event-based scripting subsystem, and can be extended using any .NET language.
It's scriptable and can be readily used from .NET.
One simple idea: Instead of monitoring the traffic directly, what about installing a browser extension that sends you the current url of the page. Then you can check if that url is in your database and optionally show the user a message using the browser extension.
This is how extensions like Invisible Hand work... It scans the current page and sends relevant data back to the server for processing. If it finds anything, it uses the browser extension framework to communicate those results back to the user. (Using an alert, or a bar across the top of the window, etc.)
for a good start, wireshark will do what you want.
you can specify a filter to isolate and view http streams.
best part is wireshark is open source, and built opon another program api, winpcap which is open source.
I'm guessing this is what you want.
capture network data off the wire
view the tcp traffic of a computer, isolate and save(in part or in hole) http data.
store information about the http connections
number 1 there is easy, you can google for a winpcap tutorial, or just use some of their sample programs to capture the data.
I recomend you study up on the pcap file format, everything with winpcap uses this basic format and its structers.
now you have to learn how to take a tcp stream and turn it into a solid data stream without curoption, or disorginized parts. (sorry for the spelling)
again, a very good example can be found in the wireshark source code.
then with your data stream, you can simple read the http format, and html data, or what ever your dealing with.
Hope that helps
If the user is cooperating, you could have them set their browser(s) to use a proxy service you provide. This would intercept all web traffic, do whatever you want with it (look up in your database, notify the user, etc), and then pass it on to the original location. Run the proxy on the local system, or on a remote system if that fits your case better.
If the user is not cooperating, or you don't want to make them change their browser settings, you could use one of the packet sniffing solutions, such as fiddler.
A simple stright forward way is to change the comupter DNS to point to your application.
this will cause all DNS traffic to pass though your app which can be sniffed and then redirected to the real DNS server.
it will also save you the hussel of filtering out emule/torrent traffic as it normally work with pure IP address (which also might be a problem as it can be circumvented by using IP address to browse).
-How to change windows DNS Servers
-DNS resolver
Another simple way is to configure (programmaticly) the browsers proxy to pass through your server this will make your life easier but will be more obvious to users.
How to create a simple proxy in C#?