def digitalRead(self, pin): log.info('digitalRead {}'.format(pin)) params = {'pin': pin} ret = self._sess.get(self._root + '/digitalRead', params=params, timeout=self._timeout) ret.raise_for_status() assert ret.text in ['0', '1'], ret.text return int(ret.text)
def digitalWrite(self, pin, value): log.info('digitalWrite {} {}'.format(pin, value)) # HIGH, LOW data = {'pin': pin, 'value': value} ret = self._sess.post(self._root + '/digitalWrite', data=data, timeout=self._timeout) ret.raise_for_status() assert ret.text == 'OK', ret.text
def pinMode(self, pin, mode): # INPUT, INPUT_PULLUP, OUTPUT log.info('set pinMode {} {}'.format(pin, mode)) data = {'pin': pin, 'mode': mode} ret = self._sess.post(self._root + '/pinMode', data=data, timeout=self._timeout) ret.raise_for_status() assert ret.text == 'OK', ret.text
def i2c_ask(self, address, message, response_len): hexstring = hex2str(message) # 01FA0002 log.info('i2c > ' + hexstring + ', wait ' + str(response_len) + ' bytes') ret = self.i2c('ask', address=address, hexstring=hexstring, response=response_len) log.info('i2c < ' + ret.text) return str2hex(ret.text)
def delay(self, msec): log.info('delay {} msec'.format(msec)) time.sleep(msec / 1000.0)
def ping(self): log.info('ping') ret = self._sess.get(self._root + '/ping', timeout=self._timeout) ret.raise_for_status() assert ret.text == 'pong'
def version(self): log.info('version') ret = self._sess.get(self._root + '/version', timeout=self._timeout) ret.raise_for_status() assert ret.text
def __init__(self, host, port=80, **kwargs): self._root = 'http://' + host + ':' + str(port) self._sess = Session() self._timeout = kwargs.get('timeout', 3.0) log.info('Testing: {}:{}'.format(host, port))