# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. import sys, os sys.path.insert(0, "..") from rmap import jsonrpc import time #mac="860719026700066" #mac="860719020206417" #MQTT_HOST = os.environ.get('MQTT_HOST', 'rmap.cc') MQTT_MAC = os.environ.get('MQTT_MAC', '') MQTT_USERNAME = os.environ.get('MQTT_USERNAME', 'rmap') MQTT_PASSWORD = os.environ.get('MQTT_PASSWORD', 'rmap') rpcproxy = jsonrpc.ServerProxy( jsonrpc.JsonRpc20(),\ jsonrpc.TransportMQTT( user=MQTT_USERNAME,password=MQTT_PASSWORD,mac=MQTT_MAC,logfunc=jsonrpc.log_stdout,timeout=60)) rpcproxy.sdrecovery({})
import rmap.jsonrpc as jsonrpc from rmap import rmap_core import base64 # create JSON-RPC server ttntransport = jsonrpc.TransportTTN(appid=appid, devid=devid, password=password, confirmed=confirmed, port=port, schedule=schedule, logfunc=jsonrpc.log_stdout) with jsonrpc.ServerProxy(jsonrpc.JsonRpc20(), ttntransport) as rpcproxy: if (rpcproxy is None): print ">>>>>>> Error building ttn transport" raise SystemExit(1) else: print ">>>>>>> execute ttn JSRPC" mydata = [{ "n": 7, "s": True }, { "n": 5, "s": False }, { "n": 4,
def configstation(transport_name="serial",station_slug=None,board_slug=None,logfunc=jsonrpc.log_file("rpc.log"), device=None,baudrate=None,host=None,transport=None,username=None): if (station_slug is None): return if (username is None): return mystation=StationMetadata.objects.get(slug=station_slug,ident__username=username) if not mystation.active: print "disactivated station: do nothing!" return for board in mystation.board_set.all(): if board_slug is not None and board.slug != board_slug: continue if transport_name == "amqp": try: if ( board.transportamqp.active): print "AMQP Transport", board.transportamqp amqpserver =board.transportamqp.amqpserver amqpuser=board.transportamqp.amqpuser amqppassword=board.transportamqp.amqppassword queue=board.transportamqp.queue exchange=board.transportamqp.exchange sh=rabbitshovel.shovel(srcqueue=queue,destexchange=exchange,destserver=amqpserver) sh.delete() sh.create(destuser=amqpuser,destpassword=amqppassword) except ObjectDoesNotExist: print "transport AMQP not present for this board" return if transport is None: if transport_name == "serial": try: if ( board.transportserial.active): print "Serial Transport", board.transportserial mydevice =board.transportserial.device if device is not None : mydevice=device mybaudrate=board.transportserial.baudrate if baudrate is not None : mybaudrate=baudrate transport=jsonrpc.TransportSERIAL( logfunc=logfunc,port=mydevice,baudrate=mybaudrate,timeout=5) except ObjectDoesNotExist: print "transport serial not present for this board" return if transport_name == "tcpip": try: if ( board.transporttcpip.active): print "TCP/IP Transport", board.transporttcpip myhost =board.transporttcpip.name if host is not None : myhost=host transport=jsonrpc.TransportTcpIp(logfunc=logfunc,addr=(myhost,1000),timeout=5) except ObjectDoesNotExist: print "transport TCPIP not present for this board" return rpcproxy = jsonrpc.ServerProxy( jsonrpc.JsonRpc20(),transport) if (rpcproxy is None): return print ">>>>>>> reset config" print "reset",rpcproxy.configure(reset=True ) print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> configure board: ", board.name," slug="+board.slug try: if ( board.transportmqtt.active): print "TCP/IP Transport",board.transportmqtt print "sampletime and mqttserver:",rpcproxy.configure(mqttsampletime=board.transportmqtt.mqttsampletime, mqttserver=board.transportmqtt.mqttserver) print "mqtt user and password:"******"transport mqtt not present" try: if ( board.transporttcpip.active): print "TCP/IP Transport",board.transporttcpip mac=board.transporttcpip.mac[board.transporttcpip.name] print "ntpserver:",rpcproxy.configure(mac=mac,ntpserver=board.transporttcpip.ntpserver) except ObjectDoesNotExist: print "transport tcpip not present" try: if ( board.transportrf24network.active): print "RF24Network Transport",board.transportrf24network print "thisnode:",rpcproxy.configure(thisnode=board.transportrf24network.node, channel=board.transportrf24network.channel) if board.transportrf24network.key != "": print "key:",rpcproxy.configure(key=map(int, board.transportrf24network.key.split(','))) if board.transportrf24network.iv != "": print "iv:",rpcproxy.configure(iv=map(int, board.transportrf24network.iv.split(','))) except ObjectDoesNotExist: print "transport rf24network not present" print ">>>> sensors:" for sensor in board.sensor_set.all(): if not sensor.active: continue print sensor print "add driver:",rpcproxy.configure(driver=sensor.driver, type=sensor.type, node=sensor.node,address=sensor.address, mqttpath=sensor.timerange+"/"+sensor.level+"/") #TODO check id of status (good only > 0) print "mqttrootpath:",rpcproxy.configure(mqttrootpath=mystation.mqttrootpath+"/"+str(mystation.ident)+"/"+\ "%d,%d" % (nint(mystation.lon*100000),nint(mystation.lat*100000))+\ "/"+mystation.network+"/") print ">>>>>>> save config" print "save",rpcproxy.configure(save=True ) print "----------------------------- board configured ---------------------------------------" transport.close()
#create a list of bytes data = bit2bytelist(template, totbit) ##convert endian #for i in xrange(0,len(data),2): # tmp=data[i] # data[i]=data[i+1] # data[i+1]=tmp return data # create JSON-RPC server server = jsonrpc.ServerProxy( jsonrpc.JsonRpc20(radio=False, notification=False), jsonrpc.TransportSERIAL(port="/dev/ttyUSB0", baudrate=19200, logfunc=jsonrpc.log_file("myrpc.log"), timeout=15)) # call a remote-procedure # configure parameter for join #Note: Use lsb notation for deveui var, use lsb/msb switch button on ttn web page for format adjustement print server.set(deveui=(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)) #Note: Use lsb notation for appeui var, use lsb/msb switch button on ttn web page for format adjustement print server.set(appeui=(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)) #Note: Use msb notation for appkey var, use lsb/msb switch button on ttn web page for format adjustement print server.set(appkey=(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16))
# create a JSON-RPC-server import rmap.jsonrpc as jsonrpc server = jsonrpc.Server( jsonrpc.JsonRpc20(radio=True), jsonrpc.TransportTcpIp(addr=("127.0.0.1", 31415), logfunc=jsonrpc.log_file("myrpc.log"))) # define some example-procedures and register them (so they can be called via RPC) def echo(s): return s server.register_function(echo) # start server server.serve()
# create JSON-RPC client import rmap.jsonrpc as jsonrpc server = jsonrpc.ServerProxy(jsonrpc.JsonRpc20(radio=True, notification=True), jsonrpc.TransportTcpIp(addr=("127.0.0.1", 31415))) # call a remote-procedure (with positional parameters) result = server.echo("hello world")