Maginon SP-2 Smart Plug – Final part

The only thing that remains is to create the code to make the initial setup and some code to turn the plug on and off.

Although I have been a software developer for many years, I have never really made much socket-programming, so I tried to find something on the internet to build on.

After quite some searching, I found this discussion on stackoverflow.

This actually issues the correct commands to make the initial setup of a Maginon SP-2 smart plug. However, it needs a small correction to make it work with the Maginon plug – the same that I mentioned earlier with regards to the Orvibo socket. Alle replies from the socket will be received on UDP port 48899.

I have made a corrected version of the register.c program here.

Before you compile the program, change these two lines to match the SSID and Wifi password to your own router  (change DLINK to your SSID and the xxxPASS_WPA_PASSxxx to your Wifi password.

static const char *ssid = "AT+WSSSID=DLINK\r";
static const char *sec_settings = "AT+WSKEY=WPA2PSK,TKIP,xxxPASS_WPA_PASSxxx\r";

The program is compiled with:

gcc -O0 -o register register.c

Before you run the program, be sure to assign the socket a static ip-address in your router. To do this, you need to get the MAC address of the socket, and then in your router, assign a static ip-address to that MAC address.

Now run the program

register

When the socket reboots, it should connect to you own WIFI router. Check the router to see if it has done so.

When it is connected, these two python scripts to turn the socket

On:

#!/usr/bin/env python

from socket import *
from datetime import datetime

HOST = 'plug1'
PORT = 8899
BUFSIZ = 1024
ADDR = (HOST, PORT)

tcpCliSock = socket(AF_INET, SOCK_STREAM)
tcpCliSock.connect(ADDR)

data2 = 'AT+YZSWITCH=1,ON,'+datetime.now().strftime('%Y%m%d%H%M')
tcpCliSock.send(data2)
data1 = tcpCliSock.recv(BUFSIZ)
print data1

tcpCliSock.close()

and Off:

#!/usr/bin/env python

from socket import *
from datetime import datetime

HOST = 'plug1'
PORT = 8899
BUFSIZ = 1024
ADDR = (HOST, PORT)

tcpCliSock = socket(AF_INET, SOCK_STREAM)
tcpCliSock.connect(ADDR)
data2 = 'AT+YZSWITCH=1,OFF,'+datetime.now().strftime('%Y%m%d%H%M')
tcpCliSock.send(data2)
data1 = tcpCliSock.recv(BUFSIZ)
print data1
tcpCliSock.close()

In both cases, you should modify the HOST line in both scripts and set it to the DNS name or the ip-adress of your plug

When you can turn the socket on and off, you can also try to use the delay command

AT+YZDELAY=1,OFF,5,201701232127

It can be used for both ON and OFF. The number after ON/OFF is the delay in minutes.

8 thoughts on “Maginon SP-2 Smart Plug – Final part”

  1. Hej, og tak for den store hjælp til Maginon SP-2.

    Jeg har lavet et PHP script til at Tænde/Slukke en eller flere af switchene fra en webside.
    Det er ikke muligt her at uploade en zipfil med scriptet, men send en mail og jeg sender det gerne til dig.

    M.V.H
    Mark

  2. It is actually possible to query the Maginon sockets if they are turned on or off.
    http://www.3fwork.com/b204/001701MYM012691 shows the process

    You send the command “YZ-RECOSCAN” on UDP to the broadcastaddress for your local network (like 192.168.1.255) on port 48899.
    Each Maginon socket connected to your router will then respond with a message that include its ip-address, its MAC, its serialnumber, a value called “RES” which seem to indicate if it is in working order AND a status that says if it is turned on or off

    This sample program will return a message like this

    Scanning for Maginon SP-2 sockets on local network:
    {'STATUS': '0', 'IP': '192.168.1.12', 'MAC': 'ACCF23482522', 'SN': '00000315', 'RES': '0'}
    {'STATUS': '0', 'IP': '192.168.1.10', 'MAC': 'ACCF2348a9FE', 'SN': '900000217', 'RES': '0'}
    

    where the “STATUS” says if the socket is turned on or off. “0” means OFF and “1” means ON.

  3. I’ve been playing with the US version (Sp-3). Other than the plug format, it seems to be identical. FCC documents show, that FCC IDs Z5C SP-2 and 2635646 are aliases for 2AEPWP1 (Reco4life smart Plug P1.)

    The internal pictures show the wifi module as HF-LPT200
    Here’s the Documentation for the wifi module:
    https://adaptivemodules.com/assets/Wi-Fi/HF-LPT200-Tiny-WiFi-Module-User-Manual.pdf

    This has a nice list of AT commands. You can use the internal serial port (don’t connect AC at the same time!!) for AT+ commands. E.g. change Wifi password, SSID etc., apparently even MAC address. Some commands should work over Wifi.

    1. Thank you for your update

      I have previously tried to look up FCC information, but I was not to find the proper site.

      If it is open to the public, could you please shed light on where you could look up this information?

      Best Regards

  4. First I checked for the FCC ID on my smart plug (Sp-3):
    https://fccid.io/Z5CSP-2
    This gave me the information that it is identical to the Rico4Life:
    https://fccid.io/Z5CSP-2/Letter/FCC-2933-Change-In-ID-2635646
    (FCC ID 2AEPWP1 )

    For the internal photos of the Rico4life smart plug:
    https://fccid.io/2AEPWP1
    Click on “internal photos”
    (https://fccid.io/2AEPWP1/Internal-Photos/Internal-Photos-2625266)

    The Pictures of the Supra US-Version / Rico4life US-Version look very similar to your picture of the European Sp-2. The European board is shorter, but functional parts are mostly at the same spots. Interestingly it even switches the same pin – important for US-version, since US outlets are polarized, but for EU it could switch either pin – which makes me think, that the EU version is a modified US-version. I guess the wifi module would stay the same.
    I’d try the AT+ commands on the serial header. (You have to start with +++ to enable it.)

    The serial module manual only gives you the built-in factory settings of the firmware, not what the plug manufacturer did with it. So, you can set wifi passwords and things like that, but what pin to switch to turn the plug on and off is the manufacturers decision. Your additional research with going through the android apk wasn’t wasted, these payload-commands aren’t in the manual.
    They might be in High-Flyings developers-sdk, but I haven’t gone trough that one yet:
    http://www.hi-flying.com/download-item-lpb100-lpt100-lpt200-lpb100u-lpb105-sdk

Leave a Reply

Your email address will not be published. Required fields are marked *