我试图从node.js服务器脚本与我的arduino交谈.
这是我的代码:
var app = require('express')()
, server = require('http').createServer(app)
, io = require('socket.io').listen(server)
, SerialPort = require('serialport').SerialPort;
//SERIAL
var portName = '/dev/ttyACM0';
var sp = new SerialPort(); // instantiate the serial port.
sp.open(portName, { // portName is instatiated to be COM3, replace as necessary
baudRate: 115200, // this is synced to what was set for the Arduino Code
dataBits: 8, // this is the default for Arduino serial communication
parity: 'none', // this is the default for Arduino serial …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Django开发一个网站,遵循各种指南,文档和谷歌.我有一些平面页面设置需要访问图像/ CSS文件.
我的settings.py文件如下所示:
# Django settings for FirstBlog project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'db', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': …Run Code Online (Sandbox Code Playgroud) 我有一个python脚本,我想在启动时在后台运行.这是脚本:
#!/usr/bin/python
from Adafruit_CharLCD import Adafruit_CharLCD
from subprocess import *
from time import sleep, strftime
from datetime import datetime
from datetime import timedelta
from os import system
from os import getloadavg
from glob import glob
#Variables
lcd = Adafruit_CharLCD() #Stores LCD object
cmdIP = "ip addr show eth0 | grep inet | awk '{print $2}' | cut -d/ -f1" #Current IP
cmdHD = "df -h / | awk '{print $5}'" # Available hd space
cmdSD = "df -h /dev/sda1 | …Run Code Online (Sandbox Code Playgroud) 我使用haystack搜索我的django网站,它完美地做到了这一点.但是在我的结果页面上,链接不起作用.在我的模板中我使用的代码:
<a href="{{ result.object.get_absolute_url }}">{{ result.object.title }}</a>
Run Code Online (Sandbox Code Playgroud)
在我的其他/ models.py中,我包括:
def get_absolute_url(self):
return urlresolvers.reverse('post', args=[self.pk])
Run Code Online (Sandbox Code Playgroud)
我的urls.py看起来像:
from django.conf.urls.defaults import *
from dbe.other.models import *
urlpatterns = patterns('dbe.other.views',
(r"^(\d+)/$", "post"),
(r"^add_comment/(\d+)/$", "add_comment"),
(r"^delete_comment/(\d+)/$", "delete_comment"),
(r"^delete_comment/(\d+)/(\d+)/$", "delete_comment"),
(r"^month/(\d+)/(\d+)/$", "month"),
(r"", "main"),
)
Run Code Online (Sandbox Code Playgroud)
它应该链接到的URL是:
http://127.0.0.1:8000/other/10/
Run Code Online (Sandbox Code Playgroud)
但它仍然链接到:
http://127.0.0.1:8000/search/?q=searchterm
Run Code Online (Sandbox Code Playgroud)
在shell中会发生这种情况:
>>> from other.models import Post
>>> inst = Post.objects.get(pk=1)
>>> inst.get_absolute_url()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/export/mailgrp4_a/sc10jbr/lib/python/django/utils/functional.py", line 55, in _curried
return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
File "/export/mailgrp4_a/sc10jbr/lib/python/django/db/models/base.py", line 887, …Run Code Online (Sandbox Code Playgroud) 我正在尝试将JSON解组为一个结构体,但它证明是困难的,因为外部JSON密钥发生了变化,我只在一周前开始.这是我的手动尝试:
import (
"encoding/json"
"fmt"
"strconv"
)
type Device struct {
localUUID string
applicationUUID string
externalUUID string
commit string
lastSeen string
state string
progress float32
}
func main() {
devices := make([]*Device, 0, 10)
b := []byte(`{
"5417871461137421886": {
"applicationUUID": "test_applicationUUID",
"commit": "test_commit",
"lastSeen": "test_lastSeen",
"localUUID": "E4:F5:13:8E:F5:43",
"progress": "3.5",
"externalUUID": "test_externalUUID",
"state": "test_state"
},
"5632882567440442530": {
"applicationUUID": "test_applicationUUID",
"commit": "test_commit",
"lastSeen": "test_lastSeen",
"localUUID": "E4:F5:13:8E:F5:42",
"progress": "3.5",
"externalUUID": "test_externalUUID",
"state": "test_state"
},
"8912255216147730520": {
"applicationUUID": "test_applicationUUID",
"commit": "test_commit",
"lastSeen": "test_lastSeen",
"localUUID": …Run Code Online (Sandbox Code Playgroud)