Snippet - Generic ESP8266 and network support libraries

I just posted Generic ESP8266 and network support libraries on Codeshare. Feel free to discuss and make suggestions here.

7 Likes

Hi.

I just posted an issue (actually a suggestion :wink: ) on github.

Great work!

Both issues posted are great points and I will follow up on each. Thanks much!

Hm,
I tried to run your example and was not able to make it run.
I downloaded the solution from github and got a lot of errors as I tried to compile the solution.
Installing the Molecule example with Nuget did not lead further.
I succeded in eliminating most errors but still the error “HttpClient.CreateRequest() does not exist” occurs.
Is it possible to get a complete working solution or a valid instruction to make it run?
Thanks in advance

M. Flume

@ mflume - Are you using PervasiveDigital.Net and further references ? On what hardware are you trying to run ?

That’s strange - now I get a fail as well but the sntp time get from internet works …

DNS lookup failed for the web site ??? See picture for details …

I am traveling now, but i will look into this tomorrow.

@ mcalsyn - Thanks for the fast response, whilst at it, can you have a look why the IP address is returning zeros all the time maybe this is correlated.

Do you want me to raise my findings (discussions, bugs, proposals, etc) as issues on MoleculeDotNet · GitHub ?

I just followed the Nuget - instructions on

then I copied the example code from

https://www.ghielectronics.com/community/codeshare/entry/1023

into the program.cs file and tried to compile this.

I had to add some references and change the usings from IngenuityMicro to PervasiveDigital. After that all errors were gone besides the missing definition of:


            var request = httpClient.CreateRequest();

This was my first try. I did not connect the hardware or tried to dig deeper as I hope there is someone who can help me.
Best for a beginner in this ESP8266 - stuff would be a complete visual studio package with all files and references needed.

@ PiWi - Yes please. I used to rely on little yellow sticky notes using a filing system best described as ‘sedimentary’. Now, I am almost completely driven by bugs and issues in Github and Visual Studio Online. The best way to get attention is to open an issue.

Sorry, but I completely forgot to look into this issue - I suspect it is a race condition of some sort or a failure to parse the response from your particular ESP8266 firmware - both of which I can fix. I may need to ask you to enable some debugging output and send me the results, but I will look into it myself first. But yes, please do open an issue. I tend to cycle through my projects and clean up issues batch-style and I forgot this one the last time around.

@ mflume - Unfortunately, I made a breaking change to the API and did not update the sample posted here. The sample, which does a simple HTTP request, is now updated. You will need to make three changes : CreateRequest() is now “new HttpRequest()”; and instead of a Send method on HttpRequest, you now use the Http client to do the send : httpClient.Send(httpRequest) for synchronous responses, or httpClient.SendAsync(httpRequest) for async responses as shown in the sample, Lastly, the http request now returns a byte array in order to support binary interactions, so you need to use resp.GetBodyAsString() to retrieve the body as a string. resp.Body returns the byte array now.

Note that the sample shows an async request, which is useful when you don’t want to block your thread (say, if you are collecting a stream of sensor values), but it is more complex to code against and coordinate everything. Use httpClient.Send to block on that line of code until a response is received. It blocks your thread but is easier to program against.

Also - you may want to use Nuget’s “update” function to pull down new binaries (Right click on your solution, Select “Manage Nuget Packages”, select “Updates”, click “Update All”). There are two bug fixes in there now. Kudos to @ Bec A Fuel for identifying a couple issues and suggesting fixes. Much appreciated!

1 Like

Now I succeeded to compile the program.
I’ll try to make it run next days, as I am a little busy in my job.
I’ll give a report.
Thanks!

These packages have been updated to v2.0.0-beta. Please let me know if you run into issues using these. See the CodeShare entry for sample code

The changes include:
[ul]Support for Access Point mode (softAP) Your ESP8266 or Neon board can act as an access point and not just a client
Support for DHCP
Support for Server Mode and incoming socket data (see “usage” code)
Expanded support for getting/setting IP and Mac addresses and getting netmask and gateway
Use of ThreadPool for greater performance
Numerous bug fixes
[/ul]

Available as 2.0.0-beta on nuget (use the “Include Prerelease” option) if you want to experiment with the new code. I’ll promote it to production next week if there are no major issues.

Note: Nuget is being a bit slow about updating their indices, so if you get errors regarding packages not being found, you may need to wait for the indices to get updated.

Source-code lovers : There are pre- and post- build PowerShell commands that take care of versioning and creation of nuget packages. These scripts can be fiddly to make work, but you can safely disable them and you will still get usable dlls (but no local nuget packages).

6 Likes

Nuget issues are resolved as of now. There was actually a problem with the upload. Please be sure to pick up the latest pre-release bits.

1 Like

@ mcalsyn - Great news. Just the excuse I needed to get my STM32F405 with on-board ESP-07 out and updated. Hoping I can get some of the socket stuff to work too. Wish me luck.

Out of curiosity: did ThreadPool give you a measurable speedup? We have in the past used a thread pool. But as NETMF threads are so light-weight, we removed it again, as it added unnecessary complexity.

It’s a fair question - I wired it in based on an issue filed in github, though I don’t have hard data yet. It certainly passes all the tests I have but I have no evidence that it is “better” in any measurable way. I do plan to do some testing and stick with the winner because the ESP8266 serial transfer is very performance sensitive (go too slow, and the esp will quickly overrun the buffer).

For what it’s worth, the code does a LOT of short-lived async dispatching and consequently was spinning up a lot of short-lived threads, so it seemed like a reasonable change, but like I said - no hard data yet.

@ Jason - If it requires luck, I did it wrong. :smiley:

Version 2.0.3, is available on nuget (ignore the bad comment on the codeshare update - it is no longer in the ‘prerelease’ nuget collection)

Includes:
– Support for Access Point mode (softAP) Your ESP8266 or Neon board can act as an access point and not just a client
– Support for DHCP
– Support for Server Mode and incoming socket data (see “usage” code)
– Expanded support for getting/setting IP and Mac addresses and getting netmask and gateway
– Use of ThreadPool
– Improved version reporting
– Improved call semantics for HttpClient and HttpRequest (breaking api change)
– Support for over-the-air updates of ESP firmware
–Numerous bug fixes

A note about OTA updates : Your ESP must have 8Mb or more of memory, and you must bring GPIO0 low before starting the update. Reading the forums, I see that bricking your ESP is a distinct possibility, but you can recover from that by re-flashing using an FTDI cable instead of the over-the-air process. The code in the nuget packages currently targets AT protocol version 0.23 and SDK 1.0.1(b2), which is the Molecule.Net Neon version. I don’t have any other boards to play with right now. If you run into problems with newer firmware, contact me and I will tell you how to capture a log file so that we can sort it out.

3 Likes