Notifications
Clear all

Experience with the ESP8266

24 Posts
6 Users
3 Likes
1,607 Views
WolfgangW
(@wolfgangw)
Member
Joined: 4 years ago
Posts: 70
Topic starter  

Hi to all...

I was researching about the possibility to send information from one device to another and probably vice versa. What I found - even not the newest one, but good enough for me - is the ESP8266.
I already tried something, but not very satisfying. 

There are some devices I want to use at home only need one-way-direction to send, but in future I guess, there are other devices that most probably need 2-way-communication. Now let me ask any of you that already have experience with that, what kind of tools, especially in software did you use in your projects.

Let's say for simple measure temperature, I don't need 2-way-communication, but there are other ideas, where this might be a must. At least, it is essential to send and get data to and from a Raspberry Pi, which in future is going to be used as a webserver for any kind of temperature and climate data and also about the home automation. 

I read about MQTT and other, also saw many video in Youtube, but somehow not satisfying right now. So I want to ask the ones who have more experience in that, who can tell my what you used and why you chose that way. 

have a great day and thank you in advance for your effort 
Wolfgang

If I am not here, then I am most probably somewhere else


   
Quote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1121
 
Posted by: @wolfgangw

I read about MQTT and other, also saw many video in Youtube, but somehow not satisfying right now.

You must be like a rolling stone who 'cant get no.. satisfaction'  😀 .   As long as theres a network wifi reach, to my mind theres no better way for ease of communications between rpi's, arduino's, desktop PC's etc than mqtt.  Its very easy to set up and use.  So much so that you will have a test set up running in under an hour, so why not give it a try to see if you can find the fulfilment you seek.

On an Rpi, install the broker -sudo apt-get install mosquitto.   Simple, nothing more to do you have a running broker.  On the same or another Rpi install the python library to run as a client - pip3 install paho-mqtt.  Maybe peruse some documentation showing example use

http://www.steves-internet-guide.com/into-mqtt-python-client/

For the ESP8266 or other Arduino type clients I suggest you install the Adafruit mqtt library.  Good example docs and programs can be found on the Adafruit website.

Your ESP8266 will soon be publishing a message like Home/Garden/Temp 24.5  A client program running on the Rpi that subscribes to Home/Garden/Temp will receive the message and activate the motor to switch on the ceiling fan.  Another ESP8266 which also subscribes to the same message, will initiate the pouring of a cold drink, and the publish a message to  Home/Fridge/DrinkReady True .This message is then received by the Rpi that also subscribes to this and on receipt of the message it sends a text message to your mobile that drinks are ready.

For home automation projects its hard to beat using mqtt.  If you don't have the network coverage then it a different story of course.  Did I mention I really like mqtt 😎 

 

This post was modified 4 years ago 2 times by byron

   
ReplyQuote
WolfgangW
(@wolfgangw)
Member
Joined: 4 years ago
Posts: 70
Topic starter  
Posted by: @byron

You must be like a rolling stone who 'cant get no.. satisfaction'

Hi Byron,

thanks for sharing your experience. About satisfaction, I think I am not a rolling stone 🤣 

Just because of my inexperience, I think I better ask, before waste time for something that is leading me into a wrong direction. So it is always good to ask someone who's already done this before.

Now I guess I am going to give it more than just one try. And thanks again for showing me that way to establish it.

Wolfgang

If I am not here, then I am most probably somewhere else


   
ReplyQuote
WolfgangW
(@wolfgangw)
Member
Joined: 4 years ago
Posts: 70
Topic starter  

@byron

sorry to bother you again. I now did what you've wrote before. I installed the MQTT on my Raspberry. So far, so good. But I need to ask. Is there a way to store the sended informations into a database? I've installed the MariaDB, APACHE2 and some other applications. 
My goal at the end is to store the measured data into a database to see for long term what is going on with the temperature and many other data within a year. Possibly life long. 

MQTT, so far I've watched in some other more videos looks like a nice way to send instant messages, but so far more like a fire-and-forget-solution. Honestly I am not through with this stuff and most probably I haven't understood the whole thing. I guess, it is possible, even with a more or less difficult workaround, but for this I am not sure.

Wolfgang

If I am not here, then I am most probably somewhere else


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1121
 
Posted by: @wolfgangw

sorry to bother you again

Hi Wolfgang, its no bother at all, feel free to ask.  And yes, it's very easy to update a database from mqtt messages and thats just what I do. 

 

Firstly get the data from the mqtt callback

# receive message from callback
def MyMqttMessage(client1, userdata, message):
myResp = str(message.payload.decode("utf-8"))
# parse topics
myTopics = message.topic.split("/")

if myTopics[0] == "FenB":
uFenB(myTopics[1],myTopics[2],myResp)
return

if myTopics [0] == etc etc

In this snippet  I have subscribed to all messages I'm expecting a message like FenB/esp8266_1/BatLevel or FenB/rpiControl/IPaddress with a payload of "5.2" or "168.0.1.50".  I call my uFenB function to update the database

# Function to update the Board table with ip or battery information.
def uFenB(myBoard,topic,data):
if topic == "IPaddress":
uIPsql = """UPDATE Board SET IPaddress = %s WHERE UnitID = %s """
cursor.execute(uIPsql, (data, myBoard))
cnx.commit()
elif topic == "BatLevel":
uBLsql = """UPDATE Board SET BatLevel = %s WHERE UnitID = %s """
cursor.execute(uBLsql,(data, myBoard))
cnx.commit()
else:
print("FenB sub topic not recognised ")
I've forgotten how to correctly format the code on this forum, but these are just some snippets taken from some of my test files not to give some horrible long winded example so never mind I think you will get the idea . 😀 
 Edit, oh I see my code comes up in nicely formatted blue boxes when I submit it, cool.
This post was modified 4 years ago 2 times by byron

   
ReplyQuote
WolfgangW
(@wolfgangw)
Member
Joined: 4 years ago
Posts: 70
Topic starter  

@byron

Hi

I have now tried to adhere to the instructions, but then I noticed that this was all done in a RaspberryPi-typical way, especially for Python, which does not quite fit my use case.
Background: I am a C # programmer with no experience of Python. With Mono I can also run C # programs on the Raspberry. Now some people like to clap their hands over their heads and ask "why is he doing this?"
The answer is simple. Right now I have so much to learn about electronics, programming in C / C ++. Circuit design, the interaction of Raspberry and Arduino, that I simply don't have the time to learn Python now.
I found out that there are free C # libraries that I can use on the Raspberry.
The installation of the MQTT broker on the Raspi went flawlessly, a test with two console windows was successful, I was able to send and receive in the other window.
What was not possible is to establish the module using

systemctl enable mosquitto.service

activate when starting the Raspi.
I have created two users on the Raspi that I have to select 1/2 and confirm with a password. The second user (root) is not accepted. The program then aborts and the broker must then be integrated manually with the next restart.
Is it possible to establish the service with the main user only? Otherwise I almost only see the possibility of reinstalling the Raspi. Too bad, but I have to confess, I am really not good with Linux.

Wolfgang

If I am not here, then I am most probably somewhere else


   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1037
 

@wolfgangw

It's a hobby! And I think you said you are retired now.  Correct, or did I understand that incorrectly?

Go ahead, take the time, and learn Python in small steps.  I would expect a massively intelligent programmer like yourself to pick up on Python rather quickly.  The same for Linux.  I worked in the Microsoft world since it's very beginnings but have now been slowly learning Linux, although I'll admit to a lot of kicking and screaming in the beginning.

TGIMITT, more time to learn something new!

SteveG


   
ReplyQuote
WolfgangW
(@wolfgangw)
Member
Joined: 4 years ago
Posts: 70
Topic starter  

@codecage

Hi Steve,

I am still working for another 9 years from now, so far not retired. So TGIF is still meaningful for me 🤣 

I am glad, you can say TGIMITT. And you right. I could learn Python too. Right now, there are still 8 of 12 points I have to work out, so after my usual job, there are only few hours left to get into all that.
About Linux, I already get a little familiar, but still not used to it like I am into Windows.

TGYMITT

See you
Wolfgang

If I am not here, then I am most probably somewhere else


   
ReplyQuote
WolfgangW
(@wolfgangw)
Member
Joined: 4 years ago
Posts: 70
Topic starter  

@byron, @codecage

problem solved. 
I tried something in the way I knew until now. root (user) has no standard password, it is empty per se.

What did I do? I gave a password to root too. After that everything is running.
Little surprise, it was asking same information several times, even it accepted, but now seems to work.

and after reboot, you know "a new boot is always good" sorry, but it sounds better in German "Ein neuer Boot ist immer gut" ít rhymes better than in English 😆 

it really works.

thanks for all

Wolfgang

 

If I am not here, then I am most probably somewhere else


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1121
 

@wolfgangw

Your message arrived just as I was typing a reply, so thats aborted and good to hear all is well in mqtt land 😀 

Maybe we should change the English 'good to boot', with "There's no dispute, its good to boot" to achieve a suitable rhythmic nuance 😎.   If @robo-pi hears of this you may get a whole lot of rhyming verse. 😍 


   
ReplyQuote
WolfgangW
(@wolfgangw)
Member
Joined: 4 years ago
Posts: 70
Topic starter  

@byron

yes, thanks to that so far. Now the next challenge waiting, to use it with C#.

I think anyway I am getting into that faster, than learning Python now. At least, there I know what I have to do.

First I guess I have to find out if and how I can work it out, to make MQTT running on a windows computer. Then I think the step to get the data into the MariaDB on that Raspi will be worked out easy.

Have a nice weekend there.

 

PS: Don't tell @robo-pi he used to bring me to the edge of my Englis abilities. He already once talked me into the ground.

Wolfgang

 

If I am not here, then I am most probably somewhere else


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1121
 

@wolfgangw

you have probably perused the site I link to for C++ clients for windows and linux, but just in case here it is:

https://www.eclipse.org/paho/index.php?page=clients/c/embedded/index.php

A nice weekend to you too 😀 


   
ReplyQuote
WolfgangW
(@wolfgangw)
Member
Joined: 4 years ago
Posts: 70
Topic starter  

@byron

yes man, I already watched and read this. But it is not exactly what I had in mind. This one is for Eclipse, more kind of Java than C#. 
Anyway, it's quite a lot stuff I need to go through now step by step to see how this is working.
At the end, I think I am going to create a little tutorial to share here. Even though to give me a reminder for myself.

Wolfgang

 

If I am not here, then I am most probably somewhere else


   
ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer
Joined: 5 years ago
Posts: 1669
 

C# or Anaconda
which language should I use?
my mind is old and feeble
and will likely blow a fuse

I'm desperate to communicate
between my Pi and ESP
I know I'll need to generate
a coding potpourri

I'll send the data in
and read the data back
and have my magic algorithm
keep everything on track

I'll read temperatures galore
o're the planet far and wide
and help to save the world
from a climate override

DroneBot Workshop Robotics Engineer
James


   
byron reacted
ReplyQuote
WolfgangW
(@wolfgangw)
Member
Joined: 4 years ago
Posts: 70
Topic starter  

@robo-pi

I knew it would happen 🤣 

thank you man, great stuff. That makes my day.

 

Have a nice weekend.
Wolfgang

If I am not here, then I am most probably somewhere else


   
ReplyQuote
Page 1 / 2