The WiFi Powermeter is a electric power meter which sends its measurement results every minute using the MQTT protocol via WiFi to an MQTT broker in the local network.
I used it to measure the power consumption of the fridge in the basement or of the PC of my son and so on.
On the MQTT broker there is one subscriber who transfers all the measurements into a MongoDB, where it now waits for further analysis.
The hardware is rather simple: an Arduino Mega (since it has more than one serial interface), an Arduino WiFi shield and on top a RS485 adaptor for the Modbus communication.
For the software I'`m using the Modbus library from <ahref="https://code.google.com/p/simple-modbus/">https://code.google.com/p/simple-modbus/</a>. Unfortunately, it disappeared right there, don'`t know why. Seems, that I have to be really careful with the files. The MQTT library I'`m using is from <ahref="http://knolleary.net/arduino-client-for-mqtt/">http://knolleary.net/arduino-client-for-mqtt/</a>.
First, it was not possible to establish an MQTT connection at all. Strange, since via Ethernet it wasn'`t a problem at all. I found, supported by Google that that the WiFi library and the shield handles a <tt>stop()</tt> on a fresh client socket somewhat strange: The socket can not be open or will be closed immediately after opening. Since at least in my case I always give a fresh <tt>WiFiClient</tt> into the <tt>PubSubClient</tt> I removed the <tt>connected()</tt> call from the top of the <tt>connect</tt> method in <tt>PubSubClient.cpp</tt>.
Second, I ran into the problem that messages I published via PubSubClient using an Arduino Mega and an Arduino Wifi Shield which are large than about 80 octets did not appear at the broker. I found by googling that it is not possible to send more than 90 octets using the Wifi Shield and the related library at once: http://mssystems.emscom.net/helpdesk/knowledgebase.php?article=51
And that exactly what I experienced too: I increased the buffer size one by one and at 90 octets it stopped and the WiFi library lost the connection.
Using this patch, which I applied against release 1.9.1 everything works fine now: