I am having not to use any .cpp library to serialise the contents of(.cpp) file. I just need the file to be transported and stored in a server. The idea is client sends/posts the file in Json format using REST API to the server. Would be helpful to know a simple python script if anyone has done this before.
This is the simple script that works locally. But I also have a web service
<pre>import json
data=[]
flag=False
# filename, mode: r for reading
with open('example.cpp','r') as f:
for line in f:
data.append(line)
# Using built in function json()
dataJ=jsonify(data)
print dataJ
这是输入文件,所以基本上是一个将用JSON包装的cpp文件(基于Arduino的程序)。输出将作为blob存储在服务器中。另外,关于jsonify我认为我的错误应该是json.dump(数据)而不是jsonify。
{
"guid" : "abcdefg",
"platformio.ini" : {
"platform": "atmelavr",
"framework": "arduino",
"board": "uno",
// "board_mcu":,
// "board_f_cpu":,
// "lib_install":,
// "lib_use":,
// "lib_ignore":,
// "lib_dfcyclic":
},
#include \"Arduino.h\"
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}",
"status" : "null"
}</pre>