These are chat archives for SmingHub/Sming

10th
Feb 2016
alon24
@alon24
Feb 10 2016 05:22
how do i set the freq for hw pwm?
ystrem
@ystrem
Feb 10 2016 06:46
hi
alon24
@alon24
Feb 10 2016 06:59
I cannot to websocket from android now:
WebSocket Commandprocessor started
TCP connection send: 2 
TCP connection send: 41 
Default server handler for: '/index.html'
SEND ERROR PAGE
TCP connection send: 17 
TCP connection send: 13 
TCP connection send: 5 
WS remove connection item
WS Close
Socket disconnectedTCP connection closing
~TCP connection
Static OnSent buf = 2920
Static OnReceive buf = 2920
-TCP connection
chg_A1:-100
chg_A1:-60
02-10 08:57:28.412 20107-20107/alon24.smartcarandroid D/de.tavendo.autobahn.WebSocketConnection: worker threads stopped
02-10 08:57:35.210 20107-20107/alon24.smartcarandroid D/SmartCar: Trying to websocket connect to ws://192.168.4.1:80/index.html?command=true
02-10 08:57:41.247 20107-20107/alon24.smartcarandroid D/SmartCar: Connection lost.
02-10 08:57:44.074 20107-20107/alon24.smartcarandroid D/de.tavendo.autobahn.WebSocketConnection: created
02-10 08:57:44.236 20107-20107/alon24.smartcarandroid E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
02-10 08:57:44.237 20107-20107/alon24.smartcarandroid E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
02-10 08:57:46.458 20107-20107/alon24.smartcarandroid D/SmartCar: Trying to websocket connect to ws://192.168.4.1:80/index.html?command=true
02-10 08:57:46.476 20107-20107/alon24.smartcarandroid D/de.tavendo.autobahn.WebSocketReader: created
02-10 08:57:46.476 20107-20107/alon24.smartcarandroid D/de.tavendo.autobahn.WebSocketConnection: WS reader created and started
02-10 08:57:46.478 20107-22204/alon24.smartcarandroid D/de.tavendo.autobahn.WebSocketReader: running
02-10 08:57:46.478 20107-20107/alon24.smartcarandroid D/de.tavendo.autobahn.WebSocketWriter: created
02-10 08:57:46.478 20107-20107/alon24.smartcarandroid D/de.tavendo.autobahn.WebSocketConnection: WS writer created and started
02-10 08:57:46.811 20107-20107/alon24.smartcarandroid D/de.tavendo.autobahn.WebSocketConnection: opening handshake received
02-10 08:57:46.811 20107-20107/alon24.smartcarandroid D/SmartCar: Status: Connected to ws://192.168.4.1:80/index.html?command=true
02-10 08:57:46.811 20107-22204/alon24.smartcarandroid D/de.tavendo.autobahn.WebSocketReader: run() : WebSocketException (de.tavendo.autobahn.WebSocketException: RSV != 0 and no extension negotiated)
02-10 08:57:46.811 20107-22204/alon24.smartcarandroid D/de.tavendo.autobahn.WebSocketReader: ended
02-10 08:57:46.812 20107-20107/alon24.smartcarandroid D/SmartCar: Got echo: Welcome to the Websocket Command Executor
02-10 08:57:46.832 20107-20107/alon24.smartcarandroid D/de.tavendo.autobahn.WebSocketConnection: fail connection [code = 4, reason = WebSockets protocol violation
02-10 08:57:46.832 20107-20107/alon24.smartcarandroid D/de.tavendo.autobahn.WebSocketReader: quit
02-10 08:57:46.832 20107-22205/alon24.smartcarandroid D/de.tavendo.autobahn.WebSocketWriter: ended
02-10 08:57:46.833 20107-20107/alon24.smartcarandroid D/SmartCar: Connection lost.
02-10 08:57:46.838 20107-20107/alon24.smartcarandroid D/de.tavendo.autobahn.WebSocketConnection: worker threads stopped
02-10 08:58:20.921 20107-20107/alon24.smartcarandroid W/IInputConnectionWrapper: getExtractedText on inactive InputConnection
02-10 08:58:20.921 20107-20107/alon24.smartcarandroid W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
02-10 08:58:20.923 20107-20107/alon24.smartcarandroid W/IInputConnectionWrapper: getSelectedText on inactive InputConnection
02-10 08:58:20.924 20107-20107/alon24.smartcarandroid W/IInputConnectionWrapper: getTextAfterCursor on inactive InputConnection
alonewolfx2
@alonewolfx2
Feb 10 2016 07:23
@alon24 did you find webide from YouTube video?
That's very good
alon24
@alon24
Feb 10 2016 07:49
@alonewolfx2 @robotiko seems to think this is it: https://blog.arduino.cc/2015/05/05/sneak-peak-arduino-create/
i asked the guy, and he said it was a fork of something, but did not give link
so he did say it was Arduino Web IDE
and he is running sming :)
so why he is not on this gitter
alon24
@alon24
Feb 10 2016 08:33
@hreintke does spiffy work ok in rtos?
10:32:44 **** Build of configuration Sming for project SmartCarWithOTA ****
make rebuild 
OC out/build/libmain2.a
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C /Users/iklein/docker/sming-docker/workspace/SmingRTOS/sming/rboot
CC rboot-stage2a.c
LD /Users/iklein/docker/sming-docker/workspace/SmartCarWithOTA/out/build/rboot-stage2a.elf
E2 /Users/iklein/docker/sming-docker/workspace/SmartCarWithOTA/out/build/rboot-hex2a.h
CC rboot.c
LD /Users/iklein/docker/sming-docker/workspace/SmartCarWithOTA/out/build/rboot.elf
E2 /Users/iklein/docker/sming-docker/workspace/SmartCarWithOTA/out/firmware/rboot.bin
C+ app/CarCommand.cpp
C+ app/application.cpp
C+ app/configuration.cpp
CC /Users/iklein/docker/sming-docker/workspace/SmingRTOS/sming/rboot/appcode/rboot-api.c
CC /Users/iklein/docker/sming-docker/workspace/SmingRTOS/sming/rboot/appcode/rboot-bigflash.c
AR out/build/app_app.a
LD out/build/app_0.out
E2 out/firmware/rom0.bin
Checking for spiffs files
files directory exists. Creating out/firmware/spiff_rom.bin
Creating rom 'out/firmware/spiff_rom.bin' of size 0x10000 (65536) bytes.
Adding files in directory 'files'.
Added '.version' to spiffs (82 bytes).
Added 'index.html' to spiffs (2768 bytes).
Added 'main.css' to spiffs (270 bytes).
Added 'main.js' to spiffs (1874 bytes).
Added 'testfile.txt' to spiffs (9 bytes).

10:32:46 Build Finished (took 1s.945ms)

but:


Static OnReceive buf = 2920
path=/
Host === 192.168.4.1
parsed
Request: GET, nodata
TCP received new: 432 bytes
onReadyToSendData: 1
Http server processrequest
open errno -10024

File wasn't found: index.html
send file: index.html (-1 bytes)
SEND ERROR PAGE
TCP connection send: 24 
TCP connection send: 19
and:
10:34:26 **** Build of configuration Sming for project SmartCarWithOTA ****
make flash 
Killing Terminal to free /dev/tty.SLAB_USBtoUART
/opt/esp-alt-sdk-v1.3.0-rtos.258-macos-x86_64/utils/esptool.py -p /dev/tty.SLAB_USBtoUART -b 961000 write_flash -ff 40m -fm qio -fs 32m 0x00000 out/firmware/rboot.bin 0x02000 out/firmware/rom0.bin 0x100000 out/firmware/spiff_rom.bin
Connecting...
Erasing flash...

Writing at 0x00000000... (33 %) 
Writing at 0x00000400... (66 %) 
Writing at 0x00000800... (100 %) 
Wrote 3072 bytes at 0x00000000 in 0.1 seconds (415.6 kbit/s)...
Erasing flash...

Writing at 0x00002000... (0 %) 
Writing at 0x00002400... (0 %) 
Writing at 0x00002800... (0 %) 
Writing at 0x00002c00... (1 %) 
...
hreintke
@hreintke
Feb 10 2016 08:38
@alon24 :
For the spiffy error : can you shouw me the spiffs_mount_manual(...,...) statement from your program ?
And what is your SPI_SIZE ?
alon24
@alon24
Feb 10 2016 08:41
I must confess that I do not remeber much about the spiffy, and so this is an early try to get ota working:
void setupSpiffs() {
    // mount spiffs
    currentRbootSlot = rboot_get_current_rom();
    #ifndef DISABLE_SPIFFS
        if (currentRbootSlot == 0) {
    #ifdef RBOOT_SPIFFS_0
            debugf("trying to mount spiffs at %x, length %d", RBOOT_SPIFFS_0 + 0x40200000, 0);
            spiffs_mount_manual(RBOOT_SPIFFS_0 + 0x40200000, 0);
    #else
            debugf("trying to mount spiffs at %x, length %d", 0x40300000, 0);
            spiffs_mount_manual(0x40300000, 0);
    #endif
        } else {
    #ifdef RBOOT_SPIFFS_1
            debugf("trying to mount spiffs at %x, length %d", RBOOT_SPIFFS_1 + 0x40200000, 0);
            spiffs_mount_manual(RBOOT_SPIFFS_1 + 0x40200000, 0);
    #else
            debugf("trying to mount spiffs at %x, length %d", 0x40500000, 0);
            spiffs_mount_manual(0x40500000, 0);
    #endif
        }
    #else
        debugf("spiffs disabled");
    #endif
}

void init() {

    Serial.begin(115200); // 115200 by default
    Serial.systemDebugOutput(true); // Debug output to serial
    setupSpiffs();
as per the doc, I chose size 0 - for automatic size config
SPI_SIZE is 4M
## Local build configuration
## Parameters configured here will override default and ENV values.
## Uncomment and change examples:

#Add your source directories here separated by space
#MODULES = app

## ESP_HOME sets the path where ESP tools and SDK are located.
## Windows:
# ESP_HOME = c:/Espressif

## MacOS / Linux:
#ESP_HOME = /opt/esp-open-sdk

## SMING_HOME sets the path where Sming framework is located.
## Windows:
# SMING_HOME = c:/tools/sming/Sming 

# MacOS / Linux
# SMING_HOME = /opt/sming/Sming

## COM port parameter is reqruied to flash firmware correctly.
## Windows: 
#COM_PORT = COM5

# MacOS / Linux:
 COM_PORT = /dev/tty.SLAB_USBtoUART

# Com port speed
COM_SPEED    = 961000

#### overridable rBoot options ####
## use rboot build mode
RBOOT_ENABLED ?= 1
## enable big flash support (for multiple roms, each in separate 1mb block of flash)
RBOOT_BIG_FLASH ?= 1
## two rom mode (where two roms sit in the same 1mb block of flash)
#RBOOT_TWO_ROMS  ?= 1
## size of the flash chip
SPI_SIZE        ?= 4M
## output file for first rom (.bin will be appended)
#RBOOT_ROM_0     ?= rom0
## input linker file for first rom
#RBOOT_LD_0      ?= rom0.ld
## these next options only needed when using two rom mode
#RBOOT_ROM_1     ?= rom1
#RBOOT_LD_1      ?= rom1.ld
## size of the spiffs to create
SPIFF_SIZE      ?= 65536
## option to completely disable spiffs
#DISABLE_SPIFFS  = 1
## flash offsets for spiffs, set if using two rom mode or not on a 4mb flash
## (spiffs location defaults to the mb after the rom slot on 4mb flash)
#RBOOT_SPIFFS_0  ?= 0x100000
#RBOOT_SPIFFS_1  ?= 0x300000
## esptool2 path
#ESPTOOL2        ?= esptool2


# we will use global WiFi settings from Eclipse Environment Variables, if possible
OTA_SERVER ?= ""
ifneq ($(OTA_SERVER), "")
    CFLAGS += -DOTA_SERVER=\"$(OTA_SERVER)\"
endif
ESPTOOL      ?= $(ESP_HOME)/utils/esptool.py
SPIFF_FILES = files
yeah i see the spiff_size, let me change it to 0
hreintke
@hreintke
Feb 10 2016 08:43
no wait
See the line from @robotiko last night annd the readme
use the actual flash address : For conversion of current spiffs_mount_manual : subtract 0x40200000 from start address
You have to change your spiffs_mount statements !
alon24
@alon24
Feb 10 2016 08:45
0x40200000 - 0x40200000 ??
also 0 in the make-file - creates 1 byte spiffy rom
hreintke
@hreintke
Feb 10 2016 08:47
The spiffs_size is OK,
It tells spiffy what size of spiffs to make.
The zero in the spiffs_mount_manual detects what size spiffy made
alon24
@alon24
Feb 10 2016 08:48
sorry let me repeat to see if I understd:
  1. in make file - SPIFF_SIZE ?= 0 ????
2.
void setupSpiffs() {
    // mount spiffs
    currentRbootSlot = rboot_get_current_rom();
    #ifndef DISABLE_SPIFFS
        if (currentRbootSlot == 0) {
    #ifdef RBOOT_SPIFFS_0
            debugf("trying to mount spiffs at %x, length %d", RBOOT_SPIFFS_0 + 0x40200000, SPIFF_SIZE);
            spiffs_mount_manual(RBOOT_SPIFFS_0 + 0x40200000 - 0x40200000, SPIFF_SIZE);
    #else
            debugf("trying to mount spiffs at %x, length %d", 0x40300000, SPIFF_SIZE);
            spiffs_mount_manual(0x40300000 - 0x40200000, SPIFF_SIZE);
    #endif
        } else {
    #ifdef RBOOT_SPIFFS_1
            debugf("trying to mount spiffs at %x, length %d", RBOOT_SPIFFS_1 + 0x40200000, SPIFF_SIZE);
            spiffs_mount_manual(RBOOT_SPIFFS_1 + 0x40200000 - 0x40200000, 0);
    #else
            debugf("trying to mount spiffs at %x, length %d", 0x40500000, SPIFF_SIZE);
            spiffs_mount_manual(0x40500000 - 0x40200000, SPIFF_SIZE);
    #endif
        }
    #else
        debugf("spiffs disabled");
    #endif
}
are these statements correct?
hreintke
@hreintke
Feb 10 2016 08:51
0x40200000 -> 0 : 0x40300000 -> 0x100000 : subtract the 0x402.. from all values
alon24
@alon24
Feb 10 2016 08:52
E2 out/firmware/rom0.bin
Checking for spiffs files
files directory exists. Creating out/firmware/spiff_rom.bin
Creating rom 'out/firmware/spiff_rom.bin' of size 0x0 (0) bytes.
Adding files in directory 'files'.
Unable to open spiffs file '.version', error -1.
Unable to open spiffs file 'index.html', error -1.
Unable to open spiffs file 'main.css', error -1.
Unable to open spiffs file 'main.js', error -1.
Unable to open spiffs file 'testfile.txt', error -1.
When in make file
SPIFF_SIZE      ?= 0
and
void setupSpiffs() {
    // mount spiffs
    currentRbootSlot = rboot_get_current_rom();
    #ifndef DISABLE_SPIFFS
        if (currentRbootSlot == 0) {
    #ifdef RBOOT_SPIFFS_0
            debugf("trying to mount spiffs at %x, length %d", RBOOT_SPIFFS_0 + 0x40200000, SPIFF_SIZE);
            spiffs_mount_manual(RBOOT_SPIFFS_0 + 0x40200000 - 0x40200000, SPIFF_SIZE);
    #else
            debugf("trying to mount spiffs at %x, length %d", 0x40300000, SPIFF_SIZE);
            spiffs_mount_manual(0x40300000 - 0x40200000, SPIFF_SIZE);
    #endif
        } else {
    #ifdef RBOOT_SPIFFS_1
            debugf("trying to mount spiffs at %x, length %d", RBOOT_SPIFFS_1 + 0x40200000, SPIFF_SIZE);
            spiffs_mount_manual(RBOOT_SPIFFS_1 + 0x40200000 - 0x40200000, SPIFF_SIZE);
    #else
            debugf("trying to mount spiffs at %x, length %d", 0x40500000, SPIFF_SIZE);
            spiffs_mount_manual(0x40500000 - 0x40200000, SPIFF_SIZE);
    #endif
        }
    #else
        debugf("spiffs disabled");
    #endif
}
hreintke
@hreintke
Feb 10 2016 08:54
that is an error from you MAC, is there an file protection access rights on your system ?
the values in the spiffs_mount manual are OK
alon24
@alon24
Feb 10 2016 08:54
i think i diabled it, when I change the value in the make file it does create spiffyt
SPIFF_SIZE      ?= 65535

10:54:44 **** Build of configuration Sming for project SmartCarWithOTA ****
make rebuild 
OC out/build/libmain2.a
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C /Users/iklein/docker/sming-docker/workspace/SmingRTOS/sming/rboot
CC rboot-stage2a.c
LD /Users/iklein/docker/sming-docker/workspace/SmartCarWithOTA/out/build/rboot-stage2a.elf
E2 /Users/iklein/docker/sming-docker/workspace/SmartCarWithOTA/out/build/rboot-hex2a.h
CC rboot.c
LD /Users/iklein/docker/sming-docker/workspace/SmartCarWithOTA/out/build/rboot.elf
E2 /Users/iklein/docker/sming-docker/workspace/SmartCarWithOTA/out/firmware/rboot.bin
C+ app/CarCommand.cpp
C+ app/application.cpp
C+ app/configuration.cpp
CC /Users/iklein/docker/sming-docker/workspace/SmingRTOS/sming/rboot/appcode/rboot-api.c
CC /Users/iklein/docker/sming-docker/workspace/SmingRTOS/sming/rboot/appcode/rboot-bigflash.c
AR out/build/app_app.a
LD out/build/app_0.out
E2 out/firmware/rom0.bin
Checking for spiffs files
files directory exists. Creating out/firmware/spiff_rom.bin
Creating rom 'out/firmware/spiff_rom.bin' of size 0xffff (65535) bytes.
Adding files in directory 'files'.
Added '.version' to spiffs (82 bytes).
Added 'index.html' to spiffs (2768 bytes).
Added 'main.css' to spiffs (270 bytes).
Added 'main.js' to spiffs (1874 bytes).
Added 'testfile.txt' to spiffs (9 bytes).

10:54:46 Build Finished (took 2s.258ms)
let me try to gflash
hreintke
@hreintke
Feb 10 2016 08:55
that is OK, now flash
alon24
@alon24
Feb 10 2016 08:56
it works now, this part
but the 0 does not auto calculte
calculate
hreintke
@hreintke
Feb 10 2016 08:59
the SPIFFY_SIZE in the makefile is not autodetect.
In your appliaction :
The spiffs_mount_manual(0x40300000 - 0x40200000, SPIFF_SIZE);
to spiffs_mount_manual(0x40300000 - 0x40200000, 0);
Is the autodetect.
Will update the readme : Is confusing
I am out for an hour. Will be back then.
alon24
@alon24
Feb 10 2016 09:03
k, did u check websocketcommand? - answer when u can
it does not work for me
Static OnReceive buf = 2920
WS: Move xyz 0 100
WebSocket message received:
Move xyz 0 100
TCP connection send: 2 
TCP connection send: 20 
TCP received new: 20 bytes
onReadyToSendData: 1
Static OnReceive buf = 2898
WS: Move xyz 0 100
WebSocket message received:
Move xyz 0 100
TCP connection send: 2 
TCP connection send: 20 
TCP received new: 20 bytes
onReadyToSendData: 1
Static OnSent buf = 2898
TCP sent: 22
onReadyToSendData: 2
Static OnSent buf = 2920
TCP sent: 22
onReadyToSendData: 2
alon24
@alon24
Feb 10 2016 09:20
Strike that, commandprocessing works
hreintke
@hreintke
Feb 10 2016 10:15
OK, Do you already have a RTOS driven car ?
alon24
@alon24
Feb 10 2016 10:28
well,something is wrong, it does not move correctly, need to understand what the issue is exactly, one motor works as expectedd, the other does not
it should not be a sming issue, but my code, now just need to understand pwm - how to set freq
hreintke
@hreintke
Feb 10 2016 10:55
Within hwpwm you set period -> time in microsecond for each period.
period : 1000 -> 1Khz
period : 2000 -> 500Hz
period : 20000 -> 50Hz
Duty cycle is always between 0 and 1023, independent on period
robotiko
@robotiko
Feb 10 2016 10:58
@alon24 try with 4000 or more and 1023 cycle..
then try with 512 duty cycle .. show go half speed..
if not.. you have to increase the period
alonewolfx2
@alonewolfx2
Feb 10 2016 12:21
@alon24 I think it's code bender
alon24
@alon24
Feb 10 2016 12:25
code bender?
@alonewolfx2 how do u mean? (what do u mean?)
alon24
@alon24
Feb 10 2016 13:43
@hreintke there is an issue with hwpwm
void CarCommand::drive(int leftDir, int leftPwm, int rightDir, int rightPwm) {
    debugf("drive command:leftD=%i,leftP=%i,rightD-%i,rightP=%i", leftDir, leftPwm, rightDir, rightPwm);
    spdTargetLeft = leftPwm;
    spdTargetRight = rightPwm;

    digitalWrite(leftMotorDir, leftDir);
    digitalWrite(rightMotorDir, rightDir);
    if (leftPwm == 0 ){
        pwmMotors->analogWrite(leftMotorPWM, 0);
    } else {
        pwmMotors->analogWrite(leftMotorPWM, leftPwm);
    }

    if (rightPwm == 0 ){
        pwmMotors->analogWrite(rightMotorPWM, 0);
    } else {
        pwmMotors->analogWrite(rightMotorPWM, rightPwm);
    }
}
send 1023,1023 (left right), then 0,0 - alone, (only leftpwm block, or just rightpwm block) it works ok - tuns and then stops ok but if both blocks then, left is ok (rusns, then stops) and then right starts, stops, starts again
crosofg
@crosofg
Feb 10 2016 13:49
is there any code read protection feature for sming?
robotiko
@robotiko
Feb 10 2016 13:50
@crosofg nopes
not supported by HW
and no SW solution
crosofg
@crosofg
Feb 10 2016 13:58
@robotiko and how easy will it be for anyone to decode my firmware once it is on the flash?!
riban-bw
@riban-bw
Feb 10 2016 14:05
@slaf Is there a reason why you didn't use the SDK SSL lib? (maybe you have explained but I missed it)
alonewolfx2
@alonewolfx2
Feb 10 2016 14:09
@alon24 arduino online ide https://codebender.cc/how_it_works
slaff
@slaff
Feb 10 2016 14:22

@riban-bw

Is there a reason why you didn't use the SDK SSL lib?

Two major reasons -

  1. Better visibility and trust in the SSL code
  2. faster fixing of possible issues of the SSL code
    The SSL lib from the SDK and the one in Sming are based on the same library - axTLS. The SDK SSL lib is "patched" by Espressif. Last time I saw the code it was full of "let's hack it and then will fix it" comments. With the axTLS coming with this PR, we, as developers, have more control to know what is exactly the SSL library doing and we have the chance to fix something if it is not working. The SSL code in this PR is not hacking wildly inside the axTLS code. It just uses it and adds compatibility layer. Which means that if there is a new version of axTLS in theory it should be quite easy to migrate to the new version. Which is quite important if one is using a SSL library IMHO for more serious stuff.
Security matters and SSL is important part of it.
riban-bw
@riban-bw
Feb 10 2016 14:26
@slaff Understood - cheers!
alon24
@alon24
Feb 10 2016 14:31
@hreintke did u test hw pwm on 2 pons, to see there are no spikes after the second pin is set, with a different value?
hreintke
@hreintke
Feb 10 2016 16:38
@alon24 : this is on 4 pins
Period 4000 : from to to bottom duty Cycle 20,200,400,800
pwm4.PNG
alon24
@alon24
Feb 10 2016 16:44
I will need to see my issue
hreintke
@hreintke
Feb 10 2016 16:47
do you want the code I am testing with ?

this is the main part :

HardwarePWM* hardwarePWM;
uint8_t pins[8] = {2,4,5,14} ;  // List of pins that you want to connect to pwm

void initPWM()
{
    hardwarePWM = new HardwarePWM(pins, 4);

}

void processPWMCommands(String commandLine, CommandOutput* commandOutput)
{
    Vector<String> commandToken;
    int numToken = splitString(commandLine, ' ' , commandToken);
    if (numToken == 2)
    {
        int period = commandToken[1].toInt();
        hardwarePWM->setPeriod(period);
        commandOutput->printf("period set to %d\r\n",period);
    }
    else if (numToken == 3)
    {
        int p = commandToken[1].toInt();
        int d = commandToken[2].toInt();
        if (hardwarePWM->setDuty(p,d))
        {
            commandOutput->printf("Pin %d set to duty %d\r\n",p,d);
        }
        else
        {
            commandOutput->printf("Error in Pin %d , duty %d\r\n",p,d);
        }
    }
    else
    {
        commandOutput->printf("invalid pwm command\r\n");
    }

}

with

    commandHandler.registerCommand(CommandDelegate("pwm","Example Command from Class","Application",processPWMCommands));

initPWM();

In init()
type command pwm pin# duty for set duty f.e. pwm 2 200
type command pwm period for setting period f.e pwm 4000
No checking within the commands :smile:

alon24
@alon24
Feb 10 2016 17:14
Please give me a link to code?
Pins should be 8? I put it as 2,because I only have 2pins
hreintke
@hreintke
Feb 10 2016 17:27
don't have it in a public repo. It's part of my larger "localtest" where I do most of my tests and not of the quality to share :smile:
Just take the blink example, strip that code and copy past the above in.
No problem to have pins to two. You can bring down the size to two and do HardwarePWM(pins, 2);

and put in the :

    Serial.commandProcessing(true);
    commandHandler.registerSystemCommands();

to enable command on serial.

alon24
@alon24
Feb 10 2016 17:29
oh u use setduty
I do analogwrite
does not change anything (setduty)
alon24
@alon24
Feb 10 2016 17:44
@hreintke can u test set value (2 together to say 800) and then to 0 in both?
or is there an issue to set hwpwm from a timer delegate??
(thats what I am doing), setting from normal command has no isues
I think that is the issue, seeting a 0 value from timer!
(o 2 pins at once)
hreintke
@hreintke
Feb 10 2016 18:06
analogWrite is the same as setDuty :smile:
bool HardwarePWM::analogWrite(uint8 pin, uint32 duty) {
    return setDuty(pin, duty);
}
not sure what you are asking me to do
pin 2 and 4 both to 400
and then pin 2 and 4 both to zero ?
Don't see any reason why it should not work from timerdelegate
how do you set two pins at once ?
alon24
@alon24
Feb 10 2016 18:14
```
I verified my timer hypothesis:
motorTimer.setCallback(carMotorDelegate(&CarCommand::handleMotorTimer, this));
motorTimer.setIntervalMs(150);
....
if (leftPwm ==0 && rightPwm == 0) {
            motorTimer.startOnce();
        }
        else {
            drive(leftDir, leftPwm, rightDir, rightPwm);
        }

}


void CarCommand::drive(int leftDir, int leftPwm, int rightDir, int rightPwm) {
    debugf("drive command:leftD=%i,leftP=%i,rightD-%i,rightP=%i", leftDir, leftPwm, rightDir, rightPwm);
    spdTargetLeft = leftPwm;
    spdTargetRight = rightPwm;

    digitalWrite(leftMotorDir, leftDir);
    digitalWrite(rightMotorDir, rightDir);

    if (leftPwm == 0 ){
        pwmMotors->setDuty(leftMotorPWM, 0);
    } else {
        pwmMotors->setDuty(leftMotorPWM, leftPwm);
    }

    if (rightPwm == 0 ){
        pwmMotors->setDuty(rightMotorPWM, 0);
    } else {
        pwmMotors->setDuty(rightMotorPWM, rightPwm);
    }
}

//Stop the car
void CarCommand::handleMotorTimer() {
    drive(0,0,0,0);
};

so when stop pressed, it fires a timer (as oposed to before, when it went streight from commandprocessing)
so from timer it does not work well
alon24
@alon24
Feb 10 2016 18:24
BTW, this happens with 0 and 1023,@robotiko said that the edges were problematic.. Maybe it's that?
hreintke
@hreintke
Feb 10 2016 18:37
duty 0 and 1023 seem to act OK. See these 4 pins,
duty 0, 350, 700,1023
This message was deleted
alon24
@alon24
Feb 10 2016 18:38
נfrom timer? Like mine?
hreintke
@hreintke
Feb 10 2016 18:38
wait wrong picture
pwm41.PNG
not yet from timer. wait a moment.
hreintke
@hreintke
Feb 10 2016 18:46
dinner break :smile: Will be back later
alon24
@alon24
Feb 10 2016 18:55
Enjoy
hreintke
@hreintke
Feb 10 2016 19:31
@alon24 :
I am busy otherwise most of this evening.
Will connect and run my motors tomorrow. And for sure using timers with that testing.
Just for my info : why did you change from stopping in command to delayed in a Timer. (not saying that you have to revert)
alon24
@alon24
Feb 10 2016 19:32
Just to test,
I do not run the motor continuously, if u do not press the button, it should stop
So there are 2 things,
  1. A stop command from websocket
  1. A timer that runs after 100 from last command, and stops the car
  1. The last code I pasted was a test to see that the timer does not stop the car, even when the times is started from websocket command
I hope this is understood
hreintke
@hreintke
Feb 10 2016 19:37
Yep, I understand. Will try to do roughly the same and feedback.
alon24
@alon24
Feb 10 2016 19:41
Thanks